revelance-lucene/php

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



hi,
i have a searching script that is integrated with lucene but i am not 
able to sort by relevance.following is the code 
<html>
<head><head>
<body>
<?php
#java_set_library_path("/usr/lib/jre/lib/ext/lucene-
1.4.3.jar:/usr/lib/jre/lib/ext/my.jar");

function microtime_float()
{
   list($usec, $sec) = explode(" ", microtime());
   return ((float)$usec + (float)$sec);
} 

$location="/var/www/html/test/index";
//$location = "/var/www/index/emp";
//$location = "/var/www/html/fieldsindex";
//$location = "/var/www/html/js/indexer/index";
$time_start = microtime();
$hits = new java("org.apache.lucene.search.Hits");
$indexreader = new java("org.apache.lucene.index.IndexReader");
//echo $indexreader;
$reader_ref = $indexreader->open($location);

$searcher = new java
("org.apache.lucene.search.IndexSearcher",$reader_ref);
$queryparser = new java("org.apache.lucene.queryParser.QueryParser");
$analyzer = new java("org.apache.lucene.custom.MyAnalyzer");
//$query = $queryparser->parse( 'gender:male','content',$analyzer);
$query = $queryparser->parse('sequence:(java^4)','name',$analyzer);
//$query = $queryparser->parse('salary:"0000" AND 
keywords:"php"','content',$analyzer);

$sortfield = new java("java.lang.String","DocRef");
//$sortfield = new java
("org.apache.lucene.search.SortField","sequence");
$sort = new java("org.apache.lucene.search.Sort",$sortfield);
$system = new Java('java.lang.System');
$startTime = $system->currentTimeMillis();
$hits = $searcher->search($query,$sort);
$endTime = $system->currentTimeMillis();

//$time_end = microtime(true);
$start = 0;
$max = 50;
echo "hits".$hits->length();
echo "<br>";
if ($hits->length()!=0 ) {
	if (@$_GET['startat'] && @$_GET['maxresults']) {
		$start = $_GET['startat'];
		$max = $_GET['maxresults'];
	}
	$thispage = $max;
	if ($start+$max > $hits->length()) {
        	$thispage = $hits->length()-$start;
	}
	$document = new java('org.apache.lucene.document.Document');
	
	for ($i=$start;$i<$thispage+$start;$i++) {
		$document = $hits->doc($i);
		$docref = $document->get("DocRef");
		//$docid = $document->get("docref");
		echo 'DocRef:'.$docref.'<br>';
	}
}
$search_time = ($endTime - $startTime)/1000.0;
$search_time = round($search_time,3);
echo 'search response:'.$search_time.'secs<br>';
echo 'number of hits:'.$hits->length();	
?>
<form>
<table>
<tr>
<td>
 <a href="fieldssearch.php?startat=<?=$start+$max?>&maxresults=<?
=$max?>">More</a>
</td>
</tr>
</table>
</form>
</body>
</html>


would anybody tell







PHP Data object relational mapping generator
http://www.metastorage.net/ 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/php-objects/

<*> To unsubscribe from this group, send an email to:
    php-objects-unsubscribe@xxxxxxxxxxxxxxx

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 




[Index of Archives]     [PHP Home]     [PHP Users]     [PHP Soap]     [Kernel Newbies]     [Yosemite]     [Yosemite Campsites]

  Powered by Linux