Let's see:
import org.apache.lucene.search.*;
import org.apache.lucene.index.*;
import org.apache.lucene.analysis.SimpleAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
public class HitDocDeleteTest {
static String indexDir = "/tmp/hddt";
static int numDocsAdd = 2;
static int docId = 0;
public static void main(String[] args) throws Exception {
index();
search();
}
static void index() throws Exception {
IndexWriter writerMain = new IndexWriter(indexDir, new
SimpleAnalyzer(), true);
for (docId = 0; docId < numDocsAdd; docId++)
{
Document doc = new Document();
doc.add(Field.Text("Content", "This is for document number
" + docId));
doc.add(Field.Keyword("DocID", Integer.toString(docId)));
writerMain.addDocument(doc);
}
writerMain.optimize();
writerMain.close();
}
static void search() throws Exception {
IndexSearcher isearcher = new IndexSearcher(indexDir);
Hits hits = isearcher.search(new TermQuery(new Term("Content",
"document")));
System.out.println("HITS: " + hits.length());
System.out.println("DOC0: " + hits.doc(0));
System.out.println("DOC1: " + hits.doc(1));
IndexReader reader = IndexReader.open(indexDir);
reader.delete(1);
reader.close();
System.out.println("HITS: " + hits.length());
System.out.println("DOC0: " + hits.doc(0));
System.out.println("DOC1: " + hits.doc(1));
}
}
java HitDocDeleteTest
HITS: 2
DOC0: Document<stored/uncompressed,indexed,tokenized<Content:This is
for document number 0> stored/uncompressed,indexed<DocID:0>>
DOC1: Document<stored/uncompressed,indexed,tokenized<Content:This is
for document number 1> stored/uncompressed,indexed<DocID:1>>
HITS: 2
DOC0: Document<stored/uncompressed,indexed,tokenized<Content:This is
for document number 0> stored/uncompressed,indexed<DocID:0>>
DOC1: Document<stored/uncompressed,indexed,tokenized<Content:This is
for document number 1> stored/uncompressed,indexed<DocID:1>>
See also:
http://lucene.apache.org/java/docs/api/org/apache/lucene/index/IndexReader.html#isDeleted(int)
Otis
--- Scott Smith <[EMAIL PROTECTED]> wrote:
> Suppose I do a search and get a hit list. Before I access the hit
> list,
> my delete routine (running in another thread) comes along and deletes
> some documents. What happens if I now try to access documents that
> have
> been deleted?
>
>
>
> Scott
>
>
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]