[mythtv] [patch] Mythweb -- Search for movies by star rating

Brad Templeton brad+mydev at templetons.com
Wed Jan 12 22:37:06 EST 2005


Well, I was appropriately chastised on the user's list for not
contributing code, so I put together a small but useful mythweb
patch which is included.  I had not coded in PHP before but it's
pretty similar to many other languages.

This patch modifies the mythweb search to allow you to see all
movies at or above a certain star rating.   In the search box,
simply enter a pattern like *, **, *** or ****.  You can also
enter things like **1/2 or **- or **.5 to mean 2 and a half stars.

A nice way to see what top movies are coming up.  Probably the
most common use will be the *** or ***1/2 search.

I considered putting a select box on the query but that just busies
up the UI and ratings queries really only make sense with movies and
where you don't know the name of the movie, though if people really
feel the need to search for "3* Science fiction movies" or "4* movies
with Spencer Tracy" this could be done.

Also changed the results display to indicate when movies are in HDTV,
similar to the listings grid display.

Possible other changes here:  Remove duplicate entries (see that when
you click on the movie like any other show), Keep a cookie to record
how far in time you browsed in prior sessions to only show you new
listings, switch to GET rather than POST to allow users to bookmark
favourite searches.   Won't do these until I get more comfortable and
are sure you want 'em.


Index: search.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/search.php,v
retrieving revision 1.11
diff -u -r1.11 search.php
--- search.php	10 Aug 2004 04:03:39 -0000	1.11
+++ search.php	13 Jan 2005 02:57:05 -0000
@@ -40,16 +40,28 @@
         $compare = ' LIKE ';
 
 // How do we want to build this query?
-    if (preg_match('/\\S/', $_SESSION['search']['searchstr'])) {
+    // If it starts with a pair of stars, it's a movie rating query
+    $searchstr = $_SESSION['search']['searchstr'];
+    if( preg_match( '/^\\*+(1\\/2|0?\\.5|-)?/', $searchstr )) {
+        $dummy_array = array();
+        $starcount = preg_match_all( '/\\*/', $searchstr, $dummy ) / 4.0;
+        if( preg_match( "/1\\/2|\\.5|-/", $searchstr ) ) 
+            $starcount += 0.125;
+        $query[] = "program.stars >= $starcount";
+        //$joiner = " AND ";
+        //$query[] = "program.category_type = 'movie'";
+    }
+    
+    else if (preg_match('/\\S/', $searchstr)) {
     // Normal search is an OR search
         $joiner = ' OR ';
     // Regex search?
-        if (preg_match('/^~/', $_SESSION['search']['searchstr'])) {
+        if (preg_match('/^~/', $searchstr)) {
             $compare = ' REGEXP ';
-            $search = escape(preg_replace('/^~/', '', $_SESSION['search']['searchstr']));
+            $search = escape(preg_replace('/^~/', '', $searchstr));
         }
         else
-            $search = search_escape($_SESSION['search']['searchstr']);
+            $search = search_escape($searchstr);
     // Build the query
         if ($_SESSION['search']['search_title'])
             $query[] = "program.title$compare$search";
Index: themes/Default/search.php
===================================================================
RCS file: /var/lib/mythcvs/mythweb/themes/Default/search.php,v
retrieving revision 1.19
diff -u -r1.19 search.php
--- themes/Default/search.php	1 Dec 2004 07:30:37 -0000	1.19
+++ themes/Default/search.php	13 Jan 2005 02:57:06 -0000
@@ -113,10 +113,16 @@
                 $additional .= ", ";
             $additional .= $show->starstring;
         }
-        if ($additional)
-            $additional = ' (' . $additional . ')';
+        if ($show->hdtv) {
+            if ($additional)
+                $additional .= ", ";
+            $additional .=  "<font color=\"yellow\"><b>HD</b></font>";
+        }
     }
 
+    if ($additional)
+        $additional = ' (' . $additional . ')';
+
     // Print the content
     ?><tr class="<?php echo $show->class ?>">
     <?php if ($group_field != "") echo "<td class=\"list\">&nbsp;</td>\n"; ?>


More information about the mythtv-dev mailing list