|
From: <php...@li...> - 2009-11-25 07:26:41
|
Hi all,
I've set up the PHPJavaBridge standalone as a windows service to
implement lucene search capabilities in my PHP application.
After having started the Bridge with SERVLET_LOCAL:8080 the very first
call to my script fails.
Here's what I can see in my SOAP Client:
<faultcode>SOAP-ENV:Server</faultcode>
<faultstring>Broken local connection handle fwrite() [<a
href='function.fwrite'>function.fwrite</a>]: send of 6 bytes failed
with errno=10054 Eine vorhandene Verbindung wurde vom Remotehost
geschlossen.</faultstring>
Which means an existing connection has been closed by the remote host.
Every additional call is made with success, only the the first time
fails. I assume the call to java_autoload(..) fails the first time.
here's my PHP function that encapsulates lucene searching:
++++++++++++++++++++++++++++++++++++++++++++++
public function SearchIndex ($maxrows, $searchstring) {
/**
* @desc Search in a lucene index
*
*/
try {
require_once ($this->javabridge_root."/Java.inc");
java_autoload("lucene-core-2.9.1.jar;lucene-analyzers-2.9.1.jar");
$analyzer = new
Java('org.apache.lucene.analysis.standard.StandardAnalyzer');
$indexer = new
Java('org.apache.lucene.search.IndexSearcher',$this->indexfilename);
//Lese alle indizierten Felder aus dem Index aus
$Felder_ind =
java('org.apache.lucene.index.IndexReader$FieldOption')->INDEXED;
$IndexReader =
java('org.apache.lucene.index.IndexReader')->open($this->indexfilename);
$AlleSuchfelder=java_values($IndexReader->getFieldNames($Felder_ind)->toArray());
$IndexReader->close();
//Eine Suche über alle im Index vorhandenen Suchfelder
$parser = new
Java('org.apache.lucene.queryParser.MultiFieldQueryParser',
$AlleSuchfelder,$analyzer);
}
catch (Exception $e) {
throw new Exception(utf8_encode($e));
}
$hits = array();
try {
if ($searchstring) {
$sortfield= new
Java('org.apache.lucene.search.SortField','releasedate',3, true);
$sorter= new
Java('org.apache.lucene.search.Sort',$sortfield );
//$sorter->setSort($sortfield);
$query = $parser->parse($searchstring);
$hits = $indexer->search($query,$sorter );
$num=java_values($hits->length());
//printf("3) Hits: %d\n", $num);
if ($num < $maxrows) {
$maxrows = $num;
}
$soapreturn = array();
for ($i = 0; $i < $maxrows; $i++) {
$found = $hits->doc($i);
$si = new SOAPSearchResult();
$si->wiretextId =
utf8_encode($found->get('wiretextid'));
$soapreturn[] = $si;
}
}
}
catch (Exception $e) {
throw new Exception(utf8_encode($e));
}
if(SF_ENVIRONMENT == 'soap') return $soapreturn;
}
:
|