Package org.apache.lucene.facet.taxonomy

Examples of org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager


    // How many unique facets to index before stopping:
    final int ordLimit = TEST_NIGHTLY ? 100000 : 6000;

    Thread indexer = new IndexerThread(w, config, tw, null, ordLimit, stop);

    final SearcherTaxonomyManager mgr = new SearcherTaxonomyManager(w, true, null, tw);

    Thread reopener = new Thread() {
        @Override
        public void run() {
          while(!stop.get()) {
            try {
              // Sleep for up to 20 msec:
              Thread.sleep(random().nextInt(20));

              if (VERBOSE) {
                System.out.println("TEST: reopen");
              }

              mgr.maybeRefresh();

              if (VERBOSE) {
                System.out.println("TEST: reopen done");
              }
            } catch (Exception ioe) {
              throw new RuntimeException(ioe);
            }
          }
        }
      };
    reopener.start();

    indexer.start();

    try {
      while (!stop.get()) {
        SearcherAndTaxonomy pair = mgr.acquire();
        try {
          //System.out.println("search maxOrd=" + pair.taxonomyReader.getSize());
          FacetsCollector sfc = new FacetsCollector();
          pair.searcher.search(new MatchAllDocsQuery(), sfc);
          Facets facets = getTaxonomyFacetCounts(pair.taxonomyReader, config, sfc);
          FacetResult result = facets.getTopChildren(10, "field");
          if (pair.searcher.getIndexReader().numDocs() > 0) {
            //System.out.println(pair.taxonomyReader.getSize());
            assertTrue(result.childCount > 0);
            assertTrue(result.labelValues.length > 0);
          }

          //if (VERBOSE) {
          //System.out.println("TEST: facets=" + FacetTestUtils.toString(results.get(0)));
          //}
        } finally {
          mgr.release(pair);
        }
      }
    } finally {
      indexer.join();
      reopener.join();
View Full Code Here


    final IndexWriter w = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
    final DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
    // first empty commit
    w.commit();
    tw.commit();
    final SearcherTaxonomyManager mgr = new SearcherTaxonomyManager(indexDir, taxoDir, null);
    final FacetsConfig config = new FacetsConfig();
    config.setMultiValued("field", true);
    final AtomicBoolean stop = new AtomicBoolean();

    // How many unique facets to index before stopping:
    final int ordLimit = TEST_NIGHTLY ? 100000 : 6000;

    Thread indexer = new IndexerThread(w, config, tw, mgr, ordLimit, stop);
    indexer.start();

    try {
      while (!stop.get()) {
        SearcherAndTaxonomy pair = mgr.acquire();
        try {
          //System.out.println("search maxOrd=" + pair.taxonomyReader.getSize());
          FacetsCollector sfc = new FacetsCollector();
          pair.searcher.search(new MatchAllDocsQuery(), sfc);
          Facets facets = getTaxonomyFacetCounts(pair.taxonomyReader, config, sfc);
          FacetResult result = facets.getTopChildren(10, "field");
          if (pair.searcher.getIndexReader().numDocs() > 0) {
            //System.out.println(pair.taxonomyReader.getSize());
            assertTrue(result.childCount > 0);
            assertTrue(result.labelValues.length > 0);
          }

          //if (VERBOSE) {
          //System.out.println("TEST: facets=" + FacetTestUtils.toString(results.get(0)));
          //}
        } finally {
          mgr.release(pair);
        }
      }
    } finally {
      indexer.join();
    }
View Full Code Here

    Directory taxoDir2 = newDirectory();
    DirectoryTaxonomyWriter tw2 = new DirectoryTaxonomyWriter(taxoDir2);
    tw2.close();

    SearcherTaxonomyManager mgr = new SearcherTaxonomyManager(w, true, null, tw);
    w.addDocument(new Document());
    tw.replaceTaxonomy(taxoDir2);
    taxoDir2.close();

    try {
      mgr.maybeRefresh();
      fail("should have hit exception");
    } catch (IllegalStateException ise) {
      // expected
    }
View Full Code Here

    Directory taxoDir2 = newDirectory();
    DirectoryTaxonomyWriter tw2 = new DirectoryTaxonomyWriter(taxoDir2);
    tw2.addCategory(new FacetLabel("a", "b"));
    tw2.close();

    SearcherTaxonomyManager mgr = new SearcherTaxonomyManager(indexDir, taxoDir, null);
    SearcherAndTaxonomy pair = mgr.acquire();
    try {
      assertEquals(1, pair.taxonomyReader.getSize());
    } finally {
      mgr.release(pair);
    }
   
    w.addDocument(new Document());
    tw.replaceTaxonomy(taxoDir2);
    taxoDir2.close();
    w.commit();
    tw.commit();

    mgr.maybeRefresh();
    pair = mgr.acquire();
    try {
      assertEquals(3, pair.taxonomyReader.getSize());
    } finally {
      mgr.release(pair);
    }

    IOUtils.close(mgr, tw, w, taxoDir, indexDir);
  }
View Full Code Here

TOP

Related Classes of org.apache.lucene.facet.taxonomy.SearcherTaxonomyManager

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.