mirror of https://github.com/apache/lucene.git
LUCENE-1084: change all IW ctors to require up-front specification of max field length; deprecated existing ones
git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@615168 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
674eae39ec
commit
ee835ccf21
|
@ -7,6 +7,11 @@ Changes in runtime behavior
|
||||||
|
|
||||||
API Changes
|
API Changes
|
||||||
|
|
||||||
|
1. LUCENE-1084: Changed all IndexWriter constructors to take an
|
||||||
|
explicit parameter for maximum field size. Deprecated all the
|
||||||
|
pre-existing constructors; these will be removed in release 3.0.
|
||||||
|
(Steven Rowe via Mike McCandless)
|
||||||
|
|
||||||
Bug fixes
|
Bug fixes
|
||||||
|
|
||||||
New features
|
New features
|
||||||
|
|
|
@ -133,7 +133,7 @@ public class StandardBenchmarker extends AbstractBenchmarker implements Benchmar
|
||||||
TestRunData trd = new TestRunData();
|
TestRunData trd = new TestRunData();
|
||||||
trd.startRun();
|
trd.startRun();
|
||||||
trd.setId(String.valueOf(i));
|
trd.setId(String.valueOf(i));
|
||||||
IndexWriter iw = new IndexWriter(params.getDirectory(), params.getAnalyzer(), true);
|
IndexWriter iw = new IndexWriter(params.getDirectory(), params.getAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
|
||||||
iw.setMergeFactor(params.getMergeFactor());
|
iw.setMergeFactor(params.getMergeFactor());
|
||||||
iw.setMaxBufferedDocs(params.getMaxBufferedDocs());
|
iw.setMaxBufferedDocs(params.getMaxBufferedDocs());
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class IndexMergeTool {
|
||||||
}
|
}
|
||||||
File mergedIndex = new File(args[0]);
|
File mergedIndex = new File(args[0]);
|
||||||
|
|
||||||
IndexWriter writer = new IndexWriter(mergedIndex, new SimpleAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(mergedIndex, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
Directory[] indexes = new Directory[args.length - 1];
|
Directory[] indexes = new Directory[args.length - 1];
|
||||||
for (int i = 1; i < args.length; i++) {
|
for (int i = 1; i < args.length; i++) {
|
||||||
|
|
|
@ -36,7 +36,8 @@ public class TestRegexQuery extends TestCase {
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
RAMDirectory directory = new RAMDirectory();
|
RAMDirectory directory = new RAMDirectory();
|
||||||
try {
|
try {
|
||||||
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field(FN, "the quick brown fox jumps over the lazy dog", Field.Store.NO, Field.Index.TOKENIZED));
|
doc.add(new Field(FN, "the quick brown fox jumps over the lazy dog", Field.Store.NO, Field.Index.TOKENIZED));
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
|
|
|
@ -36,7 +36,8 @@ public class SingleFieldTestDb {
|
||||||
docs = documents;
|
docs = documents;
|
||||||
fieldName = fName;
|
fieldName = fName;
|
||||||
Analyzer analyzer = new WhitespaceAnalyzer();
|
Analyzer analyzer = new WhitespaceAnalyzer();
|
||||||
IndexWriter writer = new IndexWriter(db, analyzer, true);
|
IndexWriter writer = new IndexWriter(db, analyzer, true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
for (int j = 0; j < docs.length; j++) {
|
for (int j = 0; j < docs.length; j++) {
|
||||||
Document d = new Document();
|
Document d = new Document();
|
||||||
d.add(new Field(fieldName, docs[j], Field.Store.NO, Field.Index.TOKENIZED));
|
d.add(new Field(fieldName, docs[j], Field.Store.NO, Field.Index.TOKENIZED));
|
||||||
|
|
|
@ -111,7 +111,7 @@ public class ListSearcher extends AbstractListModel {
|
||||||
try {
|
try {
|
||||||
// recreate the RAMDirectory
|
// recreate the RAMDirectory
|
||||||
directory = new RAMDirectory();
|
directory = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(directory, analyzer, true);
|
IndexWriter writer = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
// iterate through all rows
|
// iterate through all rows
|
||||||
for (int row=0; row < listModel.getSize(); row++){
|
for (int row=0; row < listModel.getSize(); row++){
|
||||||
|
|
|
@ -242,7 +242,7 @@ public class Syns2Index
|
||||||
int mod = 1;
|
int mod = 1;
|
||||||
|
|
||||||
// override the specific index if it already exists
|
// override the specific index if it already exists
|
||||||
IndexWriter writer = new IndexWriter(indexDir, ana, true);
|
IndexWriter writer = new IndexWriter(indexDir, ana, true, IndexWriter.MaxFieldLength.LIMITED);
|
||||||
writer.setUseCompoundFile(true); // why?
|
writer.setUseCompoundFile(true); // why?
|
||||||
// blindly up these parameters for speed
|
// blindly up these parameters for speed
|
||||||
writer.setMergeFactor( writer.getMergeFactor() * 2);
|
writer.setMergeFactor( writer.getMergeFactor() * 2);
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class IndexFiles {
|
||||||
|
|
||||||
Date start = new Date();
|
Date start = new Date();
|
||||||
try {
|
try {
|
||||||
IndexWriter writer = new IndexWriter(INDEX_DIR, new StandardAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(INDEX_DIR, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
|
||||||
System.out.println("Indexing to directory '" +INDEX_DIR+ "'...");
|
System.out.println("Indexing to directory '" +INDEX_DIR+ "'...");
|
||||||
indexDocs(writer, docDir);
|
indexDocs(writer, docDir);
|
||||||
System.out.println("Optimizing...");
|
System.out.println("Optimizing...");
|
||||||
|
|
|
@ -68,7 +68,8 @@ public class IndexHTML {
|
||||||
deleting = true;
|
deleting = true;
|
||||||
indexDocs(root, index, create);
|
indexDocs(root, index, create);
|
||||||
}
|
}
|
||||||
writer = new IndexWriter(index, new StandardAnalyzer(), create);
|
writer = new IndexWriter(index, new StandardAnalyzer(), create,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
writer.setMaxFieldLength(1000000);
|
writer.setMaxFieldLength(1000000);
|
||||||
indexDocs(root, index, create); // add new docs
|
indexDocs(root, index, create); // add new docs
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ import org.apache.lucene.store.Lock;
|
||||||
import org.apache.lucene.store.LockObtainFailedException;
|
import org.apache.lucene.store.LockObtainFailedException;
|
||||||
import org.apache.lucene.store.AlreadyClosedException;
|
import org.apache.lucene.store.AlreadyClosedException;
|
||||||
import org.apache.lucene.util.BitVector;
|
import org.apache.lucene.util.BitVector;
|
||||||
|
import org.apache.lucene.util.Parameter;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -438,6 +439,7 @@ public class IndexWriter {
|
||||||
* @param create <code>true</code> to create the index or overwrite
|
* @param create <code>true</code> to create the index or overwrite
|
||||||
* the existing one; <code>false</code> to append to the existing
|
* the existing one; <code>false</code> to append to the existing
|
||||||
* index
|
* index
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
* @throws CorruptIndexException if the index is corrupt
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
* @throws LockObtainFailedException if another writer
|
* @throws LockObtainFailedException if another writer
|
||||||
* has this index open (<code>write.lock</code> could not
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
@ -447,9 +449,9 @@ public class IndexWriter {
|
||||||
* <code>false</code> or if there is any other low-level
|
* <code>false</code> or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
*/
|
*/
|
||||||
public IndexWriter(String path, Analyzer a, boolean create)
|
public IndexWriter(String path, Analyzer a, boolean create, MaxFieldLength mfl)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(FSDirectory.getDirectory(path), a, create, true, null, true);
|
init(FSDirectory.getDirectory(path), a, create, true, null, true, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -471,10 +473,91 @@ public class IndexWriter {
|
||||||
* if it does not exist and <code>create</code> is
|
* if it does not exist and <code>create</code> is
|
||||||
* <code>false</code> or if there is any other low-level
|
* <code>false</code> or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(String,Analyzer,boolean,MaxFieldLength)} instead.
|
||||||
|
*/
|
||||||
|
public IndexWriter(String path, Analyzer a, boolean create)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(FSDirectory.getDirectory(path), a, create, true, null, true, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an IndexWriter for the index in <code>path</code>.
|
||||||
|
* Text will be analyzed with <code>a</code>. If <code>create</code>
|
||||||
|
* is true, then a new, empty index will be created in
|
||||||
|
* <code>path</code>, replacing the index already there, if any.
|
||||||
|
*
|
||||||
|
* @param path the path to the index directory
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param create <code>true</code> to create the index or overwrite
|
||||||
|
* the existing one; <code>false</code> to append to the existing
|
||||||
|
* index
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be read/written to, or
|
||||||
|
* if it does not exist and <code>create</code> is
|
||||||
|
* <code>false</code> or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(File path, Analyzer a, boolean create, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(FSDirectory.getDirectory(path), a, create, true, null, true, mfl.getLimit());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an IndexWriter for the index in <code>path</code>.
|
||||||
|
* Text will be analyzed with <code>a</code>. If <code>create</code>
|
||||||
|
* is true, then a new, empty index will be created in
|
||||||
|
* <code>path</code>, replacing the index already there, if any.
|
||||||
|
*
|
||||||
|
* @param path the path to the index directory
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param create <code>true</code> to create the index or overwrite
|
||||||
|
* the existing one; <code>false</code> to append to the existing
|
||||||
|
* index
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be read/written to, or
|
||||||
|
* if it does not exist and <code>create</code> is
|
||||||
|
* <code>false</code> or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(File,Analyzer,boolean,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(File path, Analyzer a, boolean create)
|
public IndexWriter(File path, Analyzer a, boolean create)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(FSDirectory.getDirectory(path), a, create, true, null, true);
|
init(FSDirectory.getDirectory(path), a, create, true, null, true, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an IndexWriter for the index in <code>d</code>.
|
||||||
|
* Text will be analyzed with <code>a</code>. If <code>create</code>
|
||||||
|
* is true, then a new, empty index will be created in
|
||||||
|
* <code>d</code>, replacing the index already there, if any.
|
||||||
|
*
|
||||||
|
* @param d the index directory
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param create <code>true</code> to create the index or overwrite
|
||||||
|
* the existing one; <code>false</code> to append to the existing
|
||||||
|
* index
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be read/written to, or
|
||||||
|
* if it does not exist and <code>create</code> is
|
||||||
|
* <code>false</code> or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(Directory d, Analyzer a, boolean create, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(d, a, create, false, null, true, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -496,10 +579,34 @@ public class IndexWriter {
|
||||||
* if it does not exist and <code>create</code> is
|
* if it does not exist and <code>create</code> is
|
||||||
* <code>false</code> or if there is any other low-level
|
* <code>false</code> or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(Directory,Analyzer,boolean,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(Directory d, Analyzer a, boolean create)
|
public IndexWriter(Directory d, Analyzer a, boolean create)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(d, a, create, false, null, true);
|
init(d, a, create, false, null, true, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an IndexWriter for the index in
|
||||||
|
* <code>path</code>, first creating it if it does not
|
||||||
|
* already exist. Text will be analyzed with
|
||||||
|
* <code>a</code>.
|
||||||
|
*
|
||||||
|
* @param path the path to the index directory
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be
|
||||||
|
* read/written to or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(String path, Analyzer a, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(FSDirectory.getDirectory(path), a, true, null, true, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -517,10 +624,34 @@ public class IndexWriter {
|
||||||
* @throws IOException if the directory cannot be
|
* @throws IOException if the directory cannot be
|
||||||
* read/written to or if there is any other low-level
|
* read/written to or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(String,Analyzer,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(String path, Analyzer a)
|
public IndexWriter(String path, Analyzer a)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(FSDirectory.getDirectory(path), a, true, null, true);
|
init(FSDirectory.getDirectory(path), a, true, null, true, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an IndexWriter for the index in
|
||||||
|
* <code>path</code>, first creating it if it does not
|
||||||
|
* already exist. Text will be analyzed with
|
||||||
|
* <code>a</code>.
|
||||||
|
*
|
||||||
|
* @param path the path to the index directory
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be
|
||||||
|
* read/written to or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(File path, Analyzer a, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(FSDirectory.getDirectory(path), a, true, null, true, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -538,10 +669,34 @@ public class IndexWriter {
|
||||||
* @throws IOException if the directory cannot be
|
* @throws IOException if the directory cannot be
|
||||||
* read/written to or if there is any other low-level
|
* read/written to or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(File,Analyzer,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(File path, Analyzer a)
|
public IndexWriter(File path, Analyzer a)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(FSDirectory.getDirectory(path), a, true, null, true);
|
init(FSDirectory.getDirectory(path), a, true, null, true, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an IndexWriter for the index in
|
||||||
|
* <code>d</code>, first creating it if it does not
|
||||||
|
* already exist. Text will be analyzed with
|
||||||
|
* <code>a</code>.
|
||||||
|
*
|
||||||
|
* @param d the index directory
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be
|
||||||
|
* read/written to or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(Directory d, Analyzer a, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(d, a, false, null, true, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -559,10 +714,35 @@ public class IndexWriter {
|
||||||
* @throws IOException if the directory cannot be
|
* @throws IOException if the directory cannot be
|
||||||
* read/written to or if there is any other low-level
|
* read/written to or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(Directory,Analyzer,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(Directory d, Analyzer a)
|
public IndexWriter(Directory d, Analyzer a)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(d, a, false, null, true);
|
init(d, a, false, null, true, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an IndexWriter for the index in
|
||||||
|
* <code>d</code>, first creating it if it does not
|
||||||
|
* already exist. Text will be analyzed with
|
||||||
|
* <code>a</code>.
|
||||||
|
*
|
||||||
|
* @param d the index directory
|
||||||
|
* @param autoCommit see <a href="#autoCommit">above</a>
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be
|
||||||
|
* read/written to or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(d, a, false, null, autoCommit, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -581,10 +761,39 @@ public class IndexWriter {
|
||||||
* @throws IOException if the directory cannot be
|
* @throws IOException if the directory cannot be
|
||||||
* read/written to or if there is any other low-level
|
* read/written to or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(Directory,boolean,Analyzer,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(Directory d, boolean autoCommit, Analyzer a)
|
public IndexWriter(Directory d, boolean autoCommit, Analyzer a)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(d, a, false, null, autoCommit);
|
init(d, a, false, null, autoCommit, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructs an IndexWriter for the index in <code>d</code>.
|
||||||
|
* Text will be analyzed with <code>a</code>. If <code>create</code>
|
||||||
|
* is true, then a new, empty index will be created in
|
||||||
|
* <code>d</code>, replacing the index already there, if any.
|
||||||
|
*
|
||||||
|
* @param d the index directory
|
||||||
|
* @param autoCommit see <a href="#autoCommit">above</a>
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param create <code>true</code> to create the index or overwrite
|
||||||
|
* the existing one; <code>false</code> to append to the existing
|
||||||
|
* index
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be read/written to, or
|
||||||
|
* if it does not exist and <code>create</code> is
|
||||||
|
* <code>false</code> or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, boolean create, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(d, a, create, false, null, autoCommit, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -607,10 +816,36 @@ public class IndexWriter {
|
||||||
* if it does not exist and <code>create</code> is
|
* if it does not exist and <code>create</code> is
|
||||||
* <code>false</code> or if there is any other low-level
|
* <code>false</code> or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(Directory,boolean,Analyzer,boolean,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, boolean create)
|
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, boolean create)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(d, a, create, false, null, autoCommit);
|
init(d, a, create, false, null, autoCommit, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expert: constructs an IndexWriter with a custom {@link
|
||||||
|
* IndexDeletionPolicy}, for the index in <code>d</code>,
|
||||||
|
* first creating it if it does not already exist. Text
|
||||||
|
* will be analyzed with <code>a</code>.
|
||||||
|
*
|
||||||
|
* @param d the index directory
|
||||||
|
* @param autoCommit see <a href="#autoCommit">above</a>
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param deletionPolicy see <a href="#deletionPolicy">above</a>
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be
|
||||||
|
* read/written to or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(d, a, false, deletionPolicy, autoCommit, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -630,10 +865,42 @@ public class IndexWriter {
|
||||||
* @throws IOException if the directory cannot be
|
* @throws IOException if the directory cannot be
|
||||||
* read/written to or if there is any other low-level
|
* read/written to or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(Directory,boolean,Analyzer,IndexDeletionPolicy,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, IndexDeletionPolicy deletionPolicy)
|
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, IndexDeletionPolicy deletionPolicy)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(d, a, false, deletionPolicy, autoCommit);
|
init(d, a, false, deletionPolicy, autoCommit, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Expert: constructs an IndexWriter with a custom {@link
|
||||||
|
* IndexDeletionPolicy}, for the index in <code>d</code>.
|
||||||
|
* Text will be analyzed with <code>a</code>. If
|
||||||
|
* <code>create</code> is true, then a new, empty index
|
||||||
|
* will be created in <code>d</code>, replacing the index
|
||||||
|
* already there, if any.
|
||||||
|
*
|
||||||
|
* @param d the index directory
|
||||||
|
* @param autoCommit see <a href="#autoCommit">above</a>
|
||||||
|
* @param a the analyzer to use
|
||||||
|
* @param create <code>true</code> to create the index or overwrite
|
||||||
|
* the existing one; <code>false</code> to append to the existing
|
||||||
|
* index
|
||||||
|
* @param deletionPolicy see <a href="#deletionPolicy">above</a>
|
||||||
|
* @param mfl whether or not to limit field lengths
|
||||||
|
* @throws CorruptIndexException if the index is corrupt
|
||||||
|
* @throws LockObtainFailedException if another writer
|
||||||
|
* has this index open (<code>write.lock</code> could not
|
||||||
|
* be obtained)
|
||||||
|
* @throws IOException if the directory cannot be read/written to, or
|
||||||
|
* if it does not exist and <code>create</code> is
|
||||||
|
* <code>false</code> or if there is any other low-level
|
||||||
|
* IO error
|
||||||
|
*/
|
||||||
|
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, boolean create, IndexDeletionPolicy deletionPolicy, MaxFieldLength mfl)
|
||||||
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
|
init(d, a, create, false, deletionPolicy, autoCommit, mfl.getLimit());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -659,27 +926,30 @@ public class IndexWriter {
|
||||||
* if it does not exist and <code>create</code> is
|
* if it does not exist and <code>create</code> is
|
||||||
* <code>false</code> or if there is any other low-level
|
* <code>false</code> or if there is any other low-level
|
||||||
* IO error
|
* IO error
|
||||||
|
* @deprecated This constructor will be removed in the 3.0 release.
|
||||||
|
* Use {@link #IndexWriter(Directory,boolean,Analyzer,boolean,IndexDeletionPolicy,MaxFieldLength)} instead.
|
||||||
*/
|
*/
|
||||||
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, boolean create, IndexDeletionPolicy deletionPolicy)
|
public IndexWriter(Directory d, boolean autoCommit, Analyzer a, boolean create, IndexDeletionPolicy deletionPolicy)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
init(d, a, create, false, deletionPolicy, autoCommit);
|
init(d, a, create, false, deletionPolicy, autoCommit, DEFAULT_MAX_FIELD_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(Directory d, Analyzer a, boolean closeDir, IndexDeletionPolicy deletionPolicy, boolean autoCommit)
|
private void init(Directory d, Analyzer a, boolean closeDir, IndexDeletionPolicy deletionPolicy, boolean autoCommit, int maxFieldLength)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
if (IndexReader.indexExists(d)) {
|
if (IndexReader.indexExists(d)) {
|
||||||
init(d, a, false, closeDir, deletionPolicy, autoCommit);
|
init(d, a, false, closeDir, deletionPolicy, autoCommit, maxFieldLength);
|
||||||
} else {
|
} else {
|
||||||
init(d, a, true, closeDir, deletionPolicy, autoCommit);
|
init(d, a, true, closeDir, deletionPolicy, autoCommit, maxFieldLength);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void init(Directory d, Analyzer a, final boolean create, boolean closeDir, IndexDeletionPolicy deletionPolicy, boolean autoCommit)
|
private void init(Directory d, Analyzer a, final boolean create, boolean closeDir, IndexDeletionPolicy deletionPolicy, boolean autoCommit, int maxFieldLength)
|
||||||
throws CorruptIndexException, LockObtainFailedException, IOException {
|
throws CorruptIndexException, LockObtainFailedException, IOException {
|
||||||
this.closeDir = closeDir;
|
this.closeDir = closeDir;
|
||||||
directory = d;
|
directory = d;
|
||||||
analyzer = a;
|
analyzer = a;
|
||||||
this.infoStream = defaultInfoStream;
|
this.infoStream = defaultInfoStream;
|
||||||
|
this.maxFieldLength = maxFieldLength;
|
||||||
setMessageID();
|
setMessageID();
|
||||||
|
|
||||||
if (create) {
|
if (create) {
|
||||||
|
@ -839,7 +1109,8 @@ public class IndexWriter {
|
||||||
* documents are large, be sure to set this value high enough to accomodate
|
* documents are large, be sure to set this value high enough to accomodate
|
||||||
* the expected size. If you set it to Integer.MAX_VALUE, then the only limit
|
* the expected size. If you set it to Integer.MAX_VALUE, then the only limit
|
||||||
* is your memory, but you should anticipate an OutOfMemoryError.<p/>
|
* is your memory, but you should anticipate an OutOfMemoryError.<p/>
|
||||||
* By default, no more than 10,000 terms will be indexed for a field.
|
* By default, no more than {@link IndexWriter#DEFAULT_MAX_FIELD_LENGTH} terms
|
||||||
|
* will be indexed for a field.
|
||||||
*/
|
*/
|
||||||
public void setMaxFieldLength(int maxFieldLength) {
|
public void setMaxFieldLength(int maxFieldLength) {
|
||||||
ensureOpen();
|
ensureOpen();
|
||||||
|
@ -1381,8 +1652,9 @@ public class IndexWriter {
|
||||||
* is your memory, but you should anticipate an OutOfMemoryError.<p/>
|
* is your memory, but you should anticipate an OutOfMemoryError.<p/>
|
||||||
* By default, no more than 10,000 terms will be indexed for a field.
|
* By default, no more than 10,000 terms will be indexed for a field.
|
||||||
*
|
*
|
||||||
|
* @see MaxFieldLength
|
||||||
*/
|
*/
|
||||||
private int maxFieldLength = DEFAULT_MAX_FIELD_LENGTH;
|
private int maxFieldLength;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a document to this index. If the document contains more than
|
* Adds a document to this index. If the document contains more than
|
||||||
|
@ -3359,4 +3631,35 @@ public class IndexWriter {
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specifies maximum field length in {@link IndexWriter} constructors.
|
||||||
|
* {@link IndexWriter#setMaxFieldLength(int)} overrides the value set by
|
||||||
|
* the constructor.
|
||||||
|
*/
|
||||||
|
public static final class MaxFieldLength extends Parameter implements java.io.Serializable {
|
||||||
|
|
||||||
|
private int limit;
|
||||||
|
|
||||||
|
private MaxFieldLength(String name, int limit) {
|
||||||
|
// typesafe enum pattern, no public constructor
|
||||||
|
super(name);
|
||||||
|
this.limit = limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLimit() {
|
||||||
|
return limit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Sets the maximum field length to {@link Integer#MAX_VALUE}. */
|
||||||
|
public static final MaxFieldLength UNLIMITED
|
||||||
|
= new MaxFieldLength("UNLIMITED", Integer.MAX_VALUE);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the maximum field length to
|
||||||
|
* {@link IndexWriter#DEFAULT_MAX_FIELD_LENGTH}
|
||||||
|
* */
|
||||||
|
public static final MaxFieldLength LIMITED
|
||||||
|
= new MaxFieldLength("LIMITED", DEFAULT_MAX_FIELD_LENGTH);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,7 +29,7 @@ class IndexTest {
|
||||||
try {
|
try {
|
||||||
Date start = new Date();
|
Date start = new Date();
|
||||||
IndexWriter writer = new IndexWriter(File.createTempFile("luceneTest", "idx"),
|
IndexWriter writer = new IndexWriter(File.createTempFile("luceneTest", "idx"),
|
||||||
new SimpleAnalyzer(), true);
|
new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
writer.setMergeFactor(20);
|
writer.setMergeFactor(20);
|
||||||
|
|
||||||
|
|
|
@ -50,7 +50,8 @@ public class TestDemo extends LuceneTestCase {
|
||||||
// parameter true will overwrite the index in that directory
|
// parameter true will overwrite the index in that directory
|
||||||
// if one exists):
|
// if one exists):
|
||||||
//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);
|
//Directory directory = FSDirectory.getDirectory("/tmp/testindex", true);
|
||||||
IndexWriter iwriter = new IndexWriter(directory, analyzer, true);
|
IndexWriter iwriter = new IndexWriter(directory, analyzer, true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
iwriter.setMaxFieldLength(25000);
|
iwriter.setMaxFieldLength(25000);
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
String text = "This is the text to be indexed.";
|
String text = "This is the text to be indexed.";
|
||||||
|
|
|
@ -40,7 +40,8 @@ public class TestHitIterator extends LuceneTestCase {
|
||||||
public void testIterator() throws Exception {
|
public void testIterator() throws Exception {
|
||||||
RAMDirectory directory = new RAMDirectory();
|
RAMDirectory directory = new RAMDirectory();
|
||||||
|
|
||||||
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("field", "iterator test doc 1", Field.Store.YES, Field.Index.TOKENIZED));
|
doc.add(new Field("field", "iterator test doc 1", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
|
|
|
@ -77,7 +77,8 @@ public class TestSearch extends LuceneTestCase {
|
||||||
{
|
{
|
||||||
Directory directory = new RAMDirectory();
|
Directory directory = new RAMDirectory();
|
||||||
Analyzer analyzer = new SimpleAnalyzer();
|
Analyzer analyzer = new SimpleAnalyzer();
|
||||||
IndexWriter writer = new IndexWriter(directory, analyzer, true);
|
IndexWriter writer = new IndexWriter(directory, analyzer, true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
writer.setUseCompoundFile(useCompoundFile);
|
writer.setUseCompoundFile(useCompoundFile);
|
||||||
|
|
||||||
|
|
|
@ -84,7 +84,8 @@ public class TestSearchForDuplicates extends LuceneTestCase {
|
||||||
private void doTest(PrintWriter out, boolean useCompoundFiles) throws Exception {
|
private void doTest(PrintWriter out, boolean useCompoundFiles) throws Exception {
|
||||||
Directory directory = new RAMDirectory();
|
Directory directory = new RAMDirectory();
|
||||||
Analyzer analyzer = new SimpleAnalyzer();
|
Analyzer analyzer = new SimpleAnalyzer();
|
||||||
IndexWriter writer = new IndexWriter(directory, analyzer, true);
|
IndexWriter writer = new IndexWriter(directory, analyzer, true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
writer.setUseCompoundFile(useCompoundFiles);
|
writer.setUseCompoundFile(useCompoundFiles);
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,8 @@ public class TestSnapshotDeletionPolicy extends LuceneTestCase
|
||||||
final long stopTime = System.currentTimeMillis() + 7000;
|
final long stopTime = System.currentTimeMillis() + 7000;
|
||||||
|
|
||||||
SnapshotDeletionPolicy dp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
|
SnapshotDeletionPolicy dp = new SnapshotDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
|
||||||
final IndexWriter writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp);
|
final IndexWriter writer = new IndexWriter(dir, true, new StandardAnalyzer(), dp,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
// Force frequent commits
|
// Force frequent commits
|
||||||
writer.setMaxBufferedDocs(2);
|
writer.setMaxBufferedDocs(2);
|
||||||
|
|
|
@ -37,7 +37,7 @@ public class TestCachingTokenFilter extends LuceneTestCase {
|
||||||
|
|
||||||
public void testCaching() throws IOException {
|
public void testCaching() throws IOException {
|
||||||
Directory dir = new RAMDirectory();
|
Directory dir = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer());
|
IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), IndexWriter.MaxFieldLength.LIMITED);
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
TokenStream stream = new TokenStream() {
|
TokenStream stream = new TokenStream() {
|
||||||
private int index = 0;
|
private int index = 0;
|
||||||
|
|
|
@ -33,7 +33,8 @@ public class TestCheckIndex extends LuceneTestCase {
|
||||||
|
|
||||||
public void testDeletedDocs() throws IOException {
|
public void testDeletedDocs() throws IOException {
|
||||||
MockRAMDirectory dir = new MockRAMDirectory();
|
MockRAMDirectory dir = new MockRAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
writer.setMaxBufferedDocs(2);
|
writer.setMaxBufferedDocs(2);
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("field", "aaa", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
|
doc.add(new Field("field", "aaa", Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.WITH_POSITIONS_OFFSETS));
|
||||||
|
|
|
@ -93,8 +93,8 @@ public class TestFilterIndexReader extends LuceneTestCase {
|
||||||
*/
|
*/
|
||||||
public void testFilterIndexReader() throws Exception {
|
public void testFilterIndexReader() throws Exception {
|
||||||
RAMDirectory directory = new MockRAMDirectory();
|
RAMDirectory directory = new MockRAMDirectory();
|
||||||
IndexWriter writer =
|
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true,
|
||||||
new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
Document d1 = new Document();
|
Document d1 = new Document();
|
||||||
d1.add(new Field("default","one two", Field.Store.YES, Field.Index.TOKENIZED));
|
d1.add(new Field("default","one two", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
|
|
|
@ -2656,4 +2656,26 @@ public class TestIndexWriter extends LuceneTestCase
|
||||||
public void testIOExceptionDuringWriteSegmentWithThreadsOnlyOnce() throws IOException {
|
public void testIOExceptionDuringWriteSegmentWithThreadsOnlyOnce() throws IOException {
|
||||||
_testMultipleThreadsFailure(new FailOnlyInWriteSegment(true));
|
_testMultipleThreadsFailure(new FailOnlyInWriteSegment(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// LUCENE-1084: test unlimited field length
|
||||||
|
public void testUnlimitedMaxFieldLength() throws IOException {
|
||||||
|
Directory dir = new MockRAMDirectory();
|
||||||
|
|
||||||
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), IndexWriter.MaxFieldLength.UNLIMITED);
|
||||||
|
|
||||||
|
Document doc = new Document();
|
||||||
|
StringBuffer b = new StringBuffer();
|
||||||
|
for(int i=0;i<10000;i++)
|
||||||
|
b.append(" a");
|
||||||
|
b.append(" x");
|
||||||
|
doc.add(new Field("field", b.toString(), Field.Store.NO, Field.Index.TOKENIZED));
|
||||||
|
writer.addDocument(doc);
|
||||||
|
writer.close();
|
||||||
|
|
||||||
|
IndexReader reader = IndexReader.open(dir);
|
||||||
|
Term t = new Term("field", "x");
|
||||||
|
assertEquals(1, reader.docFreq(t));
|
||||||
|
reader.close();
|
||||||
|
dir.close();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,8 @@ import org.apache.lucene.store.RAMDirectory;
|
||||||
public class TestMultiLevelSkipList extends LuceneTestCase {
|
public class TestMultiLevelSkipList extends LuceneTestCase {
|
||||||
public void testSimpleSkip() throws IOException {
|
public void testSimpleSkip() throws IOException {
|
||||||
RAMDirectory dir = new RAMDirectory();
|
RAMDirectory dir = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(dir, new PayloadAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new PayloadAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
Term term = new Term("test", "a");
|
Term term = new Term("test", "a");
|
||||||
for (int i = 0; i < 5000; i++) {
|
for (int i = 0; i < 5000; i++) {
|
||||||
Document d1 = new Document();
|
Document d1 = new Document();
|
||||||
|
|
|
@ -104,7 +104,8 @@ public class TestSegmentTermDocs extends LuceneTestCase {
|
||||||
|
|
||||||
public void testSkipTo(int indexDivisor) throws IOException {
|
public void testSkipTo(int indexDivisor) throws IOException {
|
||||||
Directory dir = new RAMDirectory();
|
Directory dir = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
Term ta = new Term("content","aaa");
|
Term ta = new Term("content","aaa");
|
||||||
for(int i = 0; i < 10; i++)
|
for(int i = 0; i < 10; i++)
|
||||||
|
|
|
@ -75,10 +75,10 @@ public class BaseTestRangeFilter extends LuceneTestCase {
|
||||||
try {
|
try {
|
||||||
|
|
||||||
/* build an index */
|
/* build an index */
|
||||||
IndexWriter writer = new IndexWriter(index,
|
IndexWriter writer = new IndexWriter(index, new SimpleAnalyzer(), T,
|
||||||
new SimpleAnalyzer(), T);
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
for (int d = minId; d <= maxId; d++) {
|
for (int d = minId; d <= maxId; d++) {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("id",pad(d), Field.Store.YES, Field.Index.UN_TOKENIZED));
|
doc.add(new Field("id",pad(d), Field.Store.YES, Field.Index.UN_TOKENIZED));
|
||||||
int r= rand.nextInt();
|
int r= rand.nextInt();
|
||||||
|
|
|
@ -67,11 +67,10 @@ public class TestConstantScoreRangeQuery extends BaseTestRangeFilter {
|
||||||
};
|
};
|
||||||
|
|
||||||
small = new RAMDirectory();
|
small = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(small,
|
IndexWriter writer = new IndexWriter(small, new WhitespaceAnalyzer(), true,
|
||||||
new WhitespaceAnalyzer(),
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
true);
|
|
||||||
|
for (int i = 0; i < data.length; i++) {
|
||||||
for (int i = 0; i < data.length; i++) {
|
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("id", String.valueOf(i), Field.Store.YES, Field.Index.UN_TOKENIZED));//Field.Keyword("id",String.valueOf(i)));
|
doc.add(new Field("id", String.valueOf(i), Field.Store.YES, Field.Index.UN_TOKENIZED));//Field.Keyword("id",String.valueOf(i)));
|
||||||
doc.add(new Field("all", "all", Field.Store.YES, Field.Index.UN_TOKENIZED));//Field.Keyword("all","all"));
|
doc.add(new Field("all", "all", Field.Store.YES, Field.Index.UN_TOKENIZED));//Field.Keyword("all","all"));
|
||||||
|
|
|
@ -49,7 +49,8 @@ public class TestDateSort extends TestCase {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
// Create an index writer.
|
// Create an index writer.
|
||||||
directory = new RAMDirectory();
|
directory = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
// oldest doc:
|
// oldest doc:
|
||||||
// Add the first document. text = "Document 1" dateTime = Oct 10 03:25:22 EDT 2007
|
// Add the first document. text = "Document 1" dateTime = Oct 10 03:25:22 EDT 2007
|
||||||
|
|
|
@ -64,7 +64,8 @@ public class TestExplanations extends LuceneTestCase {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
RAMDirectory directory = new RAMDirectory();
|
RAMDirectory directory = new RAMDirectory();
|
||||||
IndexWriter writer= new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
IndexWriter writer= new IndexWriter(directory, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
for (int i = 0; i < docFields.length; i++) {
|
for (int i = 0; i < docFields.length; i++) {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.TOKENIZED));
|
doc.add(new Field(FIELD, docFields[i], Field.Store.NO, Field.Index.TOKENIZED));
|
||||||
|
|
|
@ -114,11 +114,13 @@ public class TestMultiSearcherRanking extends LuceneTestCase {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
// create MultiSearcher from two seperate searchers
|
// create MultiSearcher from two seperate searchers
|
||||||
Directory d1 = new RAMDirectory();
|
Directory d1 = new RAMDirectory();
|
||||||
IndexWriter iw1 = new IndexWriter(d1, new StandardAnalyzer(), true);
|
IndexWriter iw1 = new IndexWriter(d1, new StandardAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
addCollection1(iw1);
|
addCollection1(iw1);
|
||||||
iw1.close();
|
iw1.close();
|
||||||
Directory d2 = new RAMDirectory();
|
Directory d2 = new RAMDirectory();
|
||||||
IndexWriter iw2 = new IndexWriter(d2, new StandardAnalyzer(), true);
|
IndexWriter iw2 = new IndexWriter(d2, new StandardAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
addCollection2(iw2);
|
addCollection2(iw2);
|
||||||
iw2.close();
|
iw2.close();
|
||||||
|
|
||||||
|
@ -129,7 +131,8 @@ public class TestMultiSearcherRanking extends LuceneTestCase {
|
||||||
|
|
||||||
// create IndexSearcher which contains all documents
|
// create IndexSearcher which contains all documents
|
||||||
Directory d = new RAMDirectory();
|
Directory d = new RAMDirectory();
|
||||||
IndexWriter iw = new IndexWriter(d, new StandardAnalyzer(), true);
|
IndexWriter iw = new IndexWriter(d, new StandardAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
addCollection1(iw);
|
addCollection1(iw);
|
||||||
addCollection2(iw);
|
addCollection2(iw);
|
||||||
iw.close();
|
iw.close();
|
||||||
|
|
|
@ -55,7 +55,8 @@ public class TestPhraseQuery extends LuceneTestCase {
|
||||||
return 100;
|
return 100;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
IndexWriter writer = new IndexWriter(directory, analyzer, true);
|
IndexWriter writer = new IndexWriter(directory, analyzer, true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("field", "one two three four five", Field.Store.YES, Field.Index.TOKENIZED));
|
doc.add(new Field("field", "one two three four five", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
|
@ -201,7 +202,8 @@ public class TestPhraseQuery extends LuceneTestCase {
|
||||||
public void testPhraseQueryWithStopAnalyzer() throws Exception {
|
public void testPhraseQueryWithStopAnalyzer() throws Exception {
|
||||||
RAMDirectory directory = new RAMDirectory();
|
RAMDirectory directory = new RAMDirectory();
|
||||||
StopAnalyzer stopAnalyzer = new StopAnalyzer();
|
StopAnalyzer stopAnalyzer = new StopAnalyzer();
|
||||||
IndexWriter writer = new IndexWriter(directory, stopAnalyzer, true);
|
IndexWriter writer = new IndexWriter(directory, stopAnalyzer, true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("field", "the stop words are here", Field.Store.YES, Field.Index.TOKENIZED));
|
doc.add(new Field("field", "the stop words are here", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
|
@ -232,7 +234,8 @@ public class TestPhraseQuery extends LuceneTestCase {
|
||||||
|
|
||||||
public void testPhraseQueryInConjunctionScorer() throws Exception {
|
public void testPhraseQueryInConjunctionScorer() throws Exception {
|
||||||
RAMDirectory directory = new RAMDirectory();
|
RAMDirectory directory = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("source", "marketing info", Field.Store.YES, Field.Index.TOKENIZED));
|
doc.add(new Field("source", "marketing info", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
|
@ -267,7 +270,8 @@ public class TestPhraseQuery extends LuceneTestCase {
|
||||||
|
|
||||||
searcher.close();
|
searcher.close();
|
||||||
|
|
||||||
writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
doc = new Document();
|
doc = new Document();
|
||||||
doc.add(new Field("contents", "map entry woo", Field.Store.YES, Field.Index.TOKENIZED));
|
doc.add(new Field("contents", "map entry woo", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
writer.addDocument(doc);
|
writer.addDocument(doc);
|
||||||
|
@ -316,7 +320,8 @@ public class TestPhraseQuery extends LuceneTestCase {
|
||||||
|
|
||||||
public void testSlopScoring() throws IOException {
|
public void testSlopScoring() throws IOException {
|
||||||
Directory directory = new RAMDirectory();
|
Directory directory = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(directory, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("field", "foo firstname lastname foo", Field.Store.YES, Field.Index.TOKENIZED));
|
doc.add(new Field("field", "foo firstname lastname foo", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
|
|
|
@ -66,7 +66,8 @@ public class TestPositionIncrement extends LuceneTestCase {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
RAMDirectory store = new RAMDirectory();
|
RAMDirectory store = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(store, analyzer, true);
|
IndexWriter writer = new IndexWriter(store, analyzer, true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
Document d = new Document();
|
Document d = new Document();
|
||||||
d.add(new Field("field", "bogus", Field.Store.YES, Field.Index.TOKENIZED));
|
d.add(new Field("field", "bogus", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
writer.addDocument(d);
|
writer.addDocument(d);
|
||||||
|
|
|
@ -55,7 +55,8 @@ public class TestRemoteCachingWrapperFilter extends LuceneTestCase {
|
||||||
private static void startServer() throws Exception {
|
private static void startServer() throws Exception {
|
||||||
// construct an index
|
// construct an index
|
||||||
RAMDirectory indexStore = new RAMDirectory();
|
RAMDirectory indexStore = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(indexStore,new SimpleAnalyzer(),true);
|
IndexWriter writer = new IndexWriter(indexStore, new SimpleAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("test", "test text", Field.Store.YES, Field.Index.TOKENIZED));
|
doc.add(new Field("test", "test text", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
doc.add(new Field("type", "A", Field.Store.YES, Field.Index.TOKENIZED));
|
doc.add(new Field("type", "A", Field.Store.YES, Field.Index.TOKENIZED));
|
||||||
|
|
|
@ -51,7 +51,8 @@ public class TestSimilarity extends LuceneTestCase {
|
||||||
|
|
||||||
public void testSimilarity() throws Exception {
|
public void testSimilarity() throws Exception {
|
||||||
RAMDirectory store = new RAMDirectory();
|
RAMDirectory store = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(store, new SimpleAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
writer.setSimilarity(new SimpleSimilarity());
|
writer.setSimilarity(new SimpleSimilarity());
|
||||||
|
|
||||||
Document d1 = new Document();
|
Document d1 = new Document();
|
||||||
|
|
|
@ -41,7 +41,8 @@ public class TestSpanQueryFilter extends LuceneTestCase {
|
||||||
|
|
||||||
public void testFilterWorks() throws Exception {
|
public void testFilterWorks() throws Exception {
|
||||||
Directory dir = new RAMDirectory();
|
Directory dir = new RAMDirectory();
|
||||||
IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
for (int i = 0; i < 500; i++) {
|
for (int i = 0; i < 500; i++) {
|
||||||
Document document = new Document();
|
Document document = new Document();
|
||||||
document.add(new Field("field", English.intToEnglish(i) + " equals " + English.intToEnglish(i),
|
document.add(new Field("field", English.intToEnglish(i) + " equals " + English.intToEnglish(i),
|
||||||
|
|
|
@ -41,8 +41,8 @@ public class TestTermVectors extends LuceneTestCase {
|
||||||
|
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
IndexWriter writer
|
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true,
|
||||||
= new IndexWriter(directory, new SimpleAnalyzer(), true);
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
//writer.setUseCompoundFile(true);
|
//writer.setUseCompoundFile(true);
|
||||||
//writer.infoStream = System.out;
|
//writer.infoStream = System.out;
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
@ -201,7 +201,8 @@ public class TestTermVectors extends LuceneTestCase {
|
||||||
Directory dir = new RAMDirectory();
|
Directory dir = new RAMDirectory();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new SimpleAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
assertTrue(writer != null);
|
assertTrue(writer != null);
|
||||||
writer.addDocument(testDoc1);
|
writer.addDocument(testDoc1);
|
||||||
writer.addDocument(testDoc2);
|
writer.addDocument(testDoc2);
|
||||||
|
@ -318,7 +319,8 @@ public class TestTermVectors extends LuceneTestCase {
|
||||||
|
|
||||||
// Test only a few docs having vectors
|
// Test only a few docs having vectors
|
||||||
public void testRareVectors() throws IOException {
|
public void testRareVectors() throws IOException {
|
||||||
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
for(int i=0;i<100;i++) {
|
for(int i=0;i<100;i++) {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("field", English.intToEnglish(i),
|
doc.add(new Field("field", English.intToEnglish(i),
|
||||||
|
@ -349,7 +351,8 @@ public class TestTermVectors extends LuceneTestCase {
|
||||||
// In a single doc, for the same field, mix the term
|
// In a single doc, for the same field, mix the term
|
||||||
// vectors up
|
// vectors up
|
||||||
public void testMixedVectrosVectors() throws IOException {
|
public void testMixedVectrosVectors() throws IOException {
|
||||||
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
doc.add(new Field("field", "one",
|
doc.add(new Field("field", "one",
|
||||||
Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
|
Field.Store.YES, Field.Index.TOKENIZED, Field.TermVector.NO));
|
||||||
|
|
|
@ -88,7 +88,8 @@ public abstract class FunctionTestSetup extends LuceneTestCase {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
dir = new RAMDirectory();
|
dir = new RAMDirectory();
|
||||||
anlzr = new StandardAnalyzer();
|
anlzr = new StandardAnalyzer();
|
||||||
IndexWriter iw = new IndexWriter(dir,anlzr);
|
IndexWriter iw = new IndexWriter(dir, anlzr,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
// add docs not exactly in natural ID order, to verify we do check the order of docs by scores
|
// add docs not exactly in natural ID order, to verify we do check the order of docs by scores
|
||||||
int remaining = N_DOCS;
|
int remaining = N_DOCS;
|
||||||
boolean done[] = new boolean[N_DOCS];
|
boolean done[] = new boolean[N_DOCS];
|
||||||
|
|
|
@ -50,8 +50,8 @@ public class TestBasics extends LuceneTestCase {
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
super.setUp();
|
super.setUp();
|
||||||
RAMDirectory directory = new RAMDirectory();
|
RAMDirectory directory = new RAMDirectory();
|
||||||
IndexWriter writer
|
IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true,
|
||||||
= new IndexWriter(directory, new SimpleAnalyzer(), true);
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
//writer.infoStream = System.out;
|
//writer.infoStream = System.out;
|
||||||
for (int i = 0; i < 1000; i++) {
|
for (int i = 0; i < 1000; i++) {
|
||||||
Document doc = new Document();
|
Document doc = new Document();
|
||||||
|
|
|
@ -49,7 +49,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
// Lock prefix should have been set:
|
// Lock prefix should have been set:
|
||||||
assertTrue("lock prefix was not set by the RAMDirectory", lf.lockPrefixSet);
|
assertTrue("lock prefix was not set by the RAMDirectory", lf.lockPrefixSet);
|
||||||
|
|
||||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
// add 100 documents (so that commit lock is used)
|
// add 100 documents (so that commit lock is used)
|
||||||
for (int i = 0; i < 100; i++) {
|
for (int i = 0; i < 100; i++) {
|
||||||
|
@ -82,13 +83,15 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
assertTrue("RAMDirectory.setLockFactory did not take",
|
assertTrue("RAMDirectory.setLockFactory did not take",
|
||||||
NoLockFactory.class.isInstance(dir.getLockFactory()));
|
NoLockFactory.class.isInstance(dir.getLockFactory()));
|
||||||
|
|
||||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
// Create a 2nd IndexWriter. This is normally not allowed but it should run through since we're not
|
// Create a 2nd IndexWriter. This is normally not allowed but it should run through since we're not
|
||||||
// using any locks:
|
// using any locks:
|
||||||
IndexWriter writer2 = null;
|
IndexWriter writer2 = null;
|
||||||
try {
|
try {
|
||||||
writer2 = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
writer2 = new IndexWriter(dir, new WhitespaceAnalyzer(), false,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
fail("Should not have hit an IOException with no locking");
|
fail("Should not have hit an IOException with no locking");
|
||||||
|
@ -108,12 +111,14 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
assertTrue("RAMDirectory did not use correct LockFactory: got " + dir.getLockFactory(),
|
assertTrue("RAMDirectory did not use correct LockFactory: got " + dir.getLockFactory(),
|
||||||
SingleInstanceLockFactory.class.isInstance(dir.getLockFactory()));
|
SingleInstanceLockFactory.class.isInstance(dir.getLockFactory()));
|
||||||
|
|
||||||
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
// Create a 2nd IndexWriter. This should fail:
|
// Create a 2nd IndexWriter. This should fail:
|
||||||
IndexWriter writer2 = null;
|
IndexWriter writer2 = null;
|
||||||
try {
|
try {
|
||||||
writer2 = new IndexWriter(dir, new WhitespaceAnalyzer(), false);
|
writer2 = new IndexWriter(dir, new WhitespaceAnalyzer(), false,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
fail("Should have hit an IOException with two IndexWriters on default SingleInstanceLockFactory");
|
fail("Should have hit an IOException with two IndexWriters on default SingleInstanceLockFactory");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
@ -129,7 +134,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
public void testDefaultFSDirectory() throws IOException {
|
public void testDefaultFSDirectory() throws IOException {
|
||||||
String indexDirName = "index.TestLockFactory1";
|
String indexDirName = "index.TestLockFactory1";
|
||||||
|
|
||||||
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
||||||
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()) ||
|
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()) ||
|
||||||
|
@ -139,7 +145,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
|
|
||||||
// Create a 2nd IndexWriter. This should fail:
|
// Create a 2nd IndexWriter. This should fail:
|
||||||
try {
|
try {
|
||||||
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false);
|
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
fail("Should have hit an IOException with two IndexWriters on default SimpleFSLockFactory");
|
fail("Should have hit an IOException with two IndexWriters on default SimpleFSLockFactory");
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
}
|
}
|
||||||
|
@ -157,7 +164,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
public void testFSDirectoryTwoCreates() throws IOException {
|
public void testFSDirectoryTwoCreates() throws IOException {
|
||||||
String indexDirName = "index.TestLockFactory2";
|
String indexDirName = "index.TestLockFactory2";
|
||||||
|
|
||||||
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
||||||
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()) ||
|
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()) ||
|
||||||
|
@ -180,7 +188,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
// Create a 2nd IndexWriter. This should not fail:
|
// Create a 2nd IndexWriter. This should not fail:
|
||||||
IndexWriter writer2 = null;
|
IndexWriter writer2 = null;
|
||||||
try {
|
try {
|
||||||
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
|
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
fail("Should not have hit an IOException with two IndexWriters with create=true, on default SimpleFSLockFactory");
|
fail("Should not have hit an IOException with two IndexWriters with create=true, on default SimpleFSLockFactory");
|
||||||
|
@ -213,28 +222,32 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
|
|
||||||
// NoLockFactory:
|
// NoLockFactory:
|
||||||
System.setProperty(prpName, "org.apache.lucene.store.NoLockFactory");
|
System.setProperty(prpName, "org.apache.lucene.store.NoLockFactory");
|
||||||
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
||||||
NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
// SingleInstanceLockFactory:
|
// SingleInstanceLockFactory:
|
||||||
System.setProperty(prpName, "org.apache.lucene.store.SingleInstanceLockFactory");
|
System.setProperty(prpName, "org.apache.lucene.store.SingleInstanceLockFactory");
|
||||||
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
|
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
||||||
SingleInstanceLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
SingleInstanceLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
// NativeFSLockFactory:
|
// NativeFSLockFactory:
|
||||||
System.setProperty(prpName, "org.apache.lucene.store.NativeFSLockFactory");
|
System.setProperty(prpName, "org.apache.lucene.store.NativeFSLockFactory");
|
||||||
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
|
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
||||||
NativeFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
NativeFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
||||||
writer.close();
|
writer.close();
|
||||||
|
|
||||||
// SimpleFSLockFactory:
|
// SimpleFSLockFactory:
|
||||||
System.setProperty(prpName, "org.apache.lucene.store.SimpleFSLockFactory");
|
System.setProperty(prpName, "org.apache.lucene.store.SimpleFSLockFactory");
|
||||||
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
|
writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
assertTrue("FSDirectory did not use correct LockFactory: got " + writer.getDirectory().getLockFactory(),
|
||||||
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
SimpleFSLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
||||||
writer.close();
|
writer.close();
|
||||||
|
@ -254,7 +267,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
assertTrue("Locks are already disabled", !FSDirectory.getDisableLocks());
|
assertTrue("Locks are already disabled", !FSDirectory.getDisableLocks());
|
||||||
FSDirectory.setDisableLocks(true);
|
FSDirectory.setDisableLocks(true);
|
||||||
|
|
||||||
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true);
|
IndexWriter writer = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
|
|
||||||
assertTrue("FSDirectory did not use correct default LockFactory: got " + writer.getDirectory().getLockFactory(),
|
assertTrue("FSDirectory did not use correct default LockFactory: got " + writer.getDirectory().getLockFactory(),
|
||||||
NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
NoLockFactory.class.isInstance(writer.getDirectory().getLockFactory()));
|
||||||
|
@ -262,7 +276,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
// Should be no error since locking is disabled:
|
// Should be no error since locking is disabled:
|
||||||
IndexWriter writer2 = null;
|
IndexWriter writer2 = null;
|
||||||
try {
|
try {
|
||||||
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false);
|
writer2 = new IndexWriter(indexDirName, new WhitespaceAnalyzer(), false,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace(System.out);
|
e.printStackTrace(System.out);
|
||||||
fail("Should not have hit an IOException with locking disabled");
|
fail("Should not have hit an IOException with locking disabled");
|
||||||
|
@ -328,7 +343,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
FSDirectory fs1 = FSDirectory.getDirectory(indexDirName, lockFactory);
|
FSDirectory fs1 = FSDirectory.getDirectory(indexDirName, lockFactory);
|
||||||
|
|
||||||
// First create a 1 doc index:
|
// First create a 1 doc index:
|
||||||
IndexWriter w = new IndexWriter(fs1, new WhitespaceAnalyzer(), true);
|
IndexWriter w = new IndexWriter(fs1, new WhitespaceAnalyzer(), true,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
addDoc(w);
|
addDoc(w);
|
||||||
w.close();
|
w.close();
|
||||||
|
|
||||||
|
@ -418,7 +434,8 @@ public class TestLockFactory extends LuceneTestCase {
|
||||||
IndexWriter writer = null;
|
IndexWriter writer = null;
|
||||||
for(int i=0;i<this.numIteration;i++) {
|
for(int i=0;i<this.numIteration;i++) {
|
||||||
try {
|
try {
|
||||||
writer = new IndexWriter(dir, analyzer, false);
|
writer = new IndexWriter(dir, analyzer, false,
|
||||||
|
IndexWriter.MaxFieldLength.LIMITED);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
if (e.toString().indexOf(" timed out:") == -1) {
|
if (e.toString().indexOf(" timed out:") == -1) {
|
||||||
hitException = true;
|
hitException = true;
|
||||||
|
|
Loading…
Reference in New Issue