r2942 - search_cmpObj(): dismiss useless function
authorDenis Ovsienko <infrastation@yandex.ru>
Mon, 13 Jul 2009 11:21:47 +0000 (11:21 +0000)
committerDenis Ovsienko <infrastation@yandex.ru>
Mon, 13 Jul 2009 11:21:47 +0000 (11:21 +0000)
 - getObjectSearchResults(): dismiss old code, merge getObjectSearchResults_new()
 - getObjectAttrsSearchResults(): new sub-search helper for static columns
 - renderSearchResults(): perform one "object" search again

inc/database.php
inc/functions.php
inc/interface.php

index b27626d859939b0b819d00dfffdab72a9c8d58c1..a8822ec9ba23e262d597e11cbe38a2be6bc5a068 100644 (file)
@@ -1620,10 +1620,7 @@ function getSearchResultByField ($tname, $rcolumns, $scolumn, $terms, $ocolumn =
        return $ret;
 }
 
-// This function will eventually merge the functionality of the "older"
-// searching function. Both ones are used at the moment, and they do
-// search in different value spaces.
-function getObjectSearchResults_new ($what)
+function getObjectSearchResults ($what)
 {
        $ret = array();
        foreach (getStickerSearchResults ($what) as $objRecord)
@@ -1636,6 +1633,33 @@ function getObjectSearchResults_new ($what)
                $ret[$objRecord['id']]['id'] = $objRecord['id'];
                $ret[$objRecord['id']]['by_portrsv'] = $objRecord['by_portrsv'];
        }
+       foreach (getObjectAttrsSearchResults ($what) as $objRecord)
+       {
+               $ret[$objRecord['id']]['id'] = $objRecord['id'];
+               $ret[$objRecord['id']]['by_attr'] = $objRecord['by_attr'];
+       }
+       return $ret;
+}
+
+function getObjectAttrsSearchResults ($what)
+{
+       $ret = array();
+       foreach (array ('name', 'label', 'asset_no', 'barcode') as $column)
+       {
+               $tmp = getSearchResultByField
+               (
+                       'RackObject',
+                       array ('id'),
+                       $column,
+                       $what,
+                       $column
+               );
+               foreach ($tmp as $row)
+               {
+                       $ret[$row['id']]['id'] = $row['id'];
+                       $ret[$row['id']]['by_attr'][] = $column;
+               }
+       }
        return $ret;
 }
 
index 9f19925e53df6a58f3d8eb1497d8bad734f97f89..3b94d66934998c2d9c55b38c12fa9077d085e3e4 100644 (file)
@@ -536,23 +536,6 @@ function markupObjectProblems (&$rackData)
                        }
 }
 
-function search_cmpObj ($a, $b)
-{
-       return ($a['score'] > $b['score'] ? -1 : 1);
-}
-
-function getObjectSearchResults ($terms)
-{
-       $objects = array();
-       mergeSearchResults ($objects, $terms, 'name');
-       mergeSearchResults ($objects, $terms, 'label');
-       mergeSearchResults ($objects, $terms, 'asset_no');
-       mergeSearchResults ($objects, $terms, 'barcode');
-       if (count ($objects) == 1)
-               usort ($objects, 'search_cmpObj');
-       return $objects;
-}
-
 // This function removes all colons and dots from a string.
 function l2addressForDatabase ($string)
 {
index 3ef9b873b1bd0d1d11cd0e8ed56e792e19ba8f27..1e656b44fdb0d17cac4cb33d6051a3b3f266cabc 100644 (file)
@@ -2769,13 +2769,6 @@ function renderSearchResults ()
                        $lasthit = 'object';
                        $summary['object'] = $tmp;
                }
-               $tmp = getObjectSearchResults_new ($terms);
-               if (count ($tmp))
-               {
-                       $nhits += count ($tmp);
-                       $lasthit = 'object_new';
-                       $summary['object_new'] = $tmp;
-               }
                $tmp = getIPv4AddressSearchResult ($terms);
                if (count ($tmp))
                {
@@ -2858,7 +2851,6 @@ function renderSearchResults ()
                                echo "';//</script>";
                                break;
                        case 'object':
-                       case 'object_new':
                                echo "<script language='Javascript'>document.location='${root}?page=object&object_id=${record['id']}';//</script>";
                                break;
                        case 'ipv4rspool':
@@ -2888,19 +2880,6 @@ function renderSearchResults ()
                        switch ($where)
                        {
                                case 'object':
-                                       startPortlet ("<a href='${root}?page=depot'>Objects</a>");
-                                       echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
-                                       foreach ($what as $obj)
-                                       {
-                                               echo "<tr class=row_${order} valign=top><td>";
-                                               renderCell (spotEntity ('object', $obj['id']));
-                                               echo "</td></tr>\n";
-                                               $order = $nextorder[$order];
-                                       }
-                                       echo '</table>';
-                                       finishPortlet();
-                                       break;
-                               case 'object_new':
                                        startPortlet ("<a href='${root}?page=depot'>Objects (continued)</a>");
                                        echo '<table border=0 cellpadding=5 cellspacing=0 align=center class=cooltable>';
                                        echo '<tr><th>what</th><th>why</th></tr>';
@@ -2908,7 +2887,16 @@ function renderSearchResults ()
                                        {
                                                echo "<tr class=row_${order} valign=top><td>";
                                                renderCell (spotEntity ('object', $obj['id']));
-                                               echo "</td><td>";
+                                               echo "</td><td class=tdleft>";
+                                               if (isset ($obj['by_attr']))
+                                               {
+                                                       // only explain non-obvious reasons for listing
+                                                       echo '<ul>';
+                                                       foreach ($obj['by_attr'] as $attr_name)
+                                                               if ($attr_name != 'name')
+                                                                       echo "<li>${attr_name} matched</li>";
+                                                       echo '</ul>';
+                                               }
                                                if (isset ($obj['by_sticker']))
                                                {
                                                        echo '<table>';