Return-Path: X-Original-To: apmail-lucene-commits-archive@www.apache.org Delivered-To: apmail-lucene-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 13EB19BCB for ; Mon, 14 Nov 2011 12:16:19 +0000 (UTC) Received: (qmail 36268 invoked by uid 500); 14 Nov 2011 12:16:18 -0000 Mailing-List: contact commits-help@lucene.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@lucene.apache.org Delivered-To: mailing list commits@lucene.apache.org Received: (qmail 36261 invoked by uid 99); 14 Nov 2011 12:16:18 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Nov 2011 12:16:18 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 14 Nov 2011 12:16:17 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id 74D042388860; Mon, 14 Nov 2011 12:15:57 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1201677 - /lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/FacetTestBase.java Date: Mon, 14 Nov 2011 12:15:57 -0000 To: commits@lucene.apache.org From: shaie@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111114121557.74D042388860@eris.apache.org> Author: shaie Date: Mon Nov 14 12:15:57 2011 New Revision: 1201677 URL: http://svn.apache.org/viewvc?rev=1201677&view=rev Log: LUCENE-3269: speed up facet tests by creating indexing once per testcase Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/FacetTestBase.java Modified: lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/FacetTestBase.java URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/FacetTestBase.java?rev=1201677&r1=1201676&r2=1201677&view=diff ============================================================================== --- lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/FacetTestBase.java (original) +++ lucene/dev/branches/branch_3x/lucene/contrib/facet/src/test/org/apache/lucene/facet/FacetTestBase.java Mon Nov 14 12:15:57 2011 @@ -28,6 +28,7 @@ import org.apache.lucene.index.TermEnum; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.Directory; +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; @@ -43,6 +44,8 @@ import org.apache.lucene.facet.taxonomy. 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 @@ -64,14 +67,17 @@ import org.apache.lucene.facet.taxonomy. /** Base faceted search test. */ public abstract class FacetTestBase extends LuceneTestCase { - /** Documents text field. */ - protected static final String CONTENT_FIELD = "content"; + /** Holds a search and taxonomy Directories pair. */ + private static final class SearchTaxoDirPair { + Directory searchDir, taxoDir; + SearchTaxoDirPair() {} + } - /** Directory for the index */ - protected Directory indexDir; + private static HashMap dirsPerPartitionSize; + private static File TEST_DIR; - /** Directory for the taxonomy */ - protected Directory taxoDir; + /** Documents text field. */ + protected static final String CONTENT_FIELD = "content"; /** taxonomy Reader for the test. */ protected TaxonomyReader taxoReader; @@ -82,6 +88,19 @@ public abstract class FacetTestBase exte /** Searcher for the test. */ protected IndexSearcher searcher; + @BeforeClass + public static void beforeClassFacetTestBase() throws Exception { + TEST_DIR = _TestUtil.getTempDir("facets"); + dirsPerPartitionSize = new HashMap(); + } + + @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.", @@ -120,34 +139,39 @@ public abstract class FacetTestBase exte } /** 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")); - } else { - indexDir = newDirectory(); - taxoDir = newDirectory(); + 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 { + pair.searchDir = newDirectory(); + pair.taxoDir = newDirectory(); + } + + RandomIndexWriter iw = new RandomIndexWriter(random, pair.searchDir, getIndexWriterConfig(getAnalyzer())); + TaxonomyWriter taxo = new DirectoryTaxonomyWriter(pair.taxoDir, OpenMode.CREATE); + + populateIndex(iw, taxo, getFacetIndexingParams(partitionSize)); + + // commit changes (taxonomy prior to search index for consistency) + taxo.commit(); + iw.commit(); + taxo.close(); + iw.close(); + + dirsPerPartitionSize.put(Integer.valueOf(partitionSize), pair); } - RandomIndexWriter iw = new RandomIndexWriter(random, indexDir, getIndexWriterConfig(getAnalyzer())); - TaxonomyWriter taxo = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE); - - populateIndex(iw, taxo, getFacetIndexingParams(partitionSize)); - - // commit changes (taxonomy prior to search index for consistency) - taxo.commit(); - iw.commit(); - taxo.close(); - iw.close(); - // prepare for searching - taxoReader = new DirectoryTaxonomyReader(taxoDir); - indexReader = IndexReader.open(indexDir); + taxoReader = new DirectoryTaxonomyReader(pair.taxoDir); + indexReader = IndexReader.open(pair.searchDir); searcher = newSearcher(indexReader); } @@ -205,16 +229,10 @@ public abstract class FacetTestBase exte /** 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; } /**