LUCENE-3552: rename LuceneTaxonomyReader/Writer to DirectoryTaxonomyReader/Writer

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1196963 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2011-11-03 06:26:22 +00:00
parent cd9606a8b1
commit 52ab4cb9a8
44 changed files with 286 additions and 292 deletions

View File

@ -18,7 +18,7 @@ package org.apache.lucene.benchmark.byTask.tasks;
*/ */
import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.index.IndexWriterConfig.OpenMode; import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import java.io.IOException; import java.io.IOException;
@ -37,7 +37,7 @@ public class CreateTaxonomyIndexTask extends PerfTask {
@Override @Override
public int doLogic() throws IOException { public int doLogic() throws IOException {
PerfRunData runData = getRunData(); PerfRunData runData = getRunData();
runData.setTaxonomyWriter(new LuceneTaxonomyWriter(runData.getTaxonomyDir(), OpenMode.CREATE)); runData.setTaxonomyWriter(new DirectoryTaxonomyWriter(runData.getTaxonomyDir(), OpenMode.CREATE));
return 1; return 1;
} }

View File

@ -18,7 +18,8 @@ package org.apache.lucene.benchmark.byTask.tasks;
*/ */
import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import java.io.IOException; import java.io.IOException;
@ -35,7 +36,7 @@ public class OpenTaxonomyIndexTask extends PerfTask {
@Override @Override
public int doLogic() throws IOException { public int doLogic() throws IOException {
PerfRunData runData = getRunData(); PerfRunData runData = getRunData();
runData.setTaxonomyWriter(new LuceneTaxonomyWriter(runData.getTaxonomyDir())); runData.setTaxonomyWriter(new DirectoryTaxonomyWriter(runData.getTaxonomyDir()));
return 1; return 1;
} }

View File

@ -20,7 +20,7 @@ package org.apache.lucene.benchmark.byTask.tasks;
import java.io.IOException; import java.io.IOException;
import org.apache.lucene.benchmark.byTask.PerfRunData; import org.apache.lucene.benchmark.byTask.PerfRunData;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
/** /**
* Open a taxonomy index reader. * Open a taxonomy index reader.
@ -35,7 +35,7 @@ public class OpenTaxonomyReaderTask extends PerfTask {
@Override @Override
public int doLogic() throws IOException { public int doLogic() throws IOException {
PerfRunData runData = getRunData(); PerfRunData runData = getRunData();
LuceneTaxonomyReader taxoReader = new LuceneTaxonomyReader(runData.getTaxonomyDir()); DirectoryTaxonomyReader taxoReader = new DirectoryTaxonomyReader(runData.getTaxonomyDir());
runData.setTaxonomyReader(taxoReader); runData.setTaxonomyReader(taxoReader);
// We transfer reference to the run data // We transfer reference to the run data
taxoReader.decRef(); taxoReader.decRef();

View File

@ -264,7 +264,7 @@ Following is a code snippet for indexing categories. The complete example can be
found in package <code>org.apache.lucene.facet.example.simple.SimpleIndexer</code>. found in package <code>org.apache.lucene.facet.example.simple.SimpleIndexer</code>.
<pre class="prettyprint lang-java linenums"> <pre class="prettyprint lang-java linenums">
IndexWriter writer = ... IndexWriter writer = ...
TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir, OpenMode.CREATE); TaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
... ...
Document doc = new Document(); Document doc = new Document();
doc.add(new Field("title", titleText, Store.YES, Index.ANALYZED)); doc.add(new Field("title", titleText, Store.YES, Index.ANALYZED));
@ -366,7 +366,7 @@ found under <code>org.apache.lucene.facet.example.simple.Searcher</code>:
<pre class="prettyprint lang-java linenums"> <pre class="prettyprint lang-java linenums">
IndexReader indexReader = IndexReader.open(indexDir); IndexReader indexReader = IndexReader.open(indexDir);
Searcher searcher = new IndexSearcher(indexReader); Searcher searcher = new IndexSearcher(indexReader);
TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
... ...
Query q = new TermQuery(new Term(SimpleUtils.TEXT, "white")); Query q = new TermQuery(new Term(SimpleUtils.TEXT, "white"));
TopScoreDocCollector tdc = TopScoreDocCollector.create(10, true); TopScoreDocCollector tdc = TopScoreDocCollector.create(10, true);
@ -781,4 +781,4 @@ the only thing that can happen is that new categories are added. Since search th
are added in the middle of a search, there is no reason to keep around the old object, and the new one suffices. are added in the middle of a search, there is no reason to keep around the old object, and the new one suffices.
</body> </body>
</html> </html>

View File

@ -27,7 +27,7 @@ public class ExampleUtils {
public static final boolean VERBOSE = Boolean.getBoolean("tests.verbose"); public static final boolean VERBOSE = Boolean.getBoolean("tests.verbose");
/** The Lucene {@link Version} used by the example code. */ /** The Lucene {@link Version} used by the example code. */
public static final Version EXAMPLE_VER = Version.LUCENE_31; public static final Version EXAMPLE_VER = Version.LUCENE_40;
public static void log(Object msg) { public static void log(Object msg) {
if (VERBOSE) { if (VERBOSE) {

View File

@ -20,7 +20,7 @@ import org.apache.lucene.facet.search.params.FacetSearchParams;
import org.apache.lucene.facet.search.results.FacetResult; import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -55,7 +55,7 @@ public class AdaptiveSearcher {
*/ */
public static List<FacetResult> searchWithFacets (Directory indexDir, Directory taxoDir) throws Exception { public static List<FacetResult> searchWithFacets (Directory indexDir, Directory taxoDir) throws Exception {
// prepare index reader and taxonomy. // prepare index reader and taxonomy.
TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
IndexReader indexReader = IndexReader.open(indexDir); IndexReader indexReader = IndexReader.open(indexDir);
// prepare searcher to search against // prepare searcher to search against

View File

@ -16,7 +16,7 @@ import org.apache.lucene.facet.index.CategoryContainer;
import org.apache.lucene.facet.index.CategoryDocumentBuilder; import org.apache.lucene.facet.index.CategoryDocumentBuilder;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -60,7 +60,7 @@ public class AssociationIndexer {
IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig(ExampleUtils.EXAMPLE_VER, SimpleUtils.analyzer)); IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig(ExampleUtils.EXAMPLE_VER, SimpleUtils.analyzer));
// create and open a taxonomy writer // create and open a taxonomy writer
TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir, OpenMode.CREATE); TaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
// loop over sample documents // loop over sample documents
int nDocsAdded = 0; int nDocsAdded = 0;

View File

@ -11,7 +11,7 @@ import org.apache.lucene.facet.search.params.association.AssociationIntSumFacetR
import org.apache.lucene.facet.search.results.FacetResult; import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -43,7 +43,7 @@ public class AssociationSearcher {
Directory taxoDir) throws Exception { Directory taxoDir) throws Exception {
// prepare index reader // prepare index reader
IndexReader indexReader = IndexReader.open(indexDir); IndexReader indexReader = IndexReader.open(indexDir);
TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
AssociationIntSumFacetRequest facetRequest = new AssociationIntSumFacetRequest( AssociationIntSumFacetRequest facetRequest = new AssociationIntSumFacetRequest(
new CategoryPath("tags"), 10); new CategoryPath("tags"), 10);
@ -63,7 +63,7 @@ public class AssociationSearcher {
Directory taxoDir) throws Exception { Directory taxoDir) throws Exception {
// prepare index reader // prepare index reader
IndexReader indexReader = IndexReader.open(indexDir); IndexReader indexReader = IndexReader.open(indexDir);
TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
AssociationFloatSumFacetRequest facetRequest = new AssociationFloatSumFacetRequest( AssociationFloatSumFacetRequest facetRequest = new AssociationFloatSumFacetRequest(
new CategoryPath("genre"), 10); new CategoryPath("genre"), 10);

View File

@ -11,10 +11,10 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.facet.example.ExampleUtils; import org.apache.lucene.facet.example.ExampleUtils;
import org.apache.lucene.facet.index.FacetsPayloadProcessorProvider; import org.apache.lucene.facet.index.FacetsPayloadProcessorProvider;
import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams; import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter.DiskOrdinalMap; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.DiskOrdinalMap;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter.MemoryOrdinalMap; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.MemoryOrdinalMap;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter.OrdinalMap; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.OrdinalMap;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -40,19 +40,19 @@ public class TaxonomyMergeUtils {
/** /**
* Merges the given taxonomy and index directories. Note that this method * Merges the given taxonomy and index directories. Note that this method
* opens {@link LuceneTaxonomyWriter} and {@link IndexWriter} on the * opens {@link DirectoryTaxonomyWriter} and {@link IndexWriter} on the
* respective destination indexes. Therefore if you have a writer open on any * respective destination indexes. Therefore if you have a writer open on any
* of them, it should be closed, or you should use * of them, it should be closed, or you should use
* {@link #merge(Directory, Directory, IndexWriter, LuceneTaxonomyWriter)} * {@link #merge(Directory, Directory, IndexWriter, DirectoryTaxonomyWriter)}
* instead. * instead.
* *
* @see #merge(Directory, Directory, IndexWriter, LuceneTaxonomyWriter) * @see #merge(Directory, Directory, IndexWriter, DirectoryTaxonomyWriter)
*/ */
public static void merge(Directory srcIndexDir, Directory srcTaxDir, public static void merge(Directory srcIndexDir, Directory srcTaxDir,
Directory destIndexDir, Directory destTaxDir) throws IOException { Directory destIndexDir, Directory destTaxDir) throws IOException {
IndexWriter destIndexWriter = new IndexWriter(destIndexDir, IndexWriter destIndexWriter = new IndexWriter(destIndexDir,
new IndexWriterConfig(ExampleUtils.EXAMPLE_VER, null)); new IndexWriterConfig(ExampleUtils.EXAMPLE_VER, null));
LuceneTaxonomyWriter destTaxWriter = new LuceneTaxonomyWriter(destTaxDir); DirectoryTaxonomyWriter destTaxWriter = new DirectoryTaxonomyWriter(destTaxDir);
merge(srcIndexDir, srcTaxDir, new MemoryOrdinalMap(), destIndexWriter, destTaxWriter); merge(srcIndexDir, srcTaxDir, new MemoryOrdinalMap(), destIndexWriter, destTaxWriter);
destTaxWriter.close(); destTaxWriter.close();
destIndexWriter.close(); destIndexWriter.close();
@ -62,14 +62,14 @@ public class TaxonomyMergeUtils {
* Merges the given taxonomy and index directories and commits the changes to * Merges the given taxonomy and index directories and commits the changes to
* the given writers. This method uses {@link MemoryOrdinalMap} to store the * the given writers. This method uses {@link MemoryOrdinalMap} to store the
* mapped ordinals. If you cannot afford the memory, you can use * mapped ordinals. If you cannot afford the memory, you can use
* {@link #merge(Directory, Directory, LuceneTaxonomyWriter.OrdinalMap, IndexWriter, LuceneTaxonomyWriter)} * {@link #merge(Directory, Directory, DirectoryTaxonomyWriter.OrdinalMap, IndexWriter, DirectoryTaxonomyWriter)}
* by passing {@link DiskOrdinalMap}. * by passing {@link DiskOrdinalMap}.
* *
* @see #merge(Directory, Directory, LuceneTaxonomyWriter.OrdinalMap, IndexWriter, LuceneTaxonomyWriter) * @see #merge(Directory, Directory, DirectoryTaxonomyWriter.OrdinalMap, IndexWriter, DirectoryTaxonomyWriter)
*/ */
public static void merge(Directory srcIndexDir, Directory srcTaxDir, public static void merge(Directory srcIndexDir, Directory srcTaxDir,
IndexWriter destIndexWriter, IndexWriter destIndexWriter,
LuceneTaxonomyWriter destTaxWriter) throws IOException { DirectoryTaxonomyWriter destTaxWriter) throws IOException {
merge(srcIndexDir, srcTaxDir, new MemoryOrdinalMap(), destIndexWriter, destTaxWriter); merge(srcIndexDir, srcTaxDir, new MemoryOrdinalMap(), destIndexWriter, destTaxWriter);
} }
@ -79,7 +79,7 @@ public class TaxonomyMergeUtils {
*/ */
public static void merge(Directory srcIndexDir, Directory srcTaxDir, public static void merge(Directory srcIndexDir, Directory srcTaxDir,
OrdinalMap map, IndexWriter destIndexWriter, OrdinalMap map, IndexWriter destIndexWriter,
LuceneTaxonomyWriter destTaxWriter) throws IOException { DirectoryTaxonomyWriter destTaxWriter) throws IOException {
// merge the taxonomies // merge the taxonomies
destTaxWriter.addTaxonomies(new Directory[] { srcTaxDir }, new OrdinalMap[] { map }); destTaxWriter.addTaxonomies(new Directory[] { srcTaxDir }, new OrdinalMap[] { map });

View File

@ -21,7 +21,7 @@ import org.apache.lucene.facet.index.params.CategoryListParams;
import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.index.params.FacetIndexingParams;
import org.apache.lucene.facet.index.params.PerDimensionIndexingParams; import org.apache.lucene.facet.index.params.PerDimensionIndexingParams;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -140,7 +140,7 @@ public class MultiCLIndexer {
IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig( IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig(
ExampleUtils.EXAMPLE_VER, SimpleUtils.analyzer).setOpenMode(OpenMode.CREATE)); ExampleUtils.EXAMPLE_VER, SimpleUtils.analyzer).setOpenMode(OpenMode.CREATE));
// create and open a taxonomy writer // create and open a taxonomy writer
LuceneTaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir, OpenMode.CREATE); DirectoryTaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
index(iw, taxo, iParams, docTitles, docTexts, cPaths); index(iw, taxo, iParams, docTitles, docTexts, cPaths);
} }
@ -153,7 +153,7 @@ public class MultiCLIndexer {
* on error (no detailed exception handling here for sample * on error (no detailed exception handling here for sample
* simplicity * simplicity
*/ */
public static void index(IndexWriter iw, LuceneTaxonomyWriter taxo, public static void index(IndexWriter iw, DirectoryTaxonomyWriter taxo,
FacetIndexingParams iParams, String[] docTitles, FacetIndexingParams iParams, String[] docTitles,
String[] docTexts, CategoryPath[][] cPaths) throws Exception { String[] docTexts, CategoryPath[][] cPaths) throws Exception {

View File

@ -20,7 +20,7 @@ import org.apache.lucene.facet.search.params.FacetSearchParams;
import org.apache.lucene.facet.search.results.FacetResult; import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -64,7 +64,7 @@ public class MultiCLSearcher {
// prepare index reader and taxonomy. // prepare index reader and taxonomy.
IndexReader indexReader = IndexReader.open(indexDir); IndexReader indexReader = IndexReader.open(indexDir);
TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// Get results // Get results
List<FacetResult> results = searchWithFacets(indexReader, taxo, iParams); List<FacetResult> results = searchWithFacets(indexReader, taxo, iParams);

View File

@ -15,7 +15,7 @@ import org.apache.lucene.facet.example.ExampleUtils;
import org.apache.lucene.facet.index.CategoryDocumentBuilder; import org.apache.lucene.facet.index.CategoryDocumentBuilder;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -53,7 +53,7 @@ public class SimpleIndexer {
IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig(ExampleUtils.EXAMPLE_VER, SimpleUtils.analyzer)); IndexWriter iw = new IndexWriter(indexDir, new IndexWriterConfig(ExampleUtils.EXAMPLE_VER, SimpleUtils.analyzer));
// create and open a taxonomy writer // create and open a taxonomy writer
TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir, OpenMode.CREATE); TaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
// loop over sample documents // loop over sample documents
int nDocsAdded = 0; int nDocsAdded = 0;

View File

@ -10,7 +10,7 @@ import org.apache.lucene.facet.example.ExampleResult;
import org.apache.lucene.facet.example.ExampleUtils; import org.apache.lucene.facet.example.ExampleUtils;
import org.apache.lucene.facet.search.results.FacetResult; import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -56,7 +56,7 @@ public class SimpleMain {
SimpleIndexer.index(indexDir, taxoDir); SimpleIndexer.index(indexDir, taxoDir);
// open readers // open readers
TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
IndexReader indexReader = IndexReader.open(indexDir, true); IndexReader indexReader = IndexReader.open(indexDir, true);
ExampleUtils.log("search the sample documents..."); ExampleUtils.log("search the sample documents...");
@ -81,7 +81,7 @@ public class SimpleMain {
SimpleIndexer.index(indexDir, taxoDir); SimpleIndexer.index(indexDir, taxoDir);
// open readers // open readers
TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
IndexReader indexReader = IndexReader.open(indexDir, true); IndexReader indexReader = IndexReader.open(indexDir, true);
ExampleUtils.log("search the sample documents..."); ExampleUtils.log("search the sample documents...");

View File

@ -13,7 +13,7 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.facet.index.params.CategoryListParams; import org.apache.lucene.facet.index.params.CategoryListParams;
import org.apache.lucene.facet.index.params.FacetIndexingParams; import org.apache.lucene.facet.index.params.FacetIndexingParams;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter.OrdinalMap; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.OrdinalMap;
import org.apache.lucene.util.BytesRef; import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.encoding.IntDecoder; import org.apache.lucene.util.encoding.IntDecoder;
import org.apache.lucene.util.encoding.IntEncoder; import org.apache.lucene.util.encoding.IntEncoder;

View File

@ -2,9 +2,8 @@ package org.apache.lucene.facet.taxonomy;
import java.io.Closeable; import java.io.Closeable;
import java.io.IOException; import java.io.IOException;
import java.util.Map;
import org.apache.lucene.index.IndexWriter; import org.apache.lucene.util.TwoPhaseCommit;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -52,7 +51,7 @@ import org.apache.lucene.index.IndexWriter;
* *
* @lucene.experimental * @lucene.experimental
*/ */
public interface TaxonomyWriter extends Closeable { public interface TaxonomyWriter extends Closeable, TwoPhaseCommit {
/** /**
* addCategory() adds a category with a given path name to the taxonomy, * addCategory() adds a category with a given path name to the taxonomy,
@ -66,32 +65,6 @@ public interface TaxonomyWriter extends Closeable {
*/ */
public int addCategory(CategoryPath categoryPath) throws IOException; public int addCategory(CategoryPath categoryPath) throws IOException;
/**
* Calling commit() ensures that all the categories written so far are
* visible to a reader that is opened (or reopened) after that call.
* When the index is closed(), commit() is also implicitly done.
*/
public void commit() throws IOException;
/**
* Like commit(), but also store properties with the index. These properties
* are retrievable by {@link TaxonomyReader#getCommitUserData}.
* See {@link IndexWriter#commit(Map)}.
*/
public void commit(Map<String,String> commitUserData) throws IOException;
/**
* prepare most of the work needed for a two-phase commit.
* See {@link IndexWriter#prepareCommit}.
*/
public void prepareCommit() throws IOException;
/**
* Like above, and also prepares to store user data with the index.
* See {@link IndexWriter#prepareCommit(Map)}
*/
public void prepareCommit(Map<String,String> commitUserData) throws IOException;
/** /**
* getParent() returns the ordinal of the parent category of the category * getParent() returns the ordinal of the parent category of the category
* with the given ordinal. * with the given ordinal.
@ -108,8 +81,8 @@ public interface TaxonomyWriter extends Closeable {
* ordinal), an ArrayIndexOutOfBoundsException is thrown. However, it is * ordinal), an ArrayIndexOutOfBoundsException is thrown. However, it is
* expected that getParent will only be called for ordinals which are * expected that getParent will only be called for ordinals which are
* already known to be in the taxonomy. * already known to be in the taxonomy.
* <P>
* TODO (Facet): instead of a getParent(ordinal) method, consider having a * TODO (Facet): instead of a getParent(ordinal) method, consider having a
* <P>
* getCategory(categorypath, prefixlen) which is similar to addCategory * getCategory(categorypath, prefixlen) which is similar to addCategory
* except it doesn't add new categories; This method can be used to get * except it doesn't add new categories; This method can be used to get
* the ordinals of all prefixes of the given category, and it can use * the ordinals of all prefixes of the given category, and it can use

View File

@ -1,4 +1,4 @@
package org.apache.lucene.facet.taxonomy.lucene; package org.apache.lucene.facet.taxonomy.directory;
import java.io.IOException; import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.apache.lucene.facet.taxonomy.lucene; package org.apache.lucene.facet.taxonomy.directory;
import java.io.IOException; import java.io.IOException;
import java.util.Iterator; import java.util.Iterator;
@ -11,7 +11,7 @@ import java.util.logging.Logger;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.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.DocsEnum; import org.apache.lucene.index.DocsEnum;
import org.apache.lucene.index.IndexReader; import org.apache.lucene.index.IndexReader;
@ -40,24 +40,21 @@ import org.apache.lucene.util.collections.LRUHashMap;
* limitations under the License. * limitations under the License.
*/ */
/** /**
* LuceneTaxonomyReader is a {@link TaxonomyReader} which retrieves stored * A {@link TaxonomyReader} which retrieves stored taxonomy information from a
* taxonomy information from a separate Lucene index. By using a Lucene index, * {@link Directory}.
* rather than some specialized file format, we get for "free" its correctness
* (especially regarding concurrency), and the ability to save it on any
* implementation of Directory (and not just the file system).
* <P> * <P>
* Reading from the on-disk index on every method call is too slow, so this * Reading from the on-disk index on every method call is too slow, so this
* implementation employs caching: Some methods cache recent requests and * implementation employs caching: Some methods cache recent requests and their
* their results, while other methods prefetch all the data into memory * results, while other methods prefetch all the data into memory and then
* and then provide answers directly from in-memory tables. See the * provide answers directly from in-memory tables. See the documentation of
* documentation of individual methods for comments on their performance. * individual methods for comments on their performance.
* *
* @lucene.experimental * @lucene.experimental
*/ */
public class LuceneTaxonomyReader implements TaxonomyReader { public class DirectoryTaxonomyReader implements TaxonomyReader {
private static final Logger logger = Logger.getLogger(LuceneTaxonomyReader.class.getName()); private static final Logger logger = Logger.getLogger(DirectoryTaxonomyReader.class.getName());
private IndexReader indexReader; private IndexReader indexReader;
@ -111,8 +108,7 @@ public class LuceneTaxonomyReader implements TaxonomyReader {
* @throws CorruptIndexException if the Taxonomy is corrupted. * @throws CorruptIndexException if the Taxonomy is corrupted.
* @throws IOException if another error occurred. * @throws IOException if another error occurred.
*/ */
public LuceneTaxonomyReader(Directory directory) public DirectoryTaxonomyReader(Directory directory) throws IOException {
throws CorruptIndexException, IOException {
this.indexReader = openIndexReader(directory); this.indexReader = openIndexReader(directory);
// These are the default cache sizes; they can be configured after // These are the default cache sizes; they can be configured after

View File

@ -1,4 +1,4 @@
package org.apache.lucene.facet.taxonomy.lucene; package org.apache.lucene.facet.taxonomy.directory;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
@ -64,29 +64,24 @@ import org.apache.lucene.facet.taxonomy.writercache.lru.LruTaxonomyWriterCache;
*/ */
/** /**
* {@link TaxonomyWriter} which uses a Lucene index to store the taxonomy * {@link TaxonomyWriter} which uses a {@link Directory} to store the taxonomy
* information on disk, and keeps an additional in-memory cache of some or all * information on disk, and keeps an additional in-memory cache of some or all
* categories. * categories.
* <P> * <p>
* By using a Lucene index to store the information on disk, rather than some * In addition to the permanently-stored information in the {@link Directory},
* specialized file format, we get for "free" Lucene's correctness (especially * efficiency dictates that we also keep an in-memory cache of <B>recently
* regarding multi-process concurrency), and the ability to write to any * seen</B> or <B>all</B> categories, so that we do not need to go back to disk
* implementation of Directory (and not just the file system). * for every category addition to see which ordinal this category already has,
* <P> * if any. A {@link TaxonomyWriterCache} object determines the specific caching
* In addition to the permanently-stored Lucene index, efficiency dictates that * algorithm used.
* we also keep an in-memory cache of <B>recently seen</B> or <B>all</B>
* categories, so that we do not need to go back to disk for every category
* addition to see which ordinal this category already has, if any. A
* {@link TaxonomyWriterCache} object determines the specific caching algorithm
* used.
* <p> * <p>
* This class offers some hooks for extending classes to control the * This class offers some hooks for extending classes to control the
* {@link IndexWriter} instance that is used. See {@link #openLuceneIndex} and * {@link IndexWriter} instance that is used. See {@link #openIndexWriter} and
* {@link #closeLuceneIndex()} . * {@link #closeIndexWriter()} .
* *
* @lucene.experimental * @lucene.experimental
*/ */
public class LuceneTaxonomyWriter implements TaxonomyWriter { public class DirectoryTaxonomyWriter implements TaxonomyWriter {
protected IndexWriter indexWriter; protected IndexWriter indexWriter;
private int nextID; private int nextID;
@ -171,12 +166,12 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
* @throws IOException * @throws IOException
* if another error occurred. * if another error occurred.
*/ */
public LuceneTaxonomyWriter(Directory directory, OpenMode openMode, public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode,
TaxonomyWriterCache cache) TaxonomyWriterCache cache)
throws CorruptIndexException, LockObtainFailedException, throws CorruptIndexException, LockObtainFailedException,
IOException { IOException {
openLuceneIndex(directory, openMode); openIndexWriter(directory, openMode);
reader = null; reader = null;
FieldType ft = new FieldType(TextField.TYPE_UNSTORED); FieldType ft = new FieldType(TextField.TYPE_UNSTORED);
@ -218,18 +213,20 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
* etc.<br> * etc.<br>
* <b>NOTE:</b> the instance this method returns will be closed upon calling * <b>NOTE:</b> the instance this method returns will be closed upon calling
* to {@link #close()}. If you wish to do something different, you should * to {@link #close()}. If you wish to do something different, you should
* override {@link #closeLuceneIndex()}. * override {@link #closeIndexWriter()}.
* *
* @param directory the {@link Directory} on top of wich an * @param directory
* {@link IndexWriter} should be opened. * the {@link Directory} on top of which an {@link IndexWriter}
* @param openMode see {@link OpenMode} * should be opened.
* @param openMode
* see {@link OpenMode}
*/ */
protected void openLuceneIndex (Directory directory, OpenMode openMode) protected void openIndexWriter(Directory directory, OpenMode openMode)
throws CorruptIndexException, LockObtainFailedException, IOException { throws IOException {
// Make sure we use a MergePolicy which merges segments in-order and thus // Make sure we use a MergePolicy which merges segments in-order and thus
// keeps the doc IDs ordered as well (this is crucial for the taxonomy // keeps the doc IDs ordered as well (this is crucial for the taxonomy
// index). // index).
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_30, IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40,
new KeywordAnalyzer()).setOpenMode(openMode).setMergePolicy( new KeywordAnalyzer()).setOpenMode(openMode).setMergePolicy(
new LogByteSizeMergePolicy()); new LogByteSizeMergePolicy());
indexWriter = new IndexWriter(directory, config); indexWriter = new IndexWriter(directory, config);
@ -250,7 +247,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
* Creates a new instance with a default cached as defined by * Creates a new instance with a default cached as defined by
* {@link #defaultTaxonomyWriterCache()}. * {@link #defaultTaxonomyWriterCache()}.
*/ */
public LuceneTaxonomyWriter(Directory directory, OpenMode openMode) public DirectoryTaxonomyWriter(Directory directory, OpenMode openMode)
throws CorruptIndexException, LockObtainFailedException, IOException { throws CorruptIndexException, LockObtainFailedException, IOException {
this(directory, openMode, defaultTaxonomyWriterCache()); this(directory, openMode, defaultTaxonomyWriterCache());
} }
@ -269,7 +266,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
// convenience constructors: // convenience constructors:
public LuceneTaxonomyWriter(Directory d) public DirectoryTaxonomyWriter(Directory d)
throws CorruptIndexException, LockObtainFailedException, throws CorruptIndexException, LockObtainFailedException,
IOException { IOException {
this(d, OpenMode.CREATE_OR_APPEND); this(d, OpenMode.CREATE_OR_APPEND);
@ -280,8 +277,9 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
* which commits whatever changes made to it to the underlying * which commits whatever changes made to it to the underlying
* {@link Directory}. * {@link Directory}.
*/ */
@Override
public synchronized void close() throws CorruptIndexException, IOException { public synchronized void close() throws CorruptIndexException, IOException {
closeLuceneIndex(); closeIndexWriter();
closeResources(); closeResources();
} }
@ -316,9 +314,9 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
/** /**
* A hook for extending classes to control closing the {@link IndexWriter} * A hook for extending classes to control closing the {@link IndexWriter}
* returned by {@link #openLuceneIndex}. * returned by {@link #openIndexWriter}.
*/ */
protected void closeLuceneIndex() throws CorruptIndexException, IOException { protected void closeIndexWriter() throws CorruptIndexException, IOException {
if (indexWriter != null) { if (indexWriter != null) {
indexWriter.close(); indexWriter.close();
indexWriter = null; indexWriter = null;
@ -413,6 +411,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
// potentially even trigger a lengthy merge) locks out other addCategory() // potentially even trigger a lengthy merge) locks out other addCategory()
// calls - even those which could immediately return a cached value. // calls - even those which could immediately return a cached value.
// We definitely need to fix this situation! // We definitely need to fix this situation!
@Override
public synchronized int addCategory(CategoryPath categoryPath) public synchronized int addCategory(CategoryPath categoryPath)
throws IOException { throws IOException {
// If the category is already in the cache and/or the taxonomy, we // If the category is already in the cache and/or the taxonomy, we
@ -578,6 +577,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
* When the index is closed(), commit() is also implicitly done. * When the index is closed(), commit() is also implicitly done.
* See {@link TaxonomyWriter#commit()} * See {@link TaxonomyWriter#commit()}
*/ */
@Override
public synchronized void commit() throws CorruptIndexException, IOException { public synchronized void commit() throws CorruptIndexException, IOException {
indexWriter.commit(); indexWriter.commit();
refreshReader(); refreshReader();
@ -585,9 +585,10 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
/** /**
* Like commit(), but also store properties with the index. These properties * Like commit(), but also store properties with the index. These properties
* are retrievable by {@link LuceneTaxonomyReader#getCommitUserData}. * are retrievable by {@link DirectoryTaxonomyReader#getCommitUserData}.
* See {@link TaxonomyWriter#commit(Map)}. * See {@link TaxonomyWriter#commit(Map)}.
*/ */
@Override
public synchronized void commit(Map<String,String> commitUserData) throws CorruptIndexException, IOException { public synchronized void commit(Map<String,String> commitUserData) throws CorruptIndexException, IOException {
indexWriter.commit(commitUserData); indexWriter.commit(commitUserData);
refreshReader(); refreshReader();
@ -597,6 +598,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
* prepare most of the work needed for a two-phase commit. * prepare most of the work needed for a two-phase commit.
* See {@link IndexWriter#prepareCommit}. * See {@link IndexWriter#prepareCommit}.
*/ */
@Override
public synchronized void prepareCommit() throws CorruptIndexException, IOException { public synchronized void prepareCommit() throws CorruptIndexException, IOException {
indexWriter.prepareCommit(); indexWriter.prepareCommit();
} }
@ -605,6 +607,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
* Like above, and also prepares to store user data with the index. * Like above, and also prepares to store user data with the index.
* See {@link IndexWriter#prepareCommit(Map)} * See {@link IndexWriter#prepareCommit(Map)}
*/ */
@Override
public synchronized void prepareCommit(Map<String,String> commitUserData) throws CorruptIndexException, IOException { public synchronized void prepareCommit(Map<String,String> commitUserData) throws CorruptIndexException, IOException {
indexWriter.prepareCommit(commitUserData); indexWriter.prepareCommit(commitUserData);
} }
@ -620,6 +623,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
* a category is added to the taxonomy, its ancestors are also added * a category is added to the taxonomy, its ancestors are also added
* automatically (including the root, which always get ordinal 0). * automatically (including the root, which always get ordinal 0).
*/ */
@Override
synchronized public int getSize() { synchronized public int getSize() {
return indexWriter.maxDoc(); return indexWriter.maxDoc();
} }
@ -720,6 +724,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
} }
return parentArray; return parentArray;
} }
@Override
public int getParent(int ordinal) throws IOException { public int getParent(int ordinal) throws IOException {
// Note: the following if() just enforces that a user can never ask // Note: the following if() just enforces that a user can never ask
// for the parent of a nonexistant category - even if the parent array // for the parent of a nonexistant category - even if the parent array
@ -930,13 +935,17 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
*/ */
public static final class MemoryOrdinalMap implements OrdinalMap { public static final class MemoryOrdinalMap implements OrdinalMap {
int[] map; int[] map;
@Override
public void setSize(int taxonomySize) { public void setSize(int taxonomySize) {
map = new int[taxonomySize]; map = new int[taxonomySize];
} }
@Override
public void addMapping(int origOrdinal, int newOrdinal) { public void addMapping(int origOrdinal, int newOrdinal) {
map[origOrdinal] = newOrdinal; map[origOrdinal] = newOrdinal;
} }
@Override
public void addDone() { /* nothing to do */ } public void addDone() { /* nothing to do */ }
@Override
public int[] getMap() { public int[] getMap() {
return map; return map;
} }
@ -955,15 +964,18 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
new FileOutputStream(tmpfile))); new FileOutputStream(tmpfile)));
} }
@Override
public void addMapping(int origOrdinal, int newOrdinal) throws IOException { public void addMapping(int origOrdinal, int newOrdinal) throws IOException {
out.writeInt(origOrdinal); out.writeInt(origOrdinal);
out.writeInt(newOrdinal); out.writeInt(newOrdinal);
} }
@Override
public void setSize(int taxonomySize) throws IOException { public void setSize(int taxonomySize) throws IOException {
out.writeInt(taxonomySize); out.writeInt(taxonomySize);
} }
@Override
public void addDone() throws IOException { public void addDone() throws IOException {
if (out!=null) { if (out!=null) {
out.close(); out.close();
@ -973,6 +985,7 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
int[] map = null; int[] map = null;
@Override
public int[] getMap() throws IOException { public int[] getMap() throws IOException {
if (map!=null) { if (map!=null) {
return map; return map;
@ -1005,4 +1018,10 @@ public class LuceneTaxonomyWriter implements TaxonomyWriter {
return null; return null;
} }
@Override
public void rollback() throws IOException {
indexWriter.rollback();
refreshReader();
}
} }

View File

@ -1,4 +1,4 @@
package org.apache.lucene.facet.taxonomy.lucene; package org.apache.lucene.facet.taxonomy.directory;
import java.io.IOException; import java.io.IOException;

View File

@ -1,7 +1,7 @@
package org.apache.lucene.facet.taxonomy.writercache; package org.apache.lucene.facet.taxonomy.writercache;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -23,7 +23,7 @@ import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter;
/** /**
* TaxonomyWriterCache is a relatively simple interface for a cache of * TaxonomyWriterCache is a relatively simple interface for a cache of
* category->ordinal mappings, used in TaxonomyWriter implementations * category->ordinal mappings, used in TaxonomyWriter implementations
* (such as {@link LuceneTaxonomyWriter}). * (such as {@link DirectoryTaxonomyWriter}).
* <P> * <P>
* It basically has put() methods for adding a mapping, and get() for looking * It basically has put() methods for adding a mapping, and get() for looking
* a mapping up the cache. The cache does <B>not</B> guarantee to hold * a mapping up the cache. The cache does <B>not</B> guarantee to hold

View File

@ -119,7 +119,7 @@ class NameIntCacheLRU {
* If cache is full remove least recently used entries from cache. * If cache is full remove least recently used entries from cache.
* Return true if anything was removed, false otherwise. * Return true if anything was removed, false otherwise.
* *
* See comment in {@link LuceneTaxonomyWriter#addToCache(String, Integer)} * See comment in {@link DirectoryTaxonomyWriter#addToCache(String, Integer)}
* for an explanation why we clean 2/3rds of the cache, and not just one * for an explanation why we clean 2/3rds of the cache, and not just one
* entry. * entry.
*/ */

View File

@ -43,8 +43,8 @@ import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -137,7 +137,7 @@ public abstract class FacetTestBase extends LuceneTestCase {
} }
RandomIndexWriter iw = new RandomIndexWriter(random, indexDir, getIndexWriterConfig(getAnalyzer())); RandomIndexWriter iw = new RandomIndexWriter(random, indexDir, getIndexWriterConfig(getAnalyzer()));
TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir, OpenMode.CREATE); TaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
populateIndex(iw, taxo, getFacetIndexingParams(partitionSize)); populateIndex(iw, taxo, getFacetIndexingParams(partitionSize));
@ -148,7 +148,7 @@ public abstract class FacetTestBase extends LuceneTestCase {
iw.close(); iw.close();
// prepare for searching // prepare for searching
taxoReader = new LuceneTaxonomyReader(taxoDir); taxoReader = new DirectoryTaxonomyReader(taxoDir);
indexReader = IndexReader.open(indexDir); indexReader = IndexReader.open(indexDir);
searcher = newSearcher(indexReader); searcher = newSearcher(indexReader);
} }

View File

@ -31,8 +31,8 @@ import org.apache.lucene.facet.search.params.FacetSearchParams;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -69,7 +69,7 @@ public class FacetTestUtils {
IndexTaxonomyReaderPair pair = new IndexTaxonomyReaderPair(); IndexTaxonomyReaderPair pair = new IndexTaxonomyReaderPair();
pair.indexReader = IndexReader.open(dirs[i][0]); pair.indexReader = IndexReader.open(dirs[i][0]);
pair.indexSearcher = new IndexSearcher(pair.indexReader); pair.indexSearcher = new IndexSearcher(pair.indexReader);
pair.taxReader = new LuceneTaxonomyReader(dirs[i][1]); pair.taxReader = new DirectoryTaxonomyReader(dirs[i][1]);
pairs[i] = pair; pairs[i] = pair;
} }
return pairs; return pairs;
@ -83,7 +83,7 @@ public class FacetTestUtils {
pair.indexWriter = new IndexWriter(dirs[i][0], new IndexWriterConfig( pair.indexWriter = new IndexWriter(dirs[i][0], new IndexWriterConfig(
LuceneTestCase.TEST_VERSION_CURRENT, new StandardAnalyzer( LuceneTestCase.TEST_VERSION_CURRENT, new StandardAnalyzer(
LuceneTestCase.TEST_VERSION_CURRENT))); LuceneTestCase.TEST_VERSION_CURRENT)));
pair.taxWriter = new LuceneTaxonomyWriter(dirs[i][1]); pair.taxWriter = new DirectoryTaxonomyWriter(dirs[i][1]);
pair.indexWriter.commit(); pair.indexWriter.commit();
pair.taxWriter.commit(); pair.taxWriter.commit();
pairs[i] = pair; pairs[i] = pair;

View File

@ -21,7 +21,7 @@ import org.apache.lucene.facet.enhancements.params.EnhancementsIndexingParams;
import org.apache.lucene.facet.search.DrillDown; import org.apache.lucene.facet.search.DrillDown;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -58,7 +58,7 @@ public class TwoEnhancementsTest extends LuceneTestCase {
RandomIndexWriter indexWriter = new RandomIndexWriter(random, indexDir, newIndexWriterConfig( RandomIndexWriter indexWriter = new RandomIndexWriter(random, indexDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)));
TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir); TaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir);
// a category document builder will add the categories to a document // a category document builder will add the categories to a document
// once build() is called // once build() is called
@ -103,7 +103,7 @@ public class TwoEnhancementsTest extends LuceneTestCase {
RandomIndexWriter indexWriter = new RandomIndexWriter(random, indexDir, newIndexWriterConfig( RandomIndexWriter indexWriter = new RandomIndexWriter(random, indexDir, newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)));
TaxonomyWriter taxo = new LuceneTaxonomyWriter(taxoDir); TaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir);
// a category document builder will add the categories to a document // a category document builder will add the categories to a document
// once build() is called // once build() is called

View File

@ -16,8 +16,8 @@ import org.apache.lucene.facet.index.CategoryContainer;
import org.apache.lucene.facet.index.attributes.CategoryAttributeImpl; import org.apache.lucene.facet.index.attributes.CategoryAttributeImpl;
import org.apache.lucene.facet.index.attributes.CategoryProperty; import org.apache.lucene.facet.index.attributes.CategoryProperty;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -59,7 +59,7 @@ public class CustomAssociationPropertyTest extends LuceneTestCase {
RandomIndexWriter w = new RandomIndexWriter(random, iDir, RandomIndexWriter w = new RandomIndexWriter(random, iDir,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false)));
LuceneTaxonomyWriter taxoW = new LuceneTaxonomyWriter(tDir); DirectoryTaxonomyWriter taxoW = new DirectoryTaxonomyWriter(tDir);
CategoryContainer cc = new CategoryContainer(); CategoryContainer cc = new CategoryContainer();
EnhancementsDocumentBuilder builder = new EnhancementsDocumentBuilder(taxoW, iParams); EnhancementsDocumentBuilder builder = new EnhancementsDocumentBuilder(taxoW, iParams);
@ -75,7 +75,7 @@ public class CustomAssociationPropertyTest extends LuceneTestCase {
IndexReader reader = w.getReader(); IndexReader reader = w.getReader();
w.close(); w.close();
LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(tDir); DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(tDir);
String field = iParams.getCategoryListParams(new CategoryPath("0")).getTerm().field(); String field = iParams.getCategoryListParams(new CategoryPath("0")).getTerm().field();
AssociationsPayloadIterator api = new AssociationsPayloadIterator(reader, field); AssociationsPayloadIterator api = new AssociationsPayloadIterator(reader, field);

View File

@ -23,8 +23,8 @@ import org.apache.lucene.facet.search.params.FacetSearchParams;
import org.apache.lucene.facet.search.results.FacetResult; import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.search.results.FacetResultNode; import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -68,7 +68,7 @@ public class FacetsPayloadProcessorProviderTest extends LuceneTestCase {
private void verifyResults(Directory dir, Directory taxDir) throws IOException { private void verifyResults(Directory dir, Directory taxDir) throws IOException {
IndexReader reader1 = IndexReader.open(dir); IndexReader reader1 = IndexReader.open(dir);
LuceneTaxonomyReader taxReader = new LuceneTaxonomyReader(taxDir); DirectoryTaxonomyReader taxReader = new DirectoryTaxonomyReader(taxDir);
IndexSearcher searcher = newSearcher(reader1); IndexSearcher searcher = newSearcher(reader1);
FacetSearchParams fsp = new FacetSearchParams(); FacetSearchParams fsp = new FacetSearchParams();
fsp.addFacetRequest(new CountFacetRequest(new CategoryPath("tag"), NUM_DOCS)); fsp.addFacetRequest(new CountFacetRequest(new CategoryPath("tag"), NUM_DOCS));
@ -94,7 +94,7 @@ public class FacetsPayloadProcessorProviderTest extends LuceneTestCase {
new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)); new MockAnalyzer(random, MockTokenizer.WHITESPACE, false));
RandomIndexWriter writer = new RandomIndexWriter(random, dir, config); RandomIndexWriter writer = new RandomIndexWriter(random, dir, config);
LuceneTaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter(taxDir); DirectoryTaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(taxDir);
for (int i = 1; i <= NUM_DOCS; i++) { for (int i = 1; i <= NUM_DOCS; i++) {
Document doc = new Document(); Document doc = new Document();
List<CategoryPath> categoryPaths = new ArrayList<CategoryPath>(i + 1); List<CategoryPath> categoryPaths = new ArrayList<CategoryPath>(i + 1);

View File

@ -10,7 +10,7 @@ import org.apache.lucene.facet.index.categorypolicy.OrdinalPolicy;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -48,7 +48,7 @@ public class OrdinalPolicyTest extends LuceneTestCase {
public void testNonTopLevelOrdinalPolicy() throws Exception { public void testNonTopLevelOrdinalPolicy() throws Exception {
Directory dir = newDirectory(); Directory dir = newDirectory();
TaxonomyWriter taxonomy = null; TaxonomyWriter taxonomy = null;
taxonomy = new LuceneTaxonomyWriter(dir); taxonomy = new DirectoryTaxonomyWriter(dir);
int[] topLevelOrdinals = new int[10]; int[] topLevelOrdinals = new int[10];
String[] topLevelStrings = new String[10]; String[] topLevelStrings = new String[10];

View File

@ -9,7 +9,7 @@ import org.apache.lucene.facet.index.categorypolicy.NonTopLevelPathPolicy;
import org.apache.lucene.facet.index.categorypolicy.PathPolicy; import org.apache.lucene.facet.index.categorypolicy.PathPolicy;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -54,7 +54,7 @@ public class PathPolicyTest extends LuceneTestCase {
public void testNonTopLevelPathPolicy() throws Exception { public void testNonTopLevelPathPolicy() throws Exception {
Directory dir = newDirectory(); Directory dir = newDirectory();
TaxonomyWriter taxonomy = null; TaxonomyWriter taxonomy = null;
taxonomy = new LuceneTaxonomyWriter(dir); taxonomy = new DirectoryTaxonomyWriter(dir);
CategoryPath[] topLevelPaths = new CategoryPath[10]; CategoryPath[] topLevelPaths = new CategoryPath[10];
String[] topLevelStrings = new String[10]; String[] topLevelStrings = new String[10];

View File

@ -19,7 +19,7 @@ import org.apache.lucene.facet.index.streaming.CategoryAttributesStream;
import org.apache.lucene.facet.index.streaming.CategoryListTokenizer; import org.apache.lucene.facet.index.streaming.CategoryListTokenizer;
import org.apache.lucene.facet.index.streaming.CategoryParentsStream; import org.apache.lucene.facet.index.streaming.CategoryParentsStream;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -50,7 +50,7 @@ public class CategoryParentsStreamTest extends CategoryContainerTestBase {
@Test @Test
public void testStreamDefaultParams() throws IOException { public void testStreamDefaultParams() throws IOException {
Directory directory = newDirectory(); Directory directory = newDirectory();
TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(
directory); directory);
CategoryParentsStream stream = new CategoryParentsStream( CategoryParentsStream stream = new CategoryParentsStream(
new CategoryAttributesStream(categoryContainer), new CategoryAttributesStream(categoryContainer),
@ -77,7 +77,7 @@ public class CategoryParentsStreamTest extends CategoryContainerTestBase {
@Test @Test
public void testStreamNonTopLevelParams() throws IOException { public void testStreamNonTopLevelParams() throws IOException {
Directory directory = newDirectory(); Directory directory = newDirectory();
final TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( final TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(
directory); directory);
FacetIndexingParams indexingParams = new DefaultFacetIndexingParams() { FacetIndexingParams indexingParams = new DefaultFacetIndexingParams() {
@Override @Override
@ -118,7 +118,7 @@ public class CategoryParentsStreamTest extends CategoryContainerTestBase {
@Test @Test
public void testNoRetainableAttributes() throws IOException, FacetException { public void testNoRetainableAttributes() throws IOException, FacetException {
Directory directory = newDirectory(); Directory directory = newDirectory();
TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter(directory); TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(directory);
new CategoryParentsStream(new CategoryAttributesStream(categoryContainer), new CategoryParentsStream(new CategoryAttributesStream(categoryContainer),
taxonomyWriter, new DefaultFacetIndexingParams()); taxonomyWriter, new DefaultFacetIndexingParams());
@ -152,7 +152,7 @@ public class CategoryParentsStreamTest extends CategoryContainerTestBase {
@Test @Test
public void testRetainableAttributes() throws IOException, FacetException { public void testRetainableAttributes() throws IOException, FacetException {
Directory directory = newDirectory(); Directory directory = newDirectory();
TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(
directory); directory);
FacetIndexingParams indexingParams = new DefaultFacetIndexingParams(); FacetIndexingParams indexingParams = new DefaultFacetIndexingParams();

View File

@ -17,7 +17,7 @@ import org.apache.lucene.facet.index.streaming.CategoryAttributesStream;
import org.apache.lucene.facet.index.streaming.CategoryTokenizer; import org.apache.lucene.facet.index.streaming.CategoryTokenizer;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -47,7 +47,7 @@ public class CategoryTokenizerTest extends CategoryContainerTestBase {
@Test @Test
public void testTokensDefaultParams() throws IOException { public void testTokensDefaultParams() throws IOException {
Directory directory = newDirectory(); Directory directory = newDirectory();
TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(
directory); directory);
DefaultFacetIndexingParams indexingParams = new DefaultFacetIndexingParams(); DefaultFacetIndexingParams indexingParams = new DefaultFacetIndexingParams();
CategoryTokenizer tokenizer = new CategoryTokenizer( CategoryTokenizer tokenizer = new CategoryTokenizer(
@ -86,7 +86,7 @@ public class CategoryTokenizerTest extends CategoryContainerTestBase {
@Test @Test
public void testLongCategoryPath() throws IOException { public void testLongCategoryPath() throws IOException {
Directory directory = newDirectory(); Directory directory = newDirectory();
TaxonomyWriter taxonomyWriter = new LuceneTaxonomyWriter( TaxonomyWriter taxonomyWriter = new DirectoryTaxonomyWriter(
directory); directory);
List<CategoryPath> longCategory = new ArrayList<CategoryPath>(); List<CategoryPath> longCategory = new ArrayList<CategoryPath>();

View File

@ -28,8 +28,8 @@ import org.apache.lucene.facet.index.params.PerDimensionIndexingParams;
import org.apache.lucene.facet.search.params.FacetSearchParams; import org.apache.lucene.facet.search.params.FacetSearchParams;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -53,7 +53,7 @@ public class DrillDownTest extends LuceneTestCase {
private FacetSearchParams defaultParams = new FacetSearchParams(); private FacetSearchParams defaultParams = new FacetSearchParams();
private FacetSearchParams nonDefaultParams; private FacetSearchParams nonDefaultParams;
private static IndexReader reader; private static IndexReader reader;
private static LuceneTaxonomyReader taxo; private static DirectoryTaxonomyReader taxo;
private static Directory dir; private static Directory dir;
private static Directory taxoDir; private static Directory taxoDir;
@ -74,7 +74,7 @@ public class DrillDownTest extends LuceneTestCase {
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false)));
taxoDir = newDirectory(); taxoDir = newDirectory();
TaxonomyWriter taxoWriter = new LuceneTaxonomyWriter(taxoDir); TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
for (int i = 0; i < 100; i++) { for (int i = 0; i < 100; i++) {
ArrayList<CategoryPath> paths = new ArrayList<CategoryPath>(); ArrayList<CategoryPath> paths = new ArrayList<CategoryPath>();
@ -100,7 +100,7 @@ public class DrillDownTest extends LuceneTestCase {
reader = writer.getReader(); reader = writer.getReader();
writer.close(); writer.close();
taxo = new LuceneTaxonomyReader(taxoDir); taxo = new DirectoryTaxonomyReader(taxoDir);
} }
@Test @Test
@ -149,6 +149,8 @@ public class DrillDownTest extends LuceneTestCase {
Query q4 = DrillDown.query(defaultParams, fooQuery, new CategoryPath("b")); Query q4 = DrillDown.query(defaultParams, fooQuery, new CategoryPath("b"));
docs = searcher.search(q4, 100); docs = searcher.search(q4, 100);
assertEquals(10, docs.totalHits); assertEquals(10, docs.totalHits);
searcher.close();
} }
@Test @Test
@ -170,6 +172,8 @@ public class DrillDownTest extends LuceneTestCase {
Query q4 = DrillDown.query(fooQuery, new CategoryPath("b")); Query q4 = DrillDown.query(fooQuery, new CategoryPath("b"));
docs = searcher.search(q4, 100); docs = searcher.search(q4, 100);
assertEquals(10, docs.totalHits); assertEquals(10, docs.totalHits);
searcher.close();
} }
@AfterClass @AfterClass

View File

@ -38,8 +38,8 @@ import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -67,7 +67,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer // create and open a taxonomy writer
TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], OpenMode.CREATE); TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
/** /**
* Configure with no custom counting lists * Configure with no custom counting lists
@ -80,7 +80,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
tw.commit(); tw.commit();
// prepare index reader and taxonomy. // prepare index reader and taxonomy.
TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); TaxonomyReader tr = new DirectoryTaxonomyReader(dirs[0][1]);
// prepare searcher to search against // prepare searcher to search against
IndexSearcher searcher = newSearcher(ir); IndexSearcher searcher = newSearcher(ir);
@ -109,7 +109,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer // create and open a taxonomy writer
TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
OpenMode.CREATE); OpenMode.CREATE);
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
@ -121,7 +121,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
tw.commit(); tw.commit();
// prepare index reader and taxonomy. // prepare index reader and taxonomy.
TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); TaxonomyReader tr = new DirectoryTaxonomyReader(dirs[0][1]);
// prepare searcher to search against // prepare searcher to search against
IndexSearcher searcher = newSearcher(ir); IndexSearcher searcher = newSearcher(ir);
@ -150,7 +150,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer // create and open a taxonomy writer
TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
OpenMode.CREATE); OpenMode.CREATE);
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
@ -164,7 +164,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
tw.commit(); tw.commit();
// prepare index reader and taxonomy. // prepare index reader and taxonomy.
TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); TaxonomyReader tr = new DirectoryTaxonomyReader(dirs[0][1]);
// prepare searcher to search against // prepare searcher to search against
IndexSearcher searcher = newSearcher(ir); IndexSearcher searcher = newSearcher(ir);
@ -199,7 +199,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer // create and open a taxonomy writer
TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], OpenMode.CREATE); TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1], OpenMode.CREATE);
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
iParams.addCategoryListParams(new CategoryPath("Band"), iParams.addCategoryListParams(new CategoryPath("Band"),
@ -212,7 +212,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
tw.commit(); tw.commit();
// prepare index reader and taxonomy. // prepare index reader and taxonomy.
TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); TaxonomyReader tr = new DirectoryTaxonomyReader(dirs[0][1]);
// prepare searcher to search against // prepare searcher to search against
IndexSearcher searcher = newSearcher(ir); IndexSearcher searcher = newSearcher(ir);
@ -240,7 +240,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig( RandomIndexWriter iw = new RandomIndexWriter(random, dirs[0][0], newIndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)));
// create and open a taxonomy writer // create and open a taxonomy writer
TaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0][1], TaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0][1],
OpenMode.CREATE); OpenMode.CREATE);
PerDimensionIndexingParams iParams = new PerDimensionIndexingParams(); PerDimensionIndexingParams iParams = new PerDimensionIndexingParams();
@ -257,7 +257,7 @@ public class TestMultipleCategoryLists extends LuceneTestCase {
tw.commit(); tw.commit();
// prepare index reader and taxonomy. // prepare index reader and taxonomy.
TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0][1]); TaxonomyReader tr = new DirectoryTaxonomyReader(dirs[0][1]);
// prepare searcher to search against // prepare searcher to search against
IndexSearcher searcher = newSearcher(ir); IndexSearcher searcher = newSearcher(ir);

View File

@ -29,8 +29,8 @@ import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.search.results.FacetResultNode; import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.facet.util.PartitionsUtils; import org.apache.lucene.facet.util.PartitionsUtils;
/** /**
@ -80,7 +80,7 @@ public class TestTopKInEachNodeResultHandler extends LuceneTestCase {
RandomIndexWriter iw = new RandomIndexWriter(random, iDir, RandomIndexWriter iw = new RandomIndexWriter(random, iDir,
newIndexWriterConfig(TEST_VERSION_CURRENT, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE)); new MockAnalyzer(random)).setOpenMode(OpenMode.CREATE));
TaxonomyWriter tw = new LuceneTaxonomyWriter(tDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(tDir);
prvt_add(iParams, iw, tw, "a", "b"); prvt_add(iParams, iw, tw, "a", "b");
prvt_add(iParams, iw, tw, "a", "b", "1"); prvt_add(iParams, iw, tw, "a", "b", "1");
prvt_add(iParams, iw, tw, "a", "b", "1"); prvt_add(iParams, iw, tw, "a", "b", "1");
@ -104,7 +104,7 @@ public class TestTopKInEachNodeResultHandler extends LuceneTestCase {
tw.close(); tw.close();
IndexSearcher is = newSearcher(ir); IndexSearcher is = newSearcher(ir);
LuceneTaxonomyReader tr = new LuceneTaxonomyReader(tDir); DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(tDir);
// Get all of the documents and run the query, then do different // Get all of the documents and run the query, then do different
// facet counts and compare to control // facet counts and compare to control

View File

@ -34,8 +34,8 @@ import org.apache.lucene.facet.search.results.FacetResultNode;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.IOUtils;
import org.apache.lucene.util.SlowRAMDirectory; import org.apache.lucene.util.SlowRAMDirectory;
import org.apache.lucene.util._TestUtil; import org.apache.lucene.util._TestUtil;
@ -67,12 +67,12 @@ public class TestTotalFacetCountsCache extends LuceneTestCase {
*/ */
private static class TFCThread extends Thread { private static class TFCThread extends Thread {
private final IndexReader r; private final IndexReader r;
private final LuceneTaxonomyReader tr; private final DirectoryTaxonomyReader tr;
private final FacetIndexingParams iParams; private final FacetIndexingParams iParams;
TotalFacetCounts tfc; TotalFacetCounts tfc;
public TFCThread(IndexReader r, LuceneTaxonomyReader tr, FacetIndexingParams iParams) { public TFCThread(IndexReader r, DirectoryTaxonomyReader tr, FacetIndexingParams iParams) {
this.r = r; this.r = r;
this.tr = tr; this.tr = tr;
this.iParams = iParams; this.iParams = iParams;
@ -156,7 +156,7 @@ public class TestTotalFacetCountsCache extends LuceneTestCase {
// Open the slow readers // Open the slow readers
IndexReader slowIndexReader = IndexReader.open(indexDir); IndexReader slowIndexReader = IndexReader.open(indexDir);
TaxonomyReader slowTaxoReader = new LuceneTaxonomyReader(taxoDir); TaxonomyReader slowTaxoReader = new DirectoryTaxonomyReader(taxoDir);
// Class to perform search and return results as threads // Class to perform search and return results as threads
class Multi extends Thread { class Multi extends Thread {
@ -421,7 +421,7 @@ public class TestTotalFacetCountsCache extends LuceneTestCase {
// Write index using 'normal' directories // Write index using 'normal' directories
IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig( IndexWriter w = new IndexWriter(indexDir, new IndexWriterConfig(
TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false))); TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.WHITESPACE, false)));
LuceneTaxonomyWriter tw = new LuceneTaxonomyWriter(taxoDir); DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams(); DefaultFacetIndexingParams iParams = new DefaultFacetIndexingParams();
// Add documents and facets // Add documents and facets
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 1000; i++) {
@ -434,7 +434,7 @@ public class TestTotalFacetCountsCache extends LuceneTestCase {
taxoDir.setSleepMillis(1); taxoDir.setSleepMillis(1);
IndexReader r = IndexReader.open(indexDir); IndexReader r = IndexReader.open(indexDir);
LuceneTaxonomyReader tr = new LuceneTaxonomyReader(taxoDir); DirectoryTaxonomyReader tr = new DirectoryTaxonomyReader(taxoDir);
// Create and start threads. Thread1 should lock the cache and calculate // Create and start threads. Thread1 should lock the cache and calculate
// the TFC array. The second thread should block until the first is // the TFC array. The second thread should block until the first is

View File

@ -29,8 +29,8 @@ import org.apache.lucene.facet.search.params.association.AssociationIntSumFacetR
import org.apache.lucene.facet.search.results.FacetResult; import org.apache.lucene.facet.search.results.FacetResult;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -69,7 +69,7 @@ public class AssociationsFacetRequestTest extends LuceneTestCase {
RandomIndexWriter writer = new RandomIndexWriter(random, dir, newIndexWriterConfig(TEST_VERSION_CURRENT, RandomIndexWriter writer = new RandomIndexWriter(random, dir, newIndexWriterConfig(TEST_VERSION_CURRENT,
new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); new MockAnalyzer(random, MockTokenizer.KEYWORD, false)));
TaxonomyWriter taxoWriter = new LuceneTaxonomyWriter(taxoDir); TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
EnhancementsDocumentBuilder builder = new EnhancementsDocumentBuilder( EnhancementsDocumentBuilder builder = new EnhancementsDocumentBuilder(
taxoWriter, new DefaultEnhancementsIndexingParams( taxoWriter, new DefaultEnhancementsIndexingParams(
@ -106,7 +106,7 @@ public class AssociationsFacetRequestTest extends LuceneTestCase {
@Test @Test
public void testIntSumAssociation() throws Exception { public void testIntSumAssociation() throws Exception {
LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets // facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(); FacetSearchParams fsp = new FacetSearchParams();
@ -132,7 +132,7 @@ public class AssociationsFacetRequestTest extends LuceneTestCase {
@Test @Test
public void testFloatSumAssociation() throws Exception { public void testFloatSumAssociation() throws Exception {
LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets // facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(); FacetSearchParams fsp = new FacetSearchParams();
@ -161,7 +161,7 @@ public class AssociationsFacetRequestTest extends LuceneTestCase {
// Same category list cannot be aggregated by two different aggregators. If // Same category list cannot be aggregated by two different aggregators. If
// you want to do that, you need to separate the categories into two // you want to do that, you need to separate the categories into two
// category list (you'll still have one association list). // category list (you'll still have one association list).
LuceneTaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); DirectoryTaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
// facet requests for two facets // facet requests for two facets
FacetSearchParams fsp = new FacetSearchParams(); FacetSearchParams fsp = new FacetSearchParams();

View File

@ -9,7 +9,7 @@ import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.facet.search.FacetResultsHandler; import org.apache.lucene.facet.search.FacetResultsHandler;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -58,8 +58,8 @@ public class FacetRequestTest extends LuceneTestCase {
// create empty indexes, so that LTR ctor won't complain about a missing index. // create empty indexes, so that LTR ctor won't complain about a missing index.
new IndexWriter(dir1, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close(); new IndexWriter(dir1, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close();
new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close(); new IndexWriter(dir2, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close();
TaxonomyReader tr1 = new LuceneTaxonomyReader(dir1); TaxonomyReader tr1 = new DirectoryTaxonomyReader(dir1);
TaxonomyReader tr2 = new LuceneTaxonomyReader(dir2); TaxonomyReader tr2 = new DirectoryTaxonomyReader(dir2);
FacetResultsHandler frh1 = fr.createFacetResultsHandler(tr1); FacetResultsHandler frh1 = fr.createFacetResultsHandler(tr1);
FacetResultsHandler frh2 = fr.createFacetResultsHandler(tr2); FacetResultsHandler frh2 = fr.createFacetResultsHandler(tr2);
assertTrue("should not return the same FacetResultHandler instance for different TaxonomyReader instances", frh1 != frh2); assertTrue("should not return the same FacetResultHandler instance for different TaxonomyReader instances", frh1 != frh2);
@ -77,7 +77,7 @@ public class FacetRequestTest extends LuceneTestCase {
Directory dir = newDirectory(); Directory dir = newDirectory();
// create empty indexes, so that LTR ctor won't complain about a missing index. // create empty indexes, so that LTR ctor won't complain about a missing index.
new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close(); new IndexWriter(dir, new IndexWriterConfig(TEST_VERSION_CURRENT, null)).close();
TaxonomyReader tr = new LuceneTaxonomyReader(dir); TaxonomyReader tr = new DirectoryTaxonomyReader(dir);
FacetResultsHandler frh = fr.createFacetResultsHandler(tr); FacetResultsHandler frh = fr.createFacetResultsHandler(tr);
fr.setDepth(10); fr.setDepth(10);
assertEquals(FacetRequest.DEFAULT_DEPTH, frh.getFacetRequest().getDepth()); assertEquals(FacetRequest.DEFAULT_DEPTH, frh.getFacetRequest().getDepth());

View File

@ -8,8 +8,8 @@ import org.apache.lucene.facet.index.params.DefaultFacetIndexingParams;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.facet.util.PartitionsUtils; import org.apache.lucene.facet.util.PartitionsUtils;
/** /**
@ -37,8 +37,8 @@ public class FacetSearchParamsTest extends LuceneTestCase {
assertEquals("unexpected default facet indexing params class", DefaultFacetIndexingParams.class.getName(), fsp.getFacetIndexingParams().getClass().getName()); assertEquals("unexpected default facet indexing params class", DefaultFacetIndexingParams.class.getName(), fsp.getFacetIndexingParams().getClass().getName());
assertEquals("no facet requests should be added by default", 0, fsp.getFacetRequests().size()); assertEquals("no facet requests should be added by default", 0, fsp.getFacetRequests().size());
Directory dir = newDirectory(); Directory dir = newDirectory();
new LuceneTaxonomyWriter(dir).close(); new DirectoryTaxonomyWriter(dir).close();
TaxonomyReader tr = new LuceneTaxonomyReader(dir); TaxonomyReader tr = new DirectoryTaxonomyReader(dir);
assertEquals("unexpected partition offset for 0 categories", 1, PartitionsUtils.partitionOffset(fsp, 1, tr)); assertEquals("unexpected partition offset for 0 categories", 1, PartitionsUtils.partitionOffset(fsp, 1, tr));
assertEquals("unexpected partition size for 0 categories", 1, PartitionsUtils.partitionSize(fsp,tr)); assertEquals("unexpected partition size for 0 categories", 1, PartitionsUtils.partitionSize(fsp,tr));
tr.close(); tr.close();
@ -56,11 +56,11 @@ public class FacetSearchParamsTest extends LuceneTestCase {
public void testPartitionSizeWithCategories() throws Exception { public void testPartitionSizeWithCategories() throws Exception {
FacetSearchParams fsp = new FacetSearchParams(); FacetSearchParams fsp = new FacetSearchParams();
Directory dir = newDirectory(); Directory dir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(dir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(dir);
tw.addCategory(new CategoryPath("a")); tw.addCategory(new CategoryPath("a"));
tw.commit(); tw.commit();
tw.close(); tw.close();
TaxonomyReader tr = new LuceneTaxonomyReader(dir); TaxonomyReader tr = new DirectoryTaxonomyReader(dir);
assertEquals("unexpected partition offset for 1 categories", 2, PartitionsUtils.partitionOffset(fsp, 1, tr)); assertEquals("unexpected partition offset for 1 categories", 2, PartitionsUtils.partitionOffset(fsp, 1, tr));
assertEquals("unexpected partition size for 1 categories", 2, PartitionsUtils.partitionSize(fsp,tr)); assertEquals("unexpected partition size for 1 categories", 2, PartitionsUtils.partitionSize(fsp,tr));
tr.close(); tr.close();

View File

@ -32,8 +32,8 @@ import org.apache.lucene.facet.search.results.IntermediateFacetResult;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.TaxonomyWriter; import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.facet.util.ScoredDocIdsUtils; import org.apache.lucene.facet.util.ScoredDocIdsUtils;
/** /**
@ -93,7 +93,7 @@ public class MultiIteratorsPerCLParamsTest extends LuceneTestCase {
Directory taxoDir = newDirectory(); Directory taxoDir = newDirectory();
populateIndex(iParams, indexDir, taxoDir); populateIndex(iParams, indexDir, taxoDir);
TaxonomyReader taxo = new LuceneTaxonomyReader(taxoDir); TaxonomyReader taxo = new DirectoryTaxonomyReader(taxoDir);
IndexReader reader = IndexReader.open(indexDir); IndexReader reader = IndexReader.open(indexDir);
CategoryListCache clCache = null; CategoryListCache clCache = null;
@ -168,7 +168,7 @@ public class MultiIteratorsPerCLParamsTest extends LuceneTestCase {
Directory taxoDir) throws Exception { Directory taxoDir) throws Exception {
RandomIndexWriter writer = new RandomIndexWriter(random, indexDir, RandomIndexWriter writer = new RandomIndexWriter(random, indexDir,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))); newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false)));
TaxonomyWriter taxoWriter = new LuceneTaxonomyWriter(taxoDir); TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
for (CategoryPath[] categories : perDocCategories) { for (CategoryPath[] categories : perDocCategories) {
writer.addDocument(new CategoryDocumentBuilder(taxoWriter, iParams) writer.addDocument(new CategoryDocumentBuilder(taxoWriter, iParams)

View File

@ -14,8 +14,8 @@ import org.junit.Test;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.facet.taxonomy.TaxonomyReader.ChildrenArrays; import org.apache.lucene.facet.taxonomy.TaxonomyReader.ChildrenArrays;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.util.SlowRAMDirectory; import org.apache.lucene.util.SlowRAMDirectory;
/** /**
@ -159,7 +159,7 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testWriter() throws Exception { public void testWriter() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
// Also check TaxonomyWriter.getSize() - see that the taxonomy's size // Also check TaxonomyWriter.getSize() - see that the taxonomy's size
// is what we expect it to be. // is what we expect it to be.
@ -175,7 +175,7 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testWriterTwice() throws Exception { public void testWriterTwice() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
// run fillTaxonomy again - this will try to add the same categories // run fillTaxonomy again - this will try to add the same categories
// again, and check that we see the same ordinal paths again, not // again, and check that we see the same ordinal paths again, not
@ -197,10 +197,10 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testWriterTwice2() throws Exception { public void testWriterTwice2() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.close(); tw.close();
tw = new LuceneTaxonomyWriter(indexDir); tw = new DirectoryTaxonomyWriter(indexDir);
// run fillTaxonomy again - this will try to add the same categories // run fillTaxonomy again - this will try to add the same categories
// again, and check that we see the same ordinals again, not different // again, and check that we see the same ordinals again, not different
// ones, and that the number of categories hasn't grown by the new // ones, and that the number of categories hasn't grown by the new
@ -222,7 +222,7 @@ public class TestTaxonomyCombined extends LuceneTestCase {
public void testWriterTwice3() throws Exception { public void testWriterTwice3() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
// First, create and fill the taxonomy // First, create and fill the taxonomy
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.close(); tw.close();
// Now, open the same taxonomy and add the same categories again. // Now, open the same taxonomy and add the same categories again.
@ -231,7 +231,7 @@ public class TestTaxonomyCombined extends LuceneTestCase {
// all into memory and close it's reader. The bug was that it closed // all into memory and close it's reader. The bug was that it closed
// the reader, but forgot that it did (because it didn't set the reader // the reader, but forgot that it did (because it didn't set the reader
// reference to null). // reference to null).
tw = new LuceneTaxonomyWriter(indexDir); tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
// Add one new category, just to make commit() do something: // Add one new category, just to make commit() do something:
tw.addCategory(new CategoryPath("hi")); tw.addCategory(new CategoryPath("hi"));
@ -253,7 +253,7 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testWriterSimpler() throws Exception { public void testWriterSimpler() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
assertEquals(1, tw.getSize()); // the root only assertEquals(1, tw.getSize()); // the root only
// Test that adding a new top-level category works // Test that adding a new top-level category works
assertEquals(1, tw.addCategory(new CategoryPath("a"))); assertEquals(1, tw.addCategory(new CategoryPath("a")));
@ -297,12 +297,12 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testRootOnly() throws Exception { public void testRootOnly() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
// right after opening the index, it should already contain the // right after opening the index, it should already contain the
// root, so have size 1: // root, so have size 1:
assertEquals(1, tw.getSize()); assertEquals(1, tw.getSize());
tw.close(); tw.close();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
assertEquals(1, tr.getSize()); assertEquals(1, tr.getSize());
assertEquals(0, tr.getPath(0).length()); assertEquals(0, tr.getPath(0).length());
assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0)); assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0));
@ -319,9 +319,9 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testRootOnly2() throws Exception { public void testRootOnly2() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
tw.commit(); tw.commit();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
assertEquals(1, tr.getSize()); assertEquals(1, tr.getSize());
assertEquals(0, tr.getPath(0).length()); assertEquals(0, tr.getPath(0).length());
assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0)); assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0));
@ -339,10 +339,10 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testReaderBasic() throws Exception { public void testReaderBasic() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.close(); tw.close();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
// test TaxonomyReader.getSize(): // test TaxonomyReader.getSize():
assertEquals(expectedCategories.length, tr.getSize()); assertEquals(expectedCategories.length, tr.getSize());
@ -398,10 +398,10 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testReaderParent() throws Exception { public void testReaderParent() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.close(); tw.close();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
// check that the parent of the root ordinal is the invalid ordinal: // check that the parent of the root ordinal is the invalid ordinal:
assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0)); assertEquals(TaxonomyReader.INVALID_ORDINAL, tr.getParent(0));
@ -463,11 +463,11 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testWriterParent1() throws Exception { public void testWriterParent1() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.close(); tw.close();
tw = new LuceneTaxonomyWriter(indexDir); tw = new DirectoryTaxonomyWriter(indexDir);
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
checkWriterParent(tr, tw); checkWriterParent(tr, tw);
@ -479,10 +479,10 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testWriterParent2() throws Exception { public void testWriterParent2() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.commit(); tw.commit();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
checkWriterParent(tr, tw); checkWriterParent(tr, tw);
@ -542,10 +542,10 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testReaderParentArray() throws Exception { public void testReaderParentArray() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.close(); tw.close();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
int[] parents = tr.getParentArray(); int[] parents = tr.getParentArray();
assertEquals(tr.getSize(), parents.length); assertEquals(tr.getSize(), parents.length);
for (int i=0; i<tr.getSize(); i++) { for (int i=0; i<tr.getSize(); i++) {
@ -563,10 +563,10 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testChildrenArrays() throws Exception { public void testChildrenArrays() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.close(); tw.close();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
ChildrenArrays ca = tr.getChildrenArrays(); ChildrenArrays ca = tr.getChildrenArrays();
int[] youngestChildArray = ca.getYoungestChildArray(); int[] youngestChildArray = ca.getYoungestChildArray();
assertEquals(tr.getSize(), youngestChildArray.length); assertEquals(tr.getSize(), youngestChildArray.length);
@ -627,10 +627,10 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testChildrenArraysInvariants() throws Exception { public void testChildrenArraysInvariants() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
tw.close(); tw.close();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
ChildrenArrays ca = tr.getChildrenArrays(); ChildrenArrays ca = tr.getChildrenArrays();
int[] youngestChildArray = ca.getYoungestChildArray(); int[] youngestChildArray = ca.getYoungestChildArray();
assertEquals(tr.getSize(), youngestChildArray.length); assertEquals(tr.getSize(), youngestChildArray.length);
@ -707,10 +707,10 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testChildrenArraysGrowth() throws Exception { public void testChildrenArraysGrowth() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
tw.addCategory(new CategoryPath("hi", "there")); tw.addCategory(new CategoryPath("hi", "there"));
tw.commit(); tw.commit();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
ChildrenArrays ca = tr.getChildrenArrays(); ChildrenArrays ca = tr.getChildrenArrays();
assertEquals(3, tr.getSize()); assertEquals(3, tr.getSize());
assertEquals(3, ca.getOlderSiblingArray().length); assertEquals(3, ca.getOlderSiblingArray().length);
@ -747,12 +747,12 @@ public class TestTaxonomyCombined extends LuceneTestCase {
public void testTaxonomyReaderRefreshRaces() throws Exception { public void testTaxonomyReaderRefreshRaces() throws Exception {
// compute base child arrays - after first chunk, and after the other // compute base child arrays - after first chunk, and after the other
Directory indexDirBase = newDirectory(); Directory indexDirBase = newDirectory();
TaxonomyWriter twBase = new LuceneTaxonomyWriter(indexDirBase); TaxonomyWriter twBase = new DirectoryTaxonomyWriter(indexDirBase);
twBase.addCategory(new CategoryPath("a", "0")); twBase.addCategory(new CategoryPath("a", "0"));
final CategoryPath abPath = new CategoryPath("a", "b"); final CategoryPath abPath = new CategoryPath("a", "b");
twBase.addCategory(abPath); twBase.addCategory(abPath);
twBase.commit(); twBase.commit();
TaxonomyReader trBase = new LuceneTaxonomyReader(indexDirBase); TaxonomyReader trBase = new DirectoryTaxonomyReader(indexDirBase);
final ChildrenArrays ca1 = trBase.getChildrenArrays(); final ChildrenArrays ca1 = trBase.getChildrenArrays();
@ -779,12 +779,12 @@ public class TestTaxonomyCombined extends LuceneTestCase {
final int abOrd, final int abYoungChildBase1, final int abYoungChildBase2, final int retry) final int abOrd, final int abYoungChildBase1, final int abYoungChildBase2, final int retry)
throws Exception { throws Exception {
SlowRAMDirectory indexDir = new SlowRAMDirectory(-1,null); // no slowness for intialization SlowRAMDirectory indexDir = new SlowRAMDirectory(-1,null); // no slowness for intialization
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
tw.addCategory(new CategoryPath("a", "0")); tw.addCategory(new CategoryPath("a", "0"));
tw.addCategory(abPath); tw.addCategory(abPath);
tw.commit(); tw.commit();
final TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); final TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
for (int i=0; i < 1<<10; i++) { //1024 facets for (int i=0; i < 1<<10; i++) { //1024 facets
final CategoryPath cp = new CategoryPath("a", "b", Integer.toString(i)); final CategoryPath cp = new CategoryPath("a", "b", Integer.toString(i));
tw.addCategory(cp); tw.addCategory(cp);
@ -865,9 +865,9 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testSeparateReaderAndWriter() throws Exception { public void testSeparateReaderAndWriter() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
tw.commit(); tw.commit();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
int author = 1; int author = 1;
@ -932,9 +932,9 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testSeparateReaderAndWriter2() throws Exception { public void testSeparateReaderAndWriter2() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
tw.commit(); tw.commit();
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
// Test getOrdinal(): // Test getOrdinal():
CategoryPath author = new CategoryPath("Author"); CategoryPath author = new CategoryPath("Author");
@ -968,26 +968,26 @@ public class TestTaxonomyCombined extends LuceneTestCase {
public void testWriterLock() throws Exception { public void testWriterLock() throws Exception {
// native fslock impl gets angry if we use it, so use RAMDirectory explicitly. // native fslock impl gets angry if we use it, so use RAMDirectory explicitly.
Directory indexDir = new RAMDirectory(); Directory indexDir = new RAMDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
tw.addCategory(new CategoryPath("hi", "there")); tw.addCategory(new CategoryPath("hi", "there"));
tw.commit(); tw.commit();
// we deliberately not close the write now, and keep it open and // we deliberately not close the write now, and keep it open and
// locked. // locked.
// Verify that the writer worked: // Verify that the writer worked:
TaxonomyReader tr = new LuceneTaxonomyReader(indexDir); TaxonomyReader tr = new DirectoryTaxonomyReader(indexDir);
assertEquals(2, tr.getOrdinal(new CategoryPath("hi", "there"))); assertEquals(2, tr.getOrdinal(new CategoryPath("hi", "there")));
// Try to open a second writer, with the first one locking the directory. // Try to open a second writer, with the first one locking the directory.
// We expect to get a LockObtainFailedException. // We expect to get a LockObtainFailedException.
try { try {
new LuceneTaxonomyWriter(indexDir); new DirectoryTaxonomyWriter(indexDir);
fail("should have failed to write in locked directory"); fail("should have failed to write in locked directory");
} catch (LockObtainFailedException e) { } catch (LockObtainFailedException e) {
// this is what we expect to happen. // this is what we expect to happen.
} }
// Remove the lock, and now the open should succeed, and we can // Remove the lock, and now the open should succeed, and we can
// write to the new writer. // write to the new writer.
LuceneTaxonomyWriter.unlock(indexDir); DirectoryTaxonomyWriter.unlock(indexDir);
TaxonomyWriter tw2 = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw2 = new DirectoryTaxonomyWriter(indexDir);
tw2.addCategory(new CategoryPath("hey")); tw2.addCategory(new CategoryPath("hey"));
tw2.close(); tw2.close();
// See that the writer indeed wrote: // See that the writer indeed wrote:
@ -1054,7 +1054,7 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testWriterCheckPaths() throws Exception { public void testWriterCheckPaths() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomyCheckPaths(tw); fillTaxonomyCheckPaths(tw);
// Also check TaxonomyWriter.getSize() - see that the taxonomy's size // Also check TaxonomyWriter.getSize() - see that the taxonomy's size
// is what we expect it to be. // is what we expect it to be.
@ -1073,14 +1073,14 @@ public class TestTaxonomyCombined extends LuceneTestCase {
@Test @Test
public void testWriterCheckPaths2() throws Exception { public void testWriterCheckPaths2() throws Exception {
Directory indexDir = newDirectory(); Directory indexDir = newDirectory();
TaxonomyWriter tw = new LuceneTaxonomyWriter(indexDir); TaxonomyWriter tw = new DirectoryTaxonomyWriter(indexDir);
fillTaxonomy(tw); fillTaxonomy(tw);
checkPaths(tw); checkPaths(tw);
fillTaxonomy(tw); fillTaxonomy(tw);
checkPaths(tw); checkPaths(tw);
tw.close(); tw.close();
tw = new LuceneTaxonomyWriter(indexDir); tw = new DirectoryTaxonomyWriter(indexDir);
checkPaths(tw); checkPaths(tw);
fillTaxonomy(tw); fillTaxonomy(tw);
checkPaths(tw); checkPaths(tw);

View File

@ -1,4 +1,4 @@
package org.apache.lucene.facet.taxonomy.lucene; package org.apache.lucene.facet.taxonomy.directory;
import java.io.File; import java.io.File;
@ -10,11 +10,11 @@ import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.util._TestUtil; import org.apache.lucene.util._TestUtil;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.TaxonomyReader; import org.apache.lucene.facet.taxonomy.TaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter.DiskOrdinalMap; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.DiskOrdinalMap;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter.MemoryOrdinalMap; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.MemoryOrdinalMap;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter.OrdinalMap; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter.OrdinalMap;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -38,16 +38,16 @@ public class TestAddTaxonomies extends LuceneTestCase {
@Test @Test
public void test1() throws Exception { public void test1() throws Exception {
Directory dir1 = newDirectory(); Directory dir1 = newDirectory();
LuceneTaxonomyWriter tw1 = new LuceneTaxonomyWriter(dir1); DirectoryTaxonomyWriter tw1 = new DirectoryTaxonomyWriter(dir1);
tw1.addCategory(new CategoryPath("Author", "Mark Twain")); tw1.addCategory(new CategoryPath("Author", "Mark Twain"));
tw1.addCategory(new CategoryPath("Animals", "Dog")); tw1.addCategory(new CategoryPath("Animals", "Dog"));
Directory dir2 = newDirectory(); Directory dir2 = newDirectory();
LuceneTaxonomyWriter tw2 = new LuceneTaxonomyWriter(dir2); DirectoryTaxonomyWriter tw2 = new DirectoryTaxonomyWriter(dir2);
tw2.addCategory(new CategoryPath("Author", "Rob Pike")); tw2.addCategory(new CategoryPath("Author", "Rob Pike"));
tw2.addCategory(new CategoryPath("Aardvarks", "Bob")); tw2.addCategory(new CategoryPath("Aardvarks", "Bob"));
tw2.close(); tw2.close();
Directory dir3 = newDirectory(); Directory dir3 = newDirectory();
LuceneTaxonomyWriter tw3 = new LuceneTaxonomyWriter(dir3); DirectoryTaxonomyWriter tw3 = new DirectoryTaxonomyWriter(dir3);
tw3.addCategory(new CategoryPath("Author", "Zebra Smith")); tw3.addCategory(new CategoryPath("Author", "Zebra Smith"));
tw3.addCategory(new CategoryPath("Aardvarks", "Bob")); tw3.addCategory(new CategoryPath("Aardvarks", "Bob"));
tw3.addCategory(new CategoryPath("Aardvarks", "Aaron")); tw3.addCategory(new CategoryPath("Aardvarks", "Aaron"));
@ -60,7 +60,7 @@ public class TestAddTaxonomies extends LuceneTestCase {
tw1.addTaxonomies(new Directory[] { dir2, dir3 }, maps); tw1.addTaxonomies(new Directory[] { dir2, dir3 }, maps);
tw1.close(); tw1.close();
TaxonomyReader tr = new LuceneTaxonomyReader(dir1); TaxonomyReader tr = new DirectoryTaxonomyReader(dir1);
// Test that the merged taxonomy now contains what we expect: // Test that the merged taxonomy now contains what we expect:
// First all the categories of the original taxonomy, in their original order: // First all the categories of the original taxonomy, in their original order:
@ -132,8 +132,8 @@ public class TestAddTaxonomies extends LuceneTestCase {
for (int i=0; i<ntaxonomies; i++) { for (int i=0; i<ntaxonomies; i++) {
dirs[i] = newDirectory(); dirs[i] = newDirectory();
copydirs[i] = newDirectory(); copydirs[i] = newDirectory();
LuceneTaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[i]); DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[i]);
LuceneTaxonomyWriter copytw = new LuceneTaxonomyWriter(copydirs[i]); DirectoryTaxonomyWriter copytw = new DirectoryTaxonomyWriter(copydirs[i]);
for (int j=0; j<ncats; j++) { for (int j=0; j<ncats; j++) {
String cat = Integer.toString(random.nextInt(range)); String cat = Integer.toString(random.nextInt(range));
tw.addCategory(new CategoryPath("a",cat)); tw.addCategory(new CategoryPath("a",cat));
@ -144,7 +144,7 @@ public class TestAddTaxonomies extends LuceneTestCase {
copytw.close(); copytw.close();
} }
LuceneTaxonomyWriter tw = new LuceneTaxonomyWriter(dirs[0]); DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(dirs[0]);
Directory otherdirs[] = new Directory[ntaxonomies-1]; Directory otherdirs[] = new Directory[ntaxonomies-1];
System.arraycopy(dirs, 1, otherdirs, 0, ntaxonomies-1); System.arraycopy(dirs, 1, otherdirs, 0, ntaxonomies-1);
@ -168,8 +168,8 @@ public class TestAddTaxonomies extends LuceneTestCase {
// Check that all original categories in the main taxonomy remain in // Check that all original categories in the main taxonomy remain in
// unchanged, and the rest of the taxonomies are completely unchanged. // unchanged, and the rest of the taxonomies are completely unchanged.
for (int i=0; i<ntaxonomies; i++) { for (int i=0; i<ntaxonomies; i++) {
TaxonomyReader tr = new LuceneTaxonomyReader(dirs[i]); TaxonomyReader tr = new DirectoryTaxonomyReader(dirs[i]);
TaxonomyReader copytr = new LuceneTaxonomyReader(copydirs[i]); TaxonomyReader copytr = new DirectoryTaxonomyReader(copydirs[i]);
if (i==0) { if (i==0) {
assertTrue(tr.getSize() >= copytr.getSize()); assertTrue(tr.getSize() >= copytr.getSize());
} else { } else {
@ -188,8 +188,8 @@ public class TestAddTaxonomies extends LuceneTestCase {
// Check that all the new categories in the main taxonomy are in // Check that all the new categories in the main taxonomy are in
// lexicographic order. This isn't a requirement of our API, but happens // lexicographic order. This isn't a requirement of our API, but happens
// this way in our current implementation. // this way in our current implementation.
TaxonomyReader tr = new LuceneTaxonomyReader(dirs[0]); TaxonomyReader tr = new DirectoryTaxonomyReader(dirs[0]);
TaxonomyReader copytr = new LuceneTaxonomyReader(copydirs[0]); TaxonomyReader copytr = new DirectoryTaxonomyReader(copydirs[0]);
if (tr.getSize() > copytr.getSize()) { if (tr.getSize() > copytr.getSize()) {
String prev = tr.getPath(copytr.getSize()).toString(); String prev = tr.getPath(copytr.getSize()).toString();
for (int j=copytr.getSize()+1; j<tr.getSize(); j++) { for (int j=copytr.getSize()+1; j<tr.getSize(); j++) {
@ -204,9 +204,9 @@ public class TestAddTaxonomies extends LuceneTestCase {
// Check that all the categories from other taxonomies exist in the new // Check that all the categories from other taxonomies exist in the new
// taxonomy. // taxonomy.
TaxonomyReader main = new LuceneTaxonomyReader(dirs[0]); TaxonomyReader main = new DirectoryTaxonomyReader(dirs[0]);
for (int i=1; i<ntaxonomies; i++) { for (int i=1; i<ntaxonomies; i++) {
TaxonomyReader other = new LuceneTaxonomyReader(dirs[i]); TaxonomyReader other = new DirectoryTaxonomyReader(dirs[i]);
for (int j=0; j<other.getSize(); j++) { for (int j=0; j<other.getSize(); j++) {
int otherord = main.getOrdinal(other.getPath(j)); int otherord = main.getOrdinal(other.getPath(j));
assertTrue(otherord != TaxonomyReader.INVALID_ORDINAL); assertTrue(otherord != TaxonomyReader.INVALID_ORDINAL);
@ -218,7 +218,7 @@ public class TestAddTaxonomies extends LuceneTestCase {
// one of the added taxonomies. // one of the added taxonomies.
TaxonomyReader[] others = new TaxonomyReader[ntaxonomies-1]; TaxonomyReader[] others = new TaxonomyReader[ntaxonomies-1];
for (int i=1; i<ntaxonomies; i++) { for (int i=1; i<ntaxonomies; i++) {
others[i-1] = new LuceneTaxonomyReader(dirs[i]); others[i-1] = new DirectoryTaxonomyReader(dirs[i]);
} }
for (int j=oldsize; j<main.getSize(); j++) { for (int j=oldsize; j<main.getSize(); j++) {
boolean found=false; boolean found=false;

View File

@ -1,6 +1,8 @@
package org.apache.lucene.facet.taxonomy.lucene; package org.apache.lucene.facet.taxonomy.directory;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.store.AlreadyClosedException; import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory; import org.apache.lucene.store.Directory;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
@ -23,16 +25,16 @@ import org.junit.Test;
* limitations under the License. * limitations under the License.
*/ */
public class TestLuceneTaxonomyReader extends LuceneTestCase { public class TestDirectoryTaxonomyReader extends LuceneTestCase {
@Test @Test
public void testCloseAfterIncRef() throws Exception { public void testCloseAfterIncRef() throws Exception {
Directory dir = newDirectory(); Directory dir = newDirectory();
LuceneTaxonomyWriter ltw = new LuceneTaxonomyWriter(dir); DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir);
ltw.addCategory(new CategoryPath("a")); ltw.addCategory(new CategoryPath("a"));
ltw.close(); ltw.close();
LuceneTaxonomyReader ltr = new LuceneTaxonomyReader(dir); DirectoryTaxonomyReader ltr = new DirectoryTaxonomyReader(dir);
ltr.incRef(); ltr.incRef();
ltr.close(); ltr.close();
@ -46,11 +48,11 @@ public class TestLuceneTaxonomyReader extends LuceneTestCase {
@Test @Test
public void testCloseTwice() throws Exception { public void testCloseTwice() throws Exception {
Directory dir = newDirectory(); Directory dir = newDirectory();
LuceneTaxonomyWriter ltw = new LuceneTaxonomyWriter(dir); DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir);
ltw.addCategory(new CategoryPath("a")); ltw.addCategory(new CategoryPath("a"));
ltw.close(); ltw.close();
LuceneTaxonomyReader ltr = new LuceneTaxonomyReader(dir); DirectoryTaxonomyReader ltr = new DirectoryTaxonomyReader(dir);
ltr.close(); ltr.close();
ltr.close(); // no exception should be thrown ltr.close(); // no exception should be thrown
@ -60,11 +62,11 @@ public class TestLuceneTaxonomyReader extends LuceneTestCase {
@Test @Test
public void testAlreadyClosed() throws Exception { public void testAlreadyClosed() throws Exception {
Directory dir = newDirectory(); Directory dir = newDirectory();
LuceneTaxonomyWriter ltw = new LuceneTaxonomyWriter(dir); DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir);
ltw.addCategory(new CategoryPath("a")); ltw.addCategory(new CategoryPath("a"));
ltw.close(); ltw.close();
LuceneTaxonomyReader ltr = new LuceneTaxonomyReader(dir); DirectoryTaxonomyReader ltr = new DirectoryTaxonomyReader(dir);
ltr.close(); ltr.close();
try { try {
ltr.getSize(); ltr.getSize();

View File

@ -1,4 +1,4 @@
package org.apache.lucene.facet.taxonomy.lucene; package org.apache.lucene.facet.taxonomy.directory;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -10,7 +10,7 @@ import org.junit.Test;
import org.apache.lucene.util.LuceneTestCase; import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
import org.apache.lucene.facet.taxonomy.writercache.TaxonomyWriterCache; import org.apache.lucene.facet.taxonomy.writercache.TaxonomyWriterCache;
/** /**
@ -30,7 +30,7 @@ import org.apache.lucene.facet.taxonomy.writercache.TaxonomyWriterCache;
* limitations under the License. * limitations under the License.
*/ */
public class TestLuceneTaxonomyWriter extends LuceneTestCase { public class TestDirectoryTaxonomyWriter extends LuceneTestCase {
// A No-Op TaxonomyWriterCache which always discards all given categories, and // A No-Op TaxonomyWriterCache which always discards all given categories, and
// always returns true in put(), to indicate some cache entries were cleared. // always returns true in put(), to indicate some cache entries were cleared.
@ -52,7 +52,7 @@ public class TestLuceneTaxonomyWriter extends LuceneTestCase {
// Verifies that nothing is committed to the underlying Directory, if // Verifies that nothing is committed to the underlying Directory, if
// commit() wasn't called. // commit() wasn't called.
Directory dir = newDirectory(); Directory dir = newDirectory();
LuceneTaxonomyWriter ltw = new LuceneTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache()); DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache());
assertFalse(IndexReader.indexExists(dir)); assertFalse(IndexReader.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"));
@ -68,7 +68,7 @@ public class TestLuceneTaxonomyWriter extends LuceneTestCase {
public void testCommitUserData() throws Exception { public void testCommitUserData() throws Exception {
// Verifies that committed data is retrievable // Verifies that committed data is retrievable
Directory dir = newDirectory(); Directory dir = newDirectory();
LuceneTaxonomyWriter ltw = new LuceneTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache()); DirectoryTaxonomyWriter ltw = new DirectoryTaxonomyWriter(dir, OpenMode.CREATE_OR_APPEND, new NoOpCache());
assertFalse(IndexReader.indexExists(dir)); assertFalse(IndexReader.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"));

View File

@ -1,4 +1,4 @@
package org.apache.lucene.facet.taxonomy.lucene; package org.apache.lucene.facet.taxonomy.directory;
import java.io.IOException; import java.io.IOException;
import java.util.HashSet; import java.util.HashSet;
@ -18,8 +18,8 @@ import org.apache.lucene.util.LuceneTestCase;
import org.apache.lucene.analysis.MockAnalyzer; import org.apache.lucene.analysis.MockAnalyzer;
import org.apache.lucene.analysis.MockTokenizer; import org.apache.lucene.analysis.MockTokenizer;
import org.apache.lucene.facet.taxonomy.CategoryPath; import org.apache.lucene.facet.taxonomy.CategoryPath;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyReader; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
import org.apache.lucene.facet.taxonomy.lucene.LuceneTaxonomyWriter; import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
/** /**
* Licensed to the Apache Software Foundation (ASF) under one or more * Licensed to the Apache Software Foundation (ASF) under one or more
@ -51,7 +51,7 @@ public class TestIndexClose extends LuceneTestCase {
public void testLeaks() throws Exception { public void testLeaks() throws Exception {
LeakChecker checker = new LeakChecker(); LeakChecker checker = new LeakChecker();
Directory dir = newDirectory(); Directory dir = newDirectory();
LuceneTaxonomyWriter tw = checker.openWriter(dir); DirectoryTaxonomyWriter tw = checker.openWriter(dir);
tw.close(); tw.close();
assertEquals(0, checker.nopen()); assertEquals(0, checker.nopen());
@ -60,7 +60,7 @@ public class TestIndexClose extends LuceneTestCase {
tw.close(); tw.close();
assertEquals(0, checker.nopen()); assertEquals(0, checker.nopen());
LuceneTaxonomyReader tr = checker.openReader(dir); DirectoryTaxonomyReader tr = checker.openReader(dir);
tr.getPath(1); tr.getPath(1);
tr.refresh(); tr.refresh();
tr.close(); tr.close();
@ -100,11 +100,11 @@ public class TestIndexClose extends LuceneTestCase {
LeakChecker() { } LeakChecker() { }
public LuceneTaxonomyWriter openWriter(Directory dir) throws CorruptIndexException, LockObtainFailedException, IOException { public DirectoryTaxonomyWriter openWriter(Directory dir) throws CorruptIndexException, LockObtainFailedException, IOException {
return new InstrumentedTaxonomyWriter(dir); return new InstrumentedTaxonomyWriter(dir);
} }
public LuceneTaxonomyReader openReader(Directory dir) throws CorruptIndexException, LockObtainFailedException, IOException { public DirectoryTaxonomyReader openReader(Directory dir) throws CorruptIndexException, LockObtainFailedException, IOException {
return new InstrumentedTaxonomyReader(dir); return new InstrumentedTaxonomyReader(dir);
} }
@ -121,7 +121,7 @@ public class TestIndexClose extends LuceneTestCase {
return ret; return ret;
} }
private class InstrumentedTaxonomyWriter extends LuceneTaxonomyWriter { private class InstrumentedTaxonomyWriter extends DirectoryTaxonomyWriter {
public InstrumentedTaxonomyWriter(Directory dir) throws CorruptIndexException, LockObtainFailedException, IOException { public InstrumentedTaxonomyWriter(Directory dir) throws CorruptIndexException, LockObtainFailedException, IOException {
super(dir); super(dir);
} }
@ -130,8 +130,7 @@ public class TestIndexClose extends LuceneTestCase {
return new InstrumentedIndexReader(super.openReader()); return new InstrumentedIndexReader(super.openReader());
} }
@Override @Override
protected void openLuceneIndex (Directory directory, OpenMode openMode) protected void openIndexWriter (Directory directory, OpenMode openMode) throws IOException {
throws CorruptIndexException, LockObtainFailedException, IOException {
indexWriter = new InstrumentedIndexWriter(directory, indexWriter = new InstrumentedIndexWriter(directory,
newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false)) newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random, MockTokenizer.KEYWORD, false))
.setOpenMode(openMode)); .setOpenMode(openMode));
@ -139,7 +138,7 @@ public class TestIndexClose extends LuceneTestCase {
} }
private class InstrumentedTaxonomyReader extends LuceneTaxonomyReader { private class InstrumentedTaxonomyReader extends DirectoryTaxonomyReader {
public InstrumentedTaxonomyReader(Directory dir) throws CorruptIndexException, LockObtainFailedException, IOException { public InstrumentedTaxonomyReader(Directory dir) throws CorruptIndexException, LockObtainFailedException, IOException {
super(dir); super(dir);
} }