mirror of https://github.com/apache/lucene.git
LUCENE-2858: fix modules facet (partially)
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2858@1237330 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4ef047b892
commit
acefe212c1
|
@ -4,7 +4,7 @@ import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
|
||||||
import org.apache.lucene.search.Collector;
|
import org.apache.lucene.search.Collector;
|
||||||
import org.apache.lucene.search.Scorer;
|
import org.apache.lucene.search.Scorer;
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ package org.apache.lucene.facet.search;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexReader.AtomicReaderContext;
|
import org.apache.lucene.index.AtomicIndexReader.AtomicReaderContext;
|
||||||
import org.apache.lucene.search.Collector;
|
import org.apache.lucene.search.Collector;
|
||||||
import org.apache.lucene.search.DocIdSet;
|
import org.apache.lucene.search.DocIdSet;
|
||||||
import org.apache.lucene.search.DocIdSetIterator;
|
import org.apache.lucene.search.DocIdSetIterator;
|
||||||
|
|
|
@ -15,6 +15,7 @@ import org.apache.lucene.facet.taxonomy.InconsistentTaxonomyException;
|
||||||
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
|
import org.apache.lucene.facet.taxonomy.TaxonomyReader;
|
||||||
import org.apache.lucene.facet.taxonomy.directory.Consts.LoadFullPathOnly;
|
import org.apache.lucene.facet.taxonomy.directory.Consts.LoadFullPathOnly;
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.DocsEnum;
|
import org.apache.lucene.index.DocsEnum;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.MultiFields;
|
import org.apache.lucene.index.MultiFields;
|
||||||
|
@ -58,7 +59,7 @@ public class DirectoryTaxonomyReader implements TaxonomyReader {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(DirectoryTaxonomyReader.class.getName());
|
private static final Logger logger = Logger.getLogger(DirectoryTaxonomyReader.class.getName());
|
||||||
|
|
||||||
private IndexReader indexReader;
|
private DirectoryReader indexReader;
|
||||||
|
|
||||||
// The following lock is used to allow multiple threads to read from the
|
// The following lock is used to allow multiple threads to read from the
|
||||||
// index concurrently, while having them block during the very short
|
// index concurrently, while having them block during the very short
|
||||||
|
@ -126,7 +127,7 @@ public class DirectoryTaxonomyReader implements TaxonomyReader {
|
||||||
parentArray.refresh(indexReader);
|
parentArray.refresh(indexReader);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected IndexReader openIndexReader(Directory directory) throws CorruptIndexException, IOException {
|
protected DirectoryReader openIndexReader(Directory directory) throws CorruptIndexException, IOException {
|
||||||
return IndexReader.open(directory);
|
return IndexReader.open(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -353,7 +354,7 @@ public class DirectoryTaxonomyReader implements TaxonomyReader {
|
||||||
// safely read indexReader without holding the write lock, because
|
// safely read indexReader without holding the write lock, because
|
||||||
// no other thread can be writing at this time (this method is the
|
// no other thread can be writing at this time (this method is the
|
||||||
// only possible writer, and it is "synchronized" to avoid this case).
|
// only possible writer, and it is "synchronized" to avoid this case).
|
||||||
IndexReader r2 = IndexReader.openIfChanged(indexReader);
|
DirectoryReader r2 = DirectoryReader.openIfChanged(indexReader);
|
||||||
if (r2 == null) {
|
if (r2 == null) {
|
||||||
return false; // no changes, nothing to do
|
return false; // no changes, nothing to do
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ import org.apache.lucene.document.FieldType;
|
||||||
import org.apache.lucene.document.StringField;
|
import org.apache.lucene.document.StringField;
|
||||||
import org.apache.lucene.document.TextField;
|
import org.apache.lucene.document.TextField;
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.DocsEnum;
|
import org.apache.lucene.index.DocsEnum;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
import org.apache.lucene.index.IndexWriter;
|
||||||
|
@ -112,7 +113,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
* that some of the cached data was cleared).
|
* that some of the cached data was cleared).
|
||||||
*/
|
*/
|
||||||
private boolean cacheIsComplete;
|
private boolean cacheIsComplete;
|
||||||
private IndexReader reader;
|
private DirectoryReader reader;
|
||||||
private int cacheMisses;
|
private int cacheMisses;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -188,7 +189,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
throws CorruptIndexException, LockObtainFailedException,
|
throws CorruptIndexException, LockObtainFailedException,
|
||||||
IOException {
|
IOException {
|
||||||
|
|
||||||
if (!IndexReader.indexExists(directory) || openMode==OpenMode.CREATE) {
|
if (!DirectoryReader.indexExists(directory) || openMode==OpenMode.CREATE) {
|
||||||
taxoIndexCreateTime = Long.toString(System.nanoTime());
|
taxoIndexCreateTime = Long.toString(System.nanoTime());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +282,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
* calling {@link IndexReader#open(IndexWriter, boolean)}. Extending classes can override
|
* calling {@link IndexReader#open(IndexWriter, boolean)}. Extending classes can override
|
||||||
* this method to return their own {@link IndexReader}.
|
* this method to return their own {@link IndexReader}.
|
||||||
*/
|
*/
|
||||||
protected IndexReader openReader() throws IOException {
|
protected DirectoryReader openReader() throws IOException {
|
||||||
return IndexReader.open(indexWriter, true);
|
return IndexReader.open(indexWriter, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -618,7 +619,7 @@ public class DirectoryTaxonomyWriter implements TaxonomyWriter {
|
||||||
|
|
||||||
private synchronized void refreshReader() throws IOException {
|
private synchronized void refreshReader() throws IOException {
|
||||||
if (reader != null) {
|
if (reader != null) {
|
||||||
IndexReader r2 = IndexReader.openIfChanged(reader);
|
DirectoryReader r2 = DirectoryReader.openIfChanged(reader);
|
||||||
if (r2 != null) {
|
if (r2 != null) {
|
||||||
reader.close();
|
reader.close();
|
||||||
reader = r2;
|
reader = r2;
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.document.Field;
|
import org.apache.lucene.document.Field;
|
||||||
import org.apache.lucene.document.TextField;
|
import org.apache.lucene.document.TextField;
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
import org.apache.lucene.index.IndexWriter;
|
||||||
import org.apache.lucene.index.IndexWriterConfig;
|
import org.apache.lucene.index.IndexWriterConfig;
|
||||||
|
@ -133,7 +134,7 @@ public class FacetTestUtils {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class IndexTaxonomyReaderPair {
|
public static class IndexTaxonomyReaderPair {
|
||||||
public IndexReader indexReader;
|
public DirectoryReader indexReader;
|
||||||
public TaxonomyReader taxReader;
|
public TaxonomyReader taxReader;
|
||||||
public IndexSearcher indexSearcher;
|
public IndexSearcher indexSearcher;
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ import org.apache.lucene.analysis.MockAnalyzer;
|
||||||
import org.apache.lucene.analysis.MockTokenizer;
|
import org.apache.lucene.analysis.MockTokenizer;
|
||||||
import org.apache.lucene.document.Document;
|
import org.apache.lucene.document.Document;
|
||||||
import org.apache.lucene.index.CorruptIndexException;
|
import org.apache.lucene.index.CorruptIndexException;
|
||||||
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexWriter;
|
import org.apache.lucene.index.IndexWriter;
|
||||||
import org.apache.lucene.index.IndexWriterConfig;
|
import org.apache.lucene.index.IndexWriterConfig;
|
||||||
|
@ -299,7 +300,7 @@ public class TestTotalFacetCountsCache extends LuceneTestCase {
|
||||||
writers[0].taxWriter.close();
|
writers[0].taxWriter.close();
|
||||||
|
|
||||||
readers[0].taxReader.refresh();
|
readers[0].taxReader.refresh();
|
||||||
IndexReader r2 = IndexReader.openIfChanged(readers[0].indexReader);
|
DirectoryReader r2 = DirectoryReader.openIfChanged(readers[0].indexReader);
|
||||||
assertNotNull(r2);
|
assertNotNull(r2);
|
||||||
// Hold on to the 'original' reader so we can do some checks with it
|
// Hold on to the 'original' reader so we can do some checks with it
|
||||||
IndexReader origReader = null;
|
IndexReader origReader = null;
|
||||||
|
|
|
@ -3,6 +3,7 @@ package org.apache.lucene.facet.taxonomy.directory;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.lucene.index.DirectoryReader;
|
||||||
import org.apache.lucene.index.IndexReader;
|
import org.apache.lucene.index.IndexReader;
|
||||||
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
|
||||||
import org.apache.lucene.store.AlreadyClosedException;
|
import org.apache.lucene.store.AlreadyClosedException;
|
||||||
|
@ -54,7 +55,7 @@ public class TestDirectoryTaxonomyWriter extends LuceneTestCase {
|
||||||
// commit() wasn't called.
|
// commit() wasn't called.
|
||||||
Directory dir = newDirectory();
|
Directory dir = newDirectory();
|
||||||
DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache());
|
DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache());
|
||||||
assertFalse(IndexReader.indexExists(dir));
|
assertFalse(DirectoryReader.indexExists(dir));
|
||||||
ltw.commit(); // first commit, so that an index will be created
|
ltw.commit(); // first commit, so that an index will be created
|
||||||
ltw.addCategory(new CategoryPath("a"));
|
ltw.addCategory(new CategoryPath("a"));
|
||||||
|
|
||||||
|
@ -70,7 +71,7 @@ public class TestDirectoryTaxonomyWriter extends LuceneTestCase {
|
||||||
// Verifies that committed data is retrievable
|
// Verifies that committed data is retrievable
|
||||||
Directory dir = newDirectory();
|
Directory dir = newDirectory();
|
||||||
DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache());
|
DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache());
|
||||||
assertFalse(IndexReader.indexExists(dir));
|
assertFalse(DirectoryReader.indexExists(dir));
|
||||||
ltw.commit(); // first commit, so that an index will be created
|
ltw.commit(); // first commit, so that an index will be created
|
||||||
ltw.addCategory(new CategoryPath("a"));
|
ltw.addCategory(new CategoryPath("a"));
|
||||||
ltw.addCategory(new CategoryPath("b"));
|
ltw.addCategory(new CategoryPath("b"));
|
||||||
|
@ -78,7 +79,7 @@ public class TestDirectoryTaxonomyWriter extends LuceneTestCase {
|
||||||
userCommitData.put("testing", "1 2 3");
|
userCommitData.put("testing", "1 2 3");
|
||||||
ltw.commit(userCommitData);
|
ltw.commit(userCommitData);
|
||||||
ltw.close();
|
ltw.close();
|
||||||
IndexReader r = IndexReader.open(dir);
|
DirectoryReader r = IndexReader.open(dir);
|
||||||
assertEquals("2 categories plus root should have been committed to the underlying directory", 3, r.numDocs());
|
assertEquals("2 categories plus root should have been committed to the underlying directory", 3, r.numDocs());
|
||||||
Map <String, String> readUserCommitData = r.getCommitUserData();
|
Map <String, String> readUserCommitData = r.getCommitUserData();
|
||||||
assertTrue("wrong value extracted from commit data",
|
assertTrue("wrong value extracted from commit data",
|
||||||
|
|
Loading…
Reference in New Issue