lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dian puma <dianp...@gmail.com>
Subject Delete Document from Index. How?
Date Thu, 11 Nov 2010 06:54:12 GMT
Hi All,

I'm struggling with Lucene on deleting a specific document from the index.
I've read the book Lucene in Action to see how to do it.
There are 2 ways to delete documents from index, using
IndexWriter.deleteDocuments(term) OR IndexReader.deleteDocuments.
CMIIW

FYI, I use PHP/Java Bridge and Lucene 2.2,
But my code below didn't work, generating error:

Exception occured: [[o:Exception]:"java.lang.Exception: Invoke failed:
[[o:IndexWriter]]->deleteDocuments([o:Term]). Cause:
java.lang.NoSuchMethodException: deleteDocuments([o:Term]).
Candidates: [] Responsible VM: 1.6.0_20@http://java.sun.com/" at: #-5
php.java.bridge.JavaBridge.Invoke(JavaBridge.java:1045) #-4
php.java.bridge.Request.handleRequest(Request.java:342) #-3
php.java.bridge.Request.handleRequests(Request.java:388) #0
Java.inc(161): java_ThrowExceptionProxyFactory->getProxy(4, true) #1
Java.inc(314): java_Arg->getResult(true) #2 Java.inc(320):
java_Client->getWrappedResult(true) #3 Java.inc(499):
java_Client->getResult() #4 Java.inc(743):
java_Client->invokeMethod(2, 'deleteDocuments', Array) #5
Java.inc(861): java_JavaProxy->__call('deleteDocuments', Array) #6
[internal function]: Java->__call('deleteDocuments', Array)

============= snippet code with IndexWriter =============
$directory = dirname(__FILE__)."/../indexLucene/";
$path = getcwd()."/txtfiles/testing.txt";

if (strlen($path) > 0) {
       //delete
       echo "Delete [".$path."]</br>";
       $analyzer_idx = new
Java('org.apache.lucene.analysis.standard.StandardAnalyzer');
       $writer_idx = new
java("org.apache.lucene.index.IndexWriter",$directory, $analyzer_idx,
false);
       echo java_values($writer_idx->docCount());
       $term = new Java('org.apache.lucene.index.Term','pathfile',$path);
       $writer_idx->deleteDocuments($term);
       $writer_idx->close();
}//end if


Then, I tried to use IndexReader, instead.
But, even worst. It failed to echo the numDocs or just to close the reader.

error message:
Exception occured: [[o:Exception]:"java.lang.Exception: Invoke failed:
[[c:IndexReader]]->numDocs. Cause: java.lang.NoSuchMethodException:
numDocs()........................

======= snippet code with IndexReader ========
$directory = dirname(__FILE__)."/../indexLucene/";
$path = getcwd()."/txtfiles/testing.txt";
$reader = new Java('org.apache.lucene.index.IndexReader');
$reader->open($directory);
//echo java_values($reader->numDocs());
$reader->close();

Hopefully someone would help me for this.
Thanks in advance
--
Dian Puma

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message