From eae90d6156e89a61301b4c7bcebb7cd9d0cd69f6 Mon Sep 17 00:00:00 2001 From: Fabien Benetou Date: Sun, 14 Aug 2011 11:45:41 +0200 Subject: [PATCH] Sphinx search interface --- pim_search.php | 147 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 147 insertions(+) create mode 100644 pim_search.php diff --git a/pim_search.php b/pim_search.php new file mode 100644 index 0000000..dad42a0 --- /dev/null +++ b/pim_search.php @@ -0,0 +1,147 @@ + +
+

To do

+ + +
+
+"; +$star_img = ""; +$alt_img = ""; +$bug_img = ""; + +if ($words == ""){ + print "You need to make an actual search, use ?query=keyword
"; + print "

"; + return; +} +if ($startingitem == "" || $startingitem < 0){ + $startingitem=0; +} + +$itemspan=20; + +$cl = new SphinxClient (); +$cl->SetLimits($startingitem, $startingitem+$itemspan); +$cl->SetMatchMode(SPH_MATCH_EXTENDED2); +$cl->SetRankingMode(SPH_RANK_PROXIMITY_BM25); +# consider other ranking e.g. pagerank, weighted with freshness and hybrid +$cl->SetSortMode(SPH_SORT_RELEVANCE); +$res = $cl->Query($words,$index); +#cf http://sphinxsearch.com/docs/manual-2.0.1.html#api-funcgroup-querying +#$res = $cl->BuildExcerpts ( $docs, $index, $words, $opts ); +if ( !$res ) { + die ( "ERROR: " . $cl->GetLastError() . ".\n" ); +} else { + // XXX should test for empty result before doing the assigment + // if (0 results) { $socialsearch = shell_exec("pmwiki_social_search "$keyword"); } + // ideally this would be done ascynhroneously as it does take some time (few seconds!) + // yet still always offer it as an option (since it's "costly") + #var_dump($res); + $IDs = array_keys($res["matches"]); + print "

Query$bug_img

"; + + print "\"$words\" found ".$res["words"]["$words"]["hits"]." time(s) in ".$res["total_found"]." document(s):
"; + print ""; + print "
"; + if ($previousitems >= 0) + print "previous items"; + for ($p=1;$p<$res["total"]/$itemspan;$p++) + print " $p/"; + if ($nextitems < $res["total"]) + print "next items"; + print "
"; + + $indexage = "unknown"; + $targetindexfile = "/var/lib/sphinxsearch/data/pmwikis.spd"; + $updatedindex = filemtime($targetindexfile); + $indexage = date("c",$updatedindex); + print "
$indexage index
(if bug check indexer errors).
"; +} + +?> +