mirror of https://github.com/apache/lucene.git
LUCENE-3269: speed up facet tests by creating indexing once per testcase
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1201678 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
e7294aab77
commit
9dd296a662
|
@ -30,6 +30,7 @@ import org.apache.lucene.search.IndexSearcher;
|
|||
import org.apache.lucene.store.Directory;
|
||||
|
||||
import org.apache.lucene.util.Bits;
|
||||
import org.apache.lucene.util.IOUtils;
|
||||
import org.apache.lucene.util.LuceneTestCase;
|
||||
import org.apache.lucene.util._TestUtil;
|
||||
import org.apache.lucene.facet.index.CategoryDocumentBuilder;
|
||||
|
@ -45,6 +46,8 @@ import org.apache.lucene.facet.taxonomy.TaxonomyReader;
|
|||
import org.apache.lucene.facet.taxonomy.TaxonomyWriter;
|
||||
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyReader;
|
||||
import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
|
||||
/**
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
|
@ -66,15 +69,18 @@ import org.apache.lucene.facet.taxonomy.directory.DirectoryTaxonomyWriter;
|
|||
/** Base faceted search test. */
|
||||
public abstract class FacetTestBase extends LuceneTestCase {
|
||||
|
||||
/** Holds a search and taxonomy Directories pair. */
|
||||
private static final class SearchTaxoDirPair {
|
||||
Directory searchDir, taxoDir;
|
||||
SearchTaxoDirPair() {}
|
||||
}
|
||||
|
||||
private static HashMap<Integer, SearchTaxoDirPair> dirsPerPartitionSize;
|
||||
private static File TEST_DIR;
|
||||
|
||||
/** Documents text field. */
|
||||
protected static final String CONTENT_FIELD = "content";
|
||||
|
||||
/** Directory for the index */
|
||||
protected Directory indexDir;
|
||||
|
||||
/** Directory for the taxonomy */
|
||||
protected Directory taxoDir;
|
||||
|
||||
/** taxonomy Reader for the test. */
|
||||
protected TaxonomyReader taxoReader;
|
||||
|
||||
|
@ -84,6 +90,19 @@ public abstract class FacetTestBase extends LuceneTestCase {
|
|||
/** Searcher for the test. */
|
||||
protected IndexSearcher searcher;
|
||||
|
||||
@BeforeClass
|
||||
public static void beforeClassFacetTestBase() throws Exception {
|
||||
TEST_DIR = _TestUtil.getTempDir("facets");
|
||||
dirsPerPartitionSize = new HashMap<Integer, FacetTestBase.SearchTaxoDirPair>();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void afterClassFacetTestBase() throws Exception {
|
||||
for (SearchTaxoDirPair pair : dirsPerPartitionSize.values()) {
|
||||
IOUtils.close(pair.searchDir, pair.taxoDir);
|
||||
}
|
||||
}
|
||||
|
||||
/** documents text (for the text field). */
|
||||
private static final String[] DEFAULT_CONTENT = {
|
||||
"the white car is the one I want.",
|
||||
|
@ -122,22 +141,24 @@ public abstract class FacetTestBase extends LuceneTestCase {
|
|||
}
|
||||
|
||||
/** Prepare index (in RAM/Disk) with some documents and some facets */
|
||||
protected final void initIndex(int partitionSize, boolean onDisk) throws Exception {
|
||||
protected final void initIndex(int partitionSize, boolean forceDisk) throws Exception {
|
||||
if (VERBOSE) {
|
||||
System.out.println("Partition Size: " + partitionSize+" onDisk: "+onDisk);
|
||||
System.out.println("Partition Size: " + partitionSize+" forceDisk: "+forceDisk);
|
||||
}
|
||||
|
||||
if (onDisk) {
|
||||
File indexFile = _TestUtil.getTempDir("index");
|
||||
indexDir = newFSDirectory(indexFile);
|
||||
taxoDir = newFSDirectory(new File(indexFile,"facets"));
|
||||
SearchTaxoDirPair pair = dirsPerPartitionSize.get(Integer.valueOf(partitionSize));
|
||||
if (pair == null) {
|
||||
pair = new SearchTaxoDirPair();
|
||||
if (forceDisk) {
|
||||
pair.searchDir = newFSDirectory(new File(TEST_DIR, "index"));
|
||||
pair.taxoDir = newFSDirectory(new File(TEST_DIR, "taxo"));
|
||||
} else {
|
||||
indexDir = newDirectory();
|
||||
taxoDir = newDirectory();
|
||||
pair.searchDir = newDirectory();
|
||||
pair.taxoDir = newDirectory();
|
||||
}
|
||||
|
||||
RandomIndexWriter iw = new RandomIndexWriter(random, indexDir, getIndexWriterConfig(getAnalyzer()));
|
||||
TaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE);
|
||||
RandomIndexWriter iw = new RandomIndexWriter(random, pair.searchDir, getIndexWriterConfig(getAnalyzer()));
|
||||
TaxonomyWriter taxo = new DirectoryTaxonomyWriter(pair.taxoDir, OpenMode.CREATE);
|
||||
|
||||
populateIndex(iw, taxo, getFacetIndexingParams(partitionSize));
|
||||
|
||||
|
@ -147,9 +168,12 @@ public abstract class FacetTestBase extends LuceneTestCase {
|
|||
taxo.close();
|
||||
iw.close();
|
||||
|
||||
dirsPerPartitionSize.put(Integer.valueOf(partitionSize), pair);
|
||||
}
|
||||
|
||||
// prepare for searching
|
||||
taxoReader = new DirectoryTaxonomyReader(taxoDir);
|
||||
indexReader = IndexReader.open(indexDir);
|
||||
taxoReader = new DirectoryTaxonomyReader(pair.taxoDir);
|
||||
indexReader = IndexReader.open(pair.searchDir);
|
||||
searcher = newSearcher(indexReader);
|
||||
}
|
||||
|
||||
|
@ -207,16 +231,10 @@ public abstract class FacetTestBase extends LuceneTestCase {
|
|||
/** Close all indexes */
|
||||
protected void closeAll() throws Exception {
|
||||
// close and nullify everything
|
||||
taxoReader.close();
|
||||
IOUtils.close(taxoReader, indexReader, searcher);
|
||||
taxoReader = null;
|
||||
indexReader.close();
|
||||
indexReader = null;
|
||||
searcher.close();
|
||||
searcher = null;
|
||||
indexDir.close();
|
||||
indexDir = null;
|
||||
taxoDir.close();
|
||||
taxoDir = null;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue