";
- if (args.length == 0) {
- System.err.println("Usage: " + usage);
- System.exit(1);
- }
- try {
- Directory directory = FSDirectory.open(new File("index"));
- IndexReader reader = IndexReader.open(directory, false); // we don't want read-only because we are about to delete
-
- Term term = new Term("path", args[0]);
- int deleted = reader.deleteDocuments(term);
-
- System.out.println("deleted " + deleted +
- " documents containing " + term);
-
- // one can also delete documents by their internal id:
- /*
- for (int i = 0; i < reader.maxDoc(); i++) {
- System.out.println("Deleting document with id " + i);
- reader.delete(i);
- }*/
-
- reader.close();
- directory.close();
-
- } catch (Exception e) {
- System.out.println(" caught a " + e.getClass() +
- "\n with message: " + e.getMessage());
- }
- }
-}
diff --git a/lucene/contrib/demo/src/java/org/apache/lucene/demo/FileDocument.java b/lucene/contrib/demo/src/java/org/apache/lucene/demo/FileDocument.java
deleted file mode 100644
index d635e6e07e7..00000000000
--- a/lucene/contrib/demo/src/java/org/apache/lucene/demo/FileDocument.java
+++ /dev/null
@@ -1,72 +0,0 @@
-package org.apache.lucene.demo;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.InputStreamReader;
-
-import org.apache.lucene.document.DateTools;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.document.Field;
-
-/** A utility for making Lucene Documents from a File. */
-
-public class FileDocument {
- /** Makes a document for a File.
-
- The document has three fields:
-
- path
--containing the pathname of the file, as a stored,
- untokenized field;
- modified
--containing the last modified date of the file as
- a field as created by DateTools; and
- contents
--containing the full contents of the file, as a
- Reader field;
- */
- public static Document Document(File f)
- throws java.io.IOException {
-
- // make a new, empty document
- Document doc = new Document();
-
- // Add the path of the file as a field named "path". Use a field that is
- // indexed (i.e. searchable), but don't tokenize the field into words.
- doc.add(new Field("path", f.getPath(), Field.Store.YES, Field.Index.NOT_ANALYZED));
-
- // Add the last modified date of the file a field named "modified". Use
- // a field that is indexed (i.e. searchable), but don't tokenize the field
- // into words.
- doc.add(new Field("modified",
- DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE),
- Field.Store.YES, Field.Index.NOT_ANALYZED));
-
- // Add the contents of the file to a field named "contents". Specify a Reader,
- // so that the text of the file is tokenized and indexed, but not stored.
- // Note that FileReader expects the file to be in UTF-8 encoding.
- // If that's not the case searching for special characters will fail.
- doc.add(new Field("contents", new InputStreamReader(new FileInputStream(f), "UTF-8")));
-
- // return the document
- return doc;
- }
-
- private FileDocument() {}
-}
-
diff --git a/lucene/contrib/demo/src/java/org/apache/lucene/demo/HTMLDocument.java b/lucene/contrib/demo/src/java/org/apache/lucene/demo/HTMLDocument.java
deleted file mode 100644
index 67cafbf2fad..00000000000
--- a/lucene/contrib/demo/src/java/org/apache/lucene/demo/HTMLDocument.java
+++ /dev/null
@@ -1,92 +0,0 @@
-package org.apache.lucene.demo;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.*;
-import org.apache.lucene.document.*;
-import org.apache.lucene.demo.html.HTMLParser;
-
-/** A utility for making Lucene Documents for HTML documents. */
-
-public class HTMLDocument {
- static char dirSep = System.getProperty("file.separator").charAt(0);
-
- public static String uid(File f) {
- // Append path and date into a string in such a way that lexicographic
- // sorting gives the same results as a walk of the file hierarchy. Thus
- // null (\u0000) is used both to separate directory components and to
- // separate the path from the date.
- return f.getPath().replace(dirSep, '\u0000') +
- "\u0000" +
- DateTools.timeToString(f.lastModified(), DateTools.Resolution.SECOND);
- }
-
- public static String uid2url(String uid) {
- String url = uid.replace('\u0000', '/'); // replace nulls with slashes
- return url.substring(0, url.lastIndexOf('/')); // remove date from end
- }
-
- public static Document Document(File f)
- throws IOException, InterruptedException {
- // make a new, empty document
- Document doc = new Document();
-
- // Add the url as a field named "path". Use a field that is
- // indexed (i.e. searchable), but don't tokenize the field into words.
- doc.add(new Field("path", f.getPath().replace(dirSep, '/'), Field.Store.YES,
- Field.Index.NOT_ANALYZED));
-
- // Add the last modified date of the file a field named "modified".
- // Use a field that is indexed (i.e. searchable), but don't tokenize
- // the field into words.
- doc.add(new Field("modified",
- DateTools.timeToString(f.lastModified(), DateTools.Resolution.MINUTE),
- Field.Store.YES, Field.Index.NOT_ANALYZED));
-
- // Add the uid as a field, so that index can be incrementally maintained.
- // This field is not stored with document, it is indexed, but it is not
- // tokenized prior to indexing.
- doc.add(new Field("uid", uid(f), Field.Store.NO, Field.Index.NOT_ANALYZED));
-
- FileInputStream fis = new FileInputStream(f);
- InputStreamReader reader = new InputStreamReader(fis, "UTF-8");
- HTMLParser parser = new HTMLParser(reader);
-
- // Add the tag-stripped contents as a Reader-valued Text field so it will
- // get tokenized and indexed.
- doc.add(new Field("contents", parser.getReader()));
-
- // add any document keywords if they exist
- String keywords = parser.getMetaTags().getProperty("keywords");
- if (keywords != null)
- doc.add(new Field("contents", keywords, Field.Store.NO, Field.Index.ANALYZED));
-
- // Add the summary as a field that is stored and returned with
- // hit documents for display.
- doc.add(new Field("summary", parser.getSummary(), Field.Store.YES, Field.Index.NO));
-
- // Add the title as a field that it can be searched and that is stored.
- doc.add(new Field("title", parser.getTitle(), Field.Store.YES, Field.Index.ANALYZED));
-
- // return the document
- return doc;
- }
-
- private HTMLDocument() {}
-}
-
diff --git a/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java b/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java
index 7652f6c0cd1..430e1f191b0 100644
--- a/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java
+++ b/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexFiles.java
@@ -17,39 +17,59 @@ package org.apache.lucene.demo;
* limitations under the License.
*/
+import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.lucene.document.NumericField;
import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
+import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.Term;
+import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.Date;
-/** Index all text files under a directory. */
+/** Index all text files under a directory. See http://lucene.apache.org/java/4_0/demo.html. */
public class IndexFiles {
private IndexFiles() {}
- static final File INDEX_DIR = new File("index");
-
/** Index all text files under a directory. */
public static void main(String[] args) {
- String usage = "java org.apache.lucene.demo.IndexFiles ";
- if (args.length == 0) {
+ String usage = "java org.apache.lucene.demo.IndexFiles"
+ + " [-index INDEX_PATH] [-docs DOCS_PATH] [-update]\n\n"
+ // TODO: Change the link with every release (or: fill in some less error-prone alternative here...)
+ + "See http://lucene.apache.org/java/4_0/demo.html for details.";
+ String indexPath = "index";
+ String docsPath = null;
+ boolean create = true;
+ for(int i=0;iWriteLineDocTask.
+ *
+ * @param writer Writer to the index where the given file/dir info will be stored
+ * @param file The file to index, or the directory to recurse into to find files to index
+ * @throws IOException
+ */
static void indexDocs(IndexWriter writer, File file)
throws IOException {
// do not try to index files that cannot be read
@@ -88,16 +149,62 @@ public class IndexFiles {
}
}
} else {
- System.out.println("adding " + file);
+
+ FileInputStream fis;
try {
- writer.addDocument(FileDocument.Document(file));
+ fis = new FileInputStream(file);
+ } catch (FileNotFoundException fnfe) {
+ // at least on windows, some temporary files raise this exception with an "access denied" message
+ // checking if the file can be read doesn't help
+ return;
}
- // at least on windows, some temporary files raise this exception with an "access denied" message
- // checking if the file can be read doesn't help
- catch (FileNotFoundException fnfe) {
+
+ try {
+
+ // make a new, empty document
+ Document doc = new Document();
+
+ // Add the path of the file as a field named "path". Use a
+ // field that is indexed (i.e. searchable), but don't tokenize
+ // the field into separate words and don't index term frequency
+ // or positional information:
+ Field pathField = new Field("path", file.getPath(), Field.Store.YES, Field.Index.NOT_ANALYZED_NO_NORMS);
+ pathField.setOmitTermFreqAndPositions(true);
+ doc.add(pathField);
+
+ // Add the last modified date of the file a field named "modified".
+ // Use a NumericField that is indexed (i.e. efficiently filterable with
+ // NumericRangeFilter). This indexes to milli-second resolution, which
+ // is often too fine. You could instead create a number based on
+ // year/month/day/hour/minutes/seconds, down the resolution you require.
+ // For example the long value 2011021714 would mean
+ // February 17, 2011, 2-3 PM.
+ NumericField modifiedField = new NumericField("modified");
+ modifiedField.setLongValue(file.lastModified());
+ doc.add(modifiedField);
+
+ // Add the contents of the file to a field named "contents". Specify a Reader,
+ // so that the text of the file is tokenized and indexed, but not stored.
+ // Note that FileReader expects the file to be in UTF-8 encoding.
+ // If that's not the case searching for special characters will fail.
+ doc.add(new Field("contents", new BufferedReader(new InputStreamReader(fis, "UTF-8"))));
+
+ if (writer.getConfig().getOpenMode() == OpenMode.CREATE) {
+ // New index, so we just add the document (no old document can be there):
+ System.out.println("adding " + file);
+ writer.addDocument(doc);
+ } else {
+ // Existing index (an old copy of this document may have been indexed) so
+ // we use updateDocument instead to replace the old one matching the exact
+ // path, if present:
+ System.out.println("updating " + file);
+ writer.updateDocument(new Term("path", file.getPath()), doc);
+ }
+
+ } finally {
+ fis.close();
}
}
}
}
-
}
diff --git a/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexHTML.java b/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexHTML.java
deleted file mode 100644
index 75090df931a..00000000000
--- a/lucene/contrib/demo/src/java/org/apache/lucene/demo/IndexHTML.java
+++ /dev/null
@@ -1,181 +0,0 @@
-package org.apache.lucene.demo;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexWriter;
-import org.apache.lucene.index.IndexWriterConfig;
-import org.apache.lucene.index.Term;
-import org.apache.lucene.index.TermsEnum;
-import org.apache.lucene.index.Terms;
-import org.apache.lucene.index.MultiFields;
-import org.apache.lucene.index.IndexWriterConfig.OpenMode;
-import org.apache.lucene.store.FSDirectory;
-import org.apache.lucene.util.Version;
-import org.apache.lucene.util.BytesRef;
-
-import java.io.File;
-import java.util.Date;
-import java.util.Arrays;
-
-/** Indexer for HTML files. */
-public class IndexHTML {
- private IndexHTML() {}
-
- private static boolean deleting = false; // true during deletion pass
- private static IndexReader reader; // existing index
- private static IndexWriter writer; // new index being built
- private static TermsEnum uidIter; // document id iterator
-
- /** Indexer for HTML files.*/
- public static void main(String[] argv) {
- try {
- File index = new File("index");
- boolean create = false;
- File root = null;
-
- String usage = "IndexHTML [-create] [-index ] ";
-
- if (argv.length == 0) {
- System.err.println("Usage: " + usage);
- return;
- }
-
- for (int i = 0; i < argv.length; i++) {
- if (argv[i].equals("-index")) { // parse -index option
- index = new File(argv[++i]);
- } else if (argv[i].equals("-create")) { // parse -create option
- create = true;
- } else if (i != argv.length-1) {
- System.err.println("Usage: " + usage);
- return;
- } else
- root = new File(argv[i]);
- }
-
- if(root == null) {
- System.err.println("Specify directory to index");
- System.err.println("Usage: " + usage);
- return;
- }
-
- Date start = new Date();
-
- if (!create) { // delete stale docs
- deleting = true;
- indexDocs(root, index, create);
- }
- writer = new IndexWriter(FSDirectory.open(index), new IndexWriterConfig(
- Version.LUCENE_CURRENT, new StandardAnalyzer(Version.LUCENE_CURRENT))
- .setOpenMode(create ? OpenMode.CREATE : OpenMode.CREATE_OR_APPEND));
- indexDocs(root, index, create); // add new docs
-
- System.out.println("Optimizing index...");
- writer.optimize();
- writer.close();
-
- Date end = new Date();
-
- System.out.print(end.getTime() - start.getTime());
- System.out.println(" total milliseconds");
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-
- /* Walk directory hierarchy in uid order, while keeping uid iterator from
- /* existing index in sync. Mismatches indicate one of: (a) old documents to
- /* be deleted; (b) unchanged documents, to be left alone; or (c) new
- /* documents, to be indexed.
- */
-
- private static void indexDocs(File file, File index, boolean create)
- throws Exception {
- if (!create) { // incrementally update
-
- reader = IndexReader.open(FSDirectory.open(index), false); // open existing index
- Terms terms = MultiFields.getTerms(reader, "uid");
- if (terms != null) {
- uidIter = terms.iterator();
-
- indexDocs(file);
-
- if (deleting) { // delete rest of stale docs
- BytesRef text;
- while ((text=uidIter.next()) != null) {
- String termText = text.utf8ToString();
- System.out.println("deleting " +
- HTMLDocument.uid2url(termText));
- reader.deleteDocuments(new Term("uid", termText));
- }
- deleting = false;
- }
- }
-
- reader.close(); // close existing index
-
- } else // don't have exisiting
- indexDocs(file);
- }
-
- private static void indexDocs(File file) throws Exception {
- if (file.isDirectory()) { // if a directory
- String[] files = file.list(); // list its files
- Arrays.sort(files); // sort the files
- for (int i = 0; i < files.length; i++) // recursively index them
- indexDocs(new File(file, files[i]));
-
- } else if (file.getPath().endsWith(".html") || // index .html files
- file.getPath().endsWith(".htm") || // index .htm files
- file.getPath().endsWith(".txt")) { // index .txt files
-
- if (uidIter != null) {
- String uid = HTMLDocument.uid(file); // construct uid for doc
-
- BytesRef text;
- while((text = uidIter.next()) != null) {
- String termText = text.utf8ToString();
- if (termText.compareTo(uid) < 0) {
- if (deleting) { // delete stale docs
- System.out.println("deleting " +
- HTMLDocument.uid2url(termText));
- reader.deleteDocuments(new Term("uid", termText));
- }
- } else {
- break;
- }
- }
- if (text != null &&
- text.utf8ToString().compareTo(uid) == 0) {
- uidIter.next(); // keep matching docs
- } else if (!deleting) { // add new docs
- Document doc = HTMLDocument.Document(file);
- System.out.println("adding " + doc.get("path"));
- writer.addDocument(doc);
- }
- } else { // creating a new index
- Document doc = HTMLDocument.Document(file);
- System.out.println("adding " + doc.get("path"));
- writer.addDocument(doc); // add docs unconditionally
- }
- }
- }
-}
diff --git a/lucene/contrib/demo/src/java/org/apache/lucene/demo/SearchFiles.java b/lucene/contrib/demo/src/java/org/apache/lucene/demo/SearchFiles.java
index 6a300459995..7d1e9292aad 100644
--- a/lucene/contrib/demo/src/java/org/apache/lucene/demo/SearchFiles.java
+++ b/lucene/contrib/demo/src/java/org/apache/lucene/demo/SearchFiles.java
@@ -27,15 +27,11 @@ import java.util.Date;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
-import org.apache.lucene.index.IndexReader;
-import org.apache.lucene.index.IndexReader.AtomicReaderContext;
import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Collector;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
-import org.apache.lucene.search.Scorer;
-import org.apache.lucene.search.TopScoreDocCollector;
+import org.apache.lucene.search.TopDocs;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Version;
@@ -47,8 +43,7 @@ public class SearchFiles {
/** Simple command-line based search demo. */
public static void main(String[] args) throws Exception {
String usage =
- "Usage:\tjava org.apache.lucene.demo.SearchFiles [-index dir] [-field f] [-repeat n] [-queries file] [-raw] [-paging hitsPerPage]";
- usage += "\n\tSpecify 'false' for hitsPerPage to use streaming instead of paging search.";
+ "Usage:\tjava org.apache.lucene.demo.SearchFiles [-index dir] [-field f] [-repeat n] [-queries file] [-query string] [-raw] [-paging hitsPerPage]\n\nSee http://lucene.apache.org/java/4_0/demo.html for details.";
if (args.length > 0 && ("-h".equals(args[0]) || "-help".equals(args[0]))) {
System.out.println(usage);
System.exit(0);
@@ -59,10 +54,10 @@ public class SearchFiles {
String queries = null;
int repeat = 0;
boolean raw = false;
- boolean paging = true;
+ String queryString = null;
int hitsPerPage = 10;
- for (int i = 0; i < args.length; i++) {
+ for(int i = 0;i < args.length;i++) {
if ("-index".equals(args[i])) {
index = args[i+1];
i++;
@@ -72,28 +67,26 @@ public class SearchFiles {
} else if ("-queries".equals(args[i])) {
queries = args[i+1];
i++;
+ } else if ("-query".equals(args[i])) {
+ queryString = args[i+1];
+ i++;
} else if ("-repeat".equals(args[i])) {
repeat = Integer.parseInt(args[i+1]);
i++;
} else if ("-raw".equals(args[i])) {
raw = true;
} else if ("-paging".equals(args[i])) {
- if (args[i+1].equals("false")) {
- paging = false;
- } else {
- hitsPerPage = Integer.parseInt(args[i+1]);
- if (hitsPerPage == 0) {
- paging = false;
- }
+ hitsPerPage = Integer.parseInt(args[i+1]);
+ if (hitsPerPage <= 0) {
+ System.err.println("There must be at least 1 hit per page.");
+ System.exit(1);
}
i++;
}
}
- IndexReader reader = IndexReader.open(FSDirectory.open(new File(index)), true); // only searching, so read-only=true
-
- IndexSearcher searcher = new IndexSearcher(reader);
- Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
+ IndexSearcher searcher = new IndexSearcher(FSDirectory.open(new File(index)));
+ Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_40);
BufferedReader in = null;
if (queries != null) {
@@ -101,23 +94,25 @@ public class SearchFiles {
} else {
in = new BufferedReader(new InputStreamReader(System.in, "UTF-8"));
}
- QueryParser parser = new QueryParser(Version.LUCENE_CURRENT, field, analyzer);
+ QueryParser parser = new QueryParser(Version.LUCENE_40, field, analyzer);
while (true) {
- if (queries == null) // prompt the user
+ if (queries == null && queryString == null) { // prompt the user
System.out.println("Enter query: ");
+ }
- String line = in.readLine();
+ String line = queryString != null ? queryString : in.readLine();
- if (line == null || line.length() == -1)
+ if (line == null || line.length() == -1) {
break;
+ }
line = line.trim();
- if (line.length() == 0)
+ if (line.length() == 0) {
break;
+ }
Query query = parser.parse(line);
System.out.println("Searching for: " + query.toString(field));
-
if (repeat > 0) { // repeat & time as benchmark
Date start = new Date();
@@ -128,52 +123,13 @@ public class SearchFiles {
System.out.println("Time: "+(end.getTime()-start.getTime())+"ms");
}
- if (paging) {
- doPagingSearch(in, searcher, query, hitsPerPage, raw, queries == null);
- } else {
- doStreamingSearch(searcher, query);
+ doPagingSearch(in, searcher, query, hitsPerPage, raw, queries == null && queryString == null);
+
+ if (queryString != null) {
+ break;
}
}
- reader.close();
- }
-
- /**
- * This method uses a custom HitCollector implementation which simply prints out
- * the docId and score of every matching document.
- *
- * This simulates the streaming search use case, where all hits are supposed to
- * be processed, regardless of their relevance.
- */
- public static void doStreamingSearch(final IndexSearcher searcher, Query query) throws IOException {
- Collector streamingHitCollector = new Collector() {
- private Scorer scorer;
- private int docBase;
-
- // simply print docId and score of every matching document
- @Override
- public void collect(int doc) throws IOException {
- System.out.println("doc=" + doc + docBase + " score=" + scorer.score());
- }
-
- @Override
- public boolean acceptsDocsOutOfOrder() {
- return true;
- }
-
- @Override
- public void setNextReader(AtomicReaderContext context)
- throws IOException {
- this.docBase = context.docBase;
- }
-
- @Override
- public void setScorer(Scorer scorer) throws IOException {
- this.scorer = scorer;
- }
-
- };
-
- searcher.search(query, streamingHitCollector);
+ searcher.close();
}
/**
@@ -190,12 +146,10 @@ public class SearchFiles {
int hitsPerPage, boolean raw, boolean interactive) throws IOException {
// Collect enough docs to show 5 pages
- TopScoreDocCollector collector = TopScoreDocCollector.create(
- 5 * hitsPerPage, false);
- searcher.search(query, collector);
- ScoreDoc[] hits = collector.topDocs().scoreDocs;
+ TopDocs results = searcher.search(query, 5 * hitsPerPage);
+ ScoreDoc[] hits = results.scoreDocs;
- int numTotalHits = collector.getTotalHits();
+ int numTotalHits = results.totalHits;
System.out.println(numTotalHits + " total matching documents");
int start = 0;
@@ -210,9 +164,7 @@ public class SearchFiles {
break;
}
- collector = TopScoreDocCollector.create(numTotalHits, false);
- searcher.search(query, collector);
- hits = collector.topDocs().scoreDocs;
+ hits = searcher.search(query, numTotalHits).scoreDocs;
}
end = Math.min(hits.length, start + hitsPerPage);
@@ -237,7 +189,7 @@ public class SearchFiles {
}
- if (!interactive) {
+ if (!interactive || end == 0) {
break;
}
@@ -279,8 +231,6 @@ public class SearchFiles {
if (quit) break;
end = Math.min(numTotalHits, start + hitsPerPage);
}
-
}
-
}
}
diff --git a/lucene/contrib/demo/src/java/org/apache/lucene/demo/html/Test.java b/lucene/contrib/demo/src/java/org/apache/lucene/demo/html/Test.java
deleted file mode 100644
index 224ae5e4784..00000000000
--- a/lucene/contrib/demo/src/java/org/apache/lucene/demo/html/Test.java
+++ /dev/null
@@ -1,51 +0,0 @@
-package org.apache.lucene.demo.html;
-
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-import java.io.*;
-
-class Test {
- public static void main(String[] argv) throws IOException, InterruptedException {
- if ("-dir".equals(argv[0])) {
- String[] files = new File(argv[1]).list();
- java.util.Arrays.sort(files);
- for (int i = 0; i < files.length; i++) {
- System.err.println(files[i]);
- File file = new File(argv[1], files[i]);
- parse(file);
- }
- } else
- parse(new File(argv[0]));
- }
-
- public static void parse(File file) throws IOException, InterruptedException {
- FileInputStream fis = null;
- try {
- fis = new FileInputStream(file);
- HTMLParser parser = new HTMLParser(fis);
- System.out.println("Title: " + Entities.encode(parser.getTitle()));
- System.out.println("Summary: " + Entities.encode(parser.getSummary()));
- System.out.println("Content:");
- LineNumberReader reader = new LineNumberReader(parser.getReader());
- for (String l = reader.readLine(); l != null; l = reader.readLine())
- System.out.println(l);
- } finally {
- if (fis != null) fis.close();
- }
- }
-}
diff --git a/lucene/contrib/demo/src/jsp/README.txt b/lucene/contrib/demo/src/jsp/README.txt
deleted file mode 100644
index 31ae0637865..00000000000
--- a/lucene/contrib/demo/src/jsp/README.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-To build the Apache Lucene web app demo just run
-"ant war-demo" from the Apache Lucene Installation
-directory (follow the master instructions in
-BUILD.txt). If you have questions please post
-them to the Apache Lucene mailing lists. To
-actually figure this out you really need to
-read the Lucene "Getting Started" guide provided
-with the doc build ("ant docs").
diff --git a/lucene/contrib/demo/src/jsp/WEB-INF/web.xml b/lucene/contrib/demo/src/jsp/WEB-INF/web.xml
deleted file mode 100755
index d6740d2c4b7..00000000000
--- a/lucene/contrib/demo/src/jsp/WEB-INF/web.xml
+++ /dev/null
@@ -1,10 +0,0 @@
-
-
-
-
-
-
-
-
diff --git a/lucene/contrib/demo/src/jsp/configuration.jsp b/lucene/contrib/demo/src/jsp/configuration.jsp
deleted file mode 100644
index eb0bcfea726..00000000000
--- a/lucene/contrib/demo/src/jsp/configuration.jsp
+++ /dev/null
@@ -1,22 +0,0 @@
-
-<%
-String appTitle = "Apache Lucene Example - Intranet Server Search Application";
-/* make sure you point the below string to the index you created with IndexHTML */
-String indexLocation = "/opt/lucene/index";
-String appfooter = "Apache Lucene Template WebApp 1.0";
-%>
diff --git a/lucene/contrib/demo/src/jsp/footer.jsp b/lucene/contrib/demo/src/jsp/footer.jsp
deleted file mode 100644
index 44127a0c3c0..00000000000
--- a/lucene/contrib/demo/src/jsp/footer.jsp
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
- <%=appfooter%>
-
-