From c027596aa2dec18bfc6f1447162b50927de6adf7 Mon Sep 17 00:00:00 2001
From: Daniel Naber
Date: Sun, 12 Oct 2008 21:24:56 +0000
Subject: [PATCH] update example so no deprecated code is used
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@703881 13f79535-47bb-0310-9956-ffa450edef68
---
src/java/overview.html | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/src/java/overview.html b/src/java/overview.html
index 388a61a0d1d..19408dc4953 100644
--- a/src/java/overview.html
+++ b/src/java/overview.html
@@ -24,6 +24,7 @@
Here's a simple example how to use Lucene for indexing and searching (using JUnit
to check if the results are what we expect):
+
@@ -40,14 +41,13 @@ to check if the results are what we expect):
Directory directory = new RAMDirectory();
// To store an index on disk, use this instead:
//Directory directory = FSDirectory.getDirectory("/tmp/testindex");
- IndexWriter iwriter = new IndexWriter(directory, analyzer, true);
- iwriter.setMaxFieldLength(25000);
+ IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
+ new IndexWriter.MaxFieldLength(25000));
Document doc = new Document();
String text = "This is the text to be indexed.";
doc.add(new Field("fieldname", text, Field.Store.YES,
- Field.Index.TOKENIZED));
+ Field.Index.ANALYZED));
iwriter.addDocument(doc);
- iwriter.optimize();
iwriter.close();
// Now search the index:
@@ -55,11 +55,11 @@ to check if the results are what we expect):
// Parse a simple query that searches for "text":
QueryParser parser = new QueryParser("fieldname", analyzer);
Query query = parser.parse("text");
- Hits hits = isearcher.search(query);
- assertEquals(1, hits.length());
+ ScoreDoc[] hits = isearcher.search(query, null, 1000).scoreDocs;
+ assertEquals(1, hits.length);
// Iterate through the results:
- for (int i = 0; i < hits.length(); i++) {
- Document hitDoc = hits.doc(i);
+ for (int i = 0; i < hits.length; i++) {
+ Document hitDoc = isearcher.doc(hits[i].doc);
assertEquals("This is the text to be indexed.", hitDoc.get("fieldname"));
}
isearcher.close();