if(strlen($_GET["query"]) > 0)
{
#echo urldecode($_GET["query"])."
";
date_default_timezone_set("Asia/Calcutta");
require_once("SolrPhpClient/Apache/Solr/Service.php");
$solr = new Apache_Solr_Service('172.30.11.57', 2003 , '/gfs-data/solr/C40/tomcat2003/solr_read');
if ($solr->ping())
{
$q = urldecode ($_GET["query"]);
#echo $q , "
";
#echo urlencode($q) , "
";
$clean_query = preg_replace ('/^\"(.*?)\"$/', '$1', $q);
#echo "---",$clean_query , "---
";
$len = strlen($q) + 1;
#echo $len;
if($_GET["start"] == "")
$start = "0";
if($_GET["limit"] == -1)
$limit = 100;
if($_GET["sortorder"] == 0)
$sortorder = "asc";
else
$sortorder = "desc";
if($_GET["sortfield"] != "")
$result = $solr->search($q, $start, 10, array('sort' => '' . $sortfield . ' ' . $sortorder , 'fl' => 'id'));#, 'facet' => 'true', 'facet.field' => $_GET["facet"], 'facet.limit' => '-1', 'facet.mincount' => '1', 'f.country.facet.missing' => 'true', 'facet.sort' => 'true'));
else
$result = $solr->search(htmlspecialchars_decode(urldecode($_GET["query"])), $start, $limit, array('fl' => '*', 'qt' => 'dismax', 'spellcheck' => 'true', 'spellcheck.collate' => 'true', 'facet' => 'false', 'facet.field' => $_GET["facet"], 'facet.limit' => '-1', 'facet.mincount' => '1', 'f.country.facet.missing' => 'true', 'facet.sort' => 'true'));
#echo $result->getRawResponse();
$result_str = "";
$start = 0;
$result_str = str_replace("},{", "}
{", str_replace('","', '|', $result->getRawResponse()));
// $result_str = str_replace(" ", " ", $result_str);
$found = $result->response->numFound; //substr($result_str, $start, strpos($result_str, ",", $start) - $start);
//echo "
"; $results = array (); if ( $found > 0) { $result = ''; $result = $solr->search($q, $start, 1000, array('sort' => '' . $sortfield . ' ' . $sortorder , 'fl' => 'id', 'hl' => 'true', 'hl.fragsize' => $len+20, 'hl.fl' => 'title,content','hl.usePhraseHighlighter' => 'true'));#, 'facet' => 'true', 'facet.field' => $_GET["facet"], 'facet.limit' => '-1', 'facet.mincount' => '1', 'f.country.facet.missing' => 'true', 'facet.sort' => 'true')); #print_r($result); foreach ($result->highlighting as $key => $value) { foreach ($value as $k1 => $v1) { foreach ($v1 as $k2 => $v2) { echo "
". $v2 . "
"; $k = preg_replace ('/^.*?(.*)<\/em>.*?$/is', '$1', $v2); $k = preg_replace ('/|<\/em>|\W/isU', ' ', $k); $k = preg_replace ('/\s+/ism',' ', $k); echo "
".$k."-----$clean_query
"; if (strcasecmp ($k, $clean_query) == 0) { echo "---",$k , "
"; $results[$k]++; } } } #echo "
---------------------------------------------------
"; } print_r($results); foreach ($results as $key => $value) { echo $key . "~#~", $value . "
"; } } } else{ echo "Unable to ping solr"; echo 0; } unset($solr); } else echo 0; ?>