Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-1558: default readOnly=true for IndexReader.open(Dir) and new IndexSearcher(Dir)

Michael McCandlessce423d5d3ba4
diff --git a/CHANGES.txt b/CHANGES.txt
index 96749edc452..d762a76800d 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -30,6 +30,11 @@ Changes in backwards compatibility policy
overridden methods unchanged and added varargs to constructors,
static, or final methods (MultiSearcher,...). (Uwe Schindler)
+* LUCENE-1558: IndexReader.open(Directory) now opens a readOnly=true
+ reader, and new IndexSearcher(Directory) does the same. Note that
+ this is a change in the default from 2.9, when these methods were
+ previously deprecated. (Mike McCandless)
+
Changes in runtime behavior
* LUCENE-1677: Remove the system property to set SegmentReader class
diff --git a/src/java/org/apache/lucene/index/IndexReader.java b/src/java/org/apache/lucene/index/IndexReader.java
index fa32cb449bf..48a6a763a8a 100644
--- a/src/java/org/apache/lucene/index/IndexReader.java
+++ b/src/java/org/apache/lucene/index/IndexReader.java
@@ -178,6 +178,16 @@ public abstract class IndexReader implements Cloneable,Closeable {
}
}
+ /** Returns a IndexReader reading the index in the given
+ * Directory, with readOnly=true.
+ * @param directory the index directory
+ * @throws CorruptIndexException if the index is corrupt
+ * @throws IOException if there is a low-level IO error
+ */
+ public static IndexReader open(final Directory directory) throws CorruptIndexException, IOException {
+ return open(directory, null, null, true, DEFAULT_TERMS_INDEX_DIVISOR);
+ }
+
/** Returns an IndexReader reading the index in the given
* Directory. You should pass readOnly=true, since it
* gives much better concurrent performance, unless you
diff --git a/src/java/org/apache/lucene/search/IndexSearcher.java b/src/java/org/apache/lucene/search/IndexSearcher.java
index 0fb82a34284..2120f421312 100644
--- a/src/java/org/apache/lucene/search/IndexSearcher.java
+++ b/src/java/org/apache/lucene/search/IndexSearcher.java
@@ -53,6 +53,16 @@ public class IndexSearcher extends Searcher {
protected IndexReader[] subReaders;
protected int[] docStarts;
+ /** Creates a searcher searching the index in the named
+ * directory, with readOnly=true
+ * @throws CorruptIndexException if the index is corrupt
+ * @throws IOException if there is a low-level IO error
+ * @param path directory where IndexReader will be opened
+ */
+ public IndexSearcher(Directory path) throws CorruptIndexException, IOException {
+ this(IndexReader.open(path, true), true);
+ }
+
/** Creates a searcher searching the index in the named
* directory. You should pass readOnly=true, since it
* gives much better concurrent performance, unless you
@@ -179,14 +189,6 @@ public class IndexSearcher extends Searcher {
public TopFieldDocs search(Weight weight, Filter filter, final int nDocs,
Sort sort, boolean fillFields)
throws IOException {
-
- SortField[] fields = sort.fields;
- for(int i = 0; i < fields.length; i++) {
- SortField field = fields[i];
- String fieldname = field.getField();
- int type = field.getType();
- }
-
TopFieldCollector collector = TopFieldCollector.create(sort, nDocs,
fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.scoresDocsOutOfOrder());
search(weight, filter, collector);