[mythtv] [PATCH] mythweb exact match
Matt Zimmerman
mdz at debian.org
Wed Feb 11 14:51:05 EST 2004
On Wed, Feb 11, 2004 at 02:31:29PM -0500, Aj wrote:
> Updated mythweb/search.php to include an "exact match" option as
> requested below. Also updated program_detail.php to use the exact
> match option.
Thanks!
> diff -ru mythweb.old/search.php mythweb/search.php
> --- mythweb.old/search.php 2004-01-14 22:22:32.000000000 -0500
> +++ mythweb/search.php 2004-02-11 13:35:55.000000000 -0500
> @@ -10,7 +10,7 @@
> require_once "includes/sorting.php";
>
> // Session variables for search types
> - foreach (array('search_title', 'search_subtitle', 'search_description', 'search_category', 'search_category_type') as $search_var) {
> + foreach (array('search_title', 'search_subtitle', 'search_description', 'search_category', 'search_category_type', 'search_exact') as $search_var) {
> isset($_GET[$search_var]) or $_GET[$search_var] = $_POST[$search_var];
> #isset($_GET[$search_var]) or $_GET[$search_var] = $_SESSION[$search_var];
> #$_SESSION[$search_var] = $_GET[$search_bar];
> @@ -23,11 +23,14 @@
> isset($_GET['description']) or $_GET['description'] = $_POST['description'];
> isset($_GET['category']) or $_GET['category'] = $_POST['category'];
> isset($_GET['category_type']) or $_GET['category_type'] = $_POST['category_type'];
> + isset($_GET['search_exact']) or $_GET['search_exact'] = $_POST['serach_exact'];
^^^^^ typo?
I confess that I don't understand why these are both necessary; shouldn't
all of these lines in the second bit here be replaced by adding the
corresponding variables to the foreach above? It seems to do exactly the
same thing.
> // Start the query out as an array
> $query = array();
> $joiner = ' OR ';
> $compare = ' LIKE ';
> + if($_GET['search_exact'])
> + $compare = ' = ';
>
> // How do we want to build this query?
> if (preg_match('/^\~/', $_GET['searchstr'])) {
> @@ -109,6 +112,7 @@
> # starttime
> # endtime
> // Perform the query
> +print_r($query);
This should be removed, yes?
> @@ -129,6 +133,10 @@
>
> // One little function to help us format search queries
> function search_escape($value) {
> + //if we are asking for an exact match, dont put the '%'s in
> + if($_GET['search_exact'])
> + return "'" . $value . "'";
> +
> return escape('%'.preg_replace('/[\\s-_]+/', '%', $value).'%');
> }
> function regexp_escape($value) {
Will this still do the right thing by escaping '%' in non-LIKE comparisons?
I got the impression that a large chunk of this file should be rewritten, as
things have been tacked on over time. There should be one big, clear
if/else or case statement (does php have case statements?) which handles
each type of search. They don't really share much code at all and there are
some weird fall-through conditions and the indentation is messed up.
Since you seem comfortable with PHP, would you be interested in cleaning it
up a bit? :-)
--
- mdz
More information about the mythtv-dev
mailing list