Package org.apache.lucene.facet.taxonomy

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


      // For computing range facet counts:
      doc.add(new NumericDocValuesField("field", l));
      // For drill down by numeric range:
      doc.add(new LongField("field", l, Field.Store.NO));

      CategoryPath cp;
      if ((l&3) == 0) {
        cp = new CategoryPath("dim", "a");
      } else {
        cp = new CategoryPath("dim", "b");
      }
      ff.addFields(doc, Collections.singletonList(cp));
      w.addDocument(doc);
    }

    final IndexReader r = w.getReader();
    w.close();

    final TaxonomyReader tr = new DirectoryTaxonomyReader(tw);
    tw.close();

    IndexSearcher s = newSearcher(r);

    final CountFacetRequest countRequest = new CountFacetRequest(new CategoryPath("dim"), 2);
    final RangeFacetRequest<LongRange> rangeRequest = new RangeFacetRequest<LongRange>("field",
                          new LongRange("less than 10", 0L, true, 10L, false),
                          new LongRange("less than or equal to 10", 0L, true, 10L, true),
                          new LongRange("over 90", 90L, false, 100L, false),
                          new LongRange("90 or above", 90L, true, 100L, false),
                          new LongRange("over 1000", 1000L, false, Long.MAX_VALUE, false));
    FacetSearchParams fsp = new FacetSearchParams(countRequest, rangeRequest);
   
    final Set<String> dimSeen = new HashSet<String>();

    DrillSideways ds = new DrillSideways(s, tr) {
        @Override
        protected FacetsAccumulator getDrillDownAccumulator(FacetSearchParams fsp) {
          checkSeen(fsp);
          return FacetsAccumulator.create(fsp, r, tr, null);
        }

        @Override
        protected FacetsAccumulator getDrillSidewaysAccumulator(String dim, FacetSearchParams fsp) {
          checkSeen(fsp);
          return FacetsAccumulator.create(fsp, r, tr, null);
        }

        private void checkSeen(FacetSearchParams fsp) {
          // Each dim should up only once, across
          // both drillDown and drillSideways requests:
          for(FacetRequest fr : fsp.facetRequests) {
            String dim = fr.categoryPath.components[0];
            assertFalse("dim " + dim + " already seen", dimSeen.contains(dim));
            dimSeen.add(dim);
          }
        }

        @Override
        protected boolean scoreSubDocsAtOnce() {
          return random().nextBoolean();
        }
      };

    // First search, no drill downs:
    DrillDownQuery ddq = new DrillDownQuery(FacetIndexingParams.DEFAULT, new MatchAllDocsQuery());
    DrillSidewaysResult dsr = ds.search(null, ddq, 10, fsp);

    assertEquals(100, dsr.hits.totalHits);
    assertEquals(2, dsr.facetResults.size());
    assertEquals("dim (0)\n  b (75)\n  a (25)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(0)));
    assertEquals("field (0)\n  less than 10 (10)\n  less than or equal to 10 (11)\n  over 90 (9)\n  90 or above (10)\n  over 1000 (0)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(1)));

    // Second search, drill down on dim=b:
    ddq = new DrillDownQuery(FacetIndexingParams.DEFAULT, new MatchAllDocsQuery());
    ddq.add(new CategoryPath("dim", "b"));
    dimSeen.clear();
    dsr = ds.search(null, ddq, 10, fsp);

    assertEquals(75, dsr.hits.totalHits);
    assertEquals(2, dsr.facetResults.size());
View Full Code Here


      // For computing range facet counts:
      doc.add(new NumericDocValuesField("field", l));
      // For drill down by numeric range:
      doc.add(new LongField("field", l, Field.Store.NO));

      CategoryPath cp;
      if ((l&3) == 0) {
        cp = new CategoryPath("dim", "a");
      } else {
        cp = new CategoryPath("dim", "b");
      }
      ff.addFields(doc, Collections.singletonList(cp));
      w.addDocument(doc);
    }

    final IndexReader r = w.getReader();
    w.close();

    IndexSearcher s = newSearcher(r);
    final SortedSetDocValuesReaderState state = new SortedSetDocValuesReaderState(s.getIndexReader());

    final CountFacetRequest countRequest = new CountFacetRequest(new CategoryPath("dim"), 2);
    final RangeFacetRequest<LongRange> rangeRequest = new RangeFacetRequest<LongRange>("field",
                          new LongRange("less than 10", 0L, true, 10L, false),
                          new LongRange("less than or equal to 10", 0L, true, 10L, true),
                          new LongRange("over 90", 90L, false, 100L, false),
                          new LongRange("90 or above", 90L, true, 100L, false),
                          new LongRange("over 1000", 1000L, false, Long.MAX_VALUE, false));
    FacetSearchParams fsp = new FacetSearchParams(countRequest, rangeRequest);
   
    final Set<String> dimSeen = new HashSet<String>();

    DrillSideways ds = new DrillSideways(s, state) {
        @Override
        protected FacetsAccumulator getDrillDownAccumulator(FacetSearchParams fsp) throws IOException {
          checkSeen(fsp);
          return FacetsAccumulator.create(fsp, state, null);
        }

        @Override
        protected FacetsAccumulator getDrillSidewaysAccumulator(String dim, FacetSearchParams fsp) throws IOException {
          checkSeen(fsp);
          return FacetsAccumulator.create(fsp, state, null);
        }

        private void checkSeen(FacetSearchParams fsp) {
          // Each dim should up only once, across
          // both drillDown and drillSideways requests:
          for(FacetRequest fr : fsp.facetRequests) {
            String dim = fr.categoryPath.components[0];
            assertFalse("dim " + dim + " already seen", dimSeen.contains(dim));
            dimSeen.add(dim);
          }
        }

        @Override
        protected boolean scoreSubDocsAtOnce() {
          return random().nextBoolean();
        }
      };

    // First search, no drill downs:
    DrillDownQuery ddq = new DrillDownQuery(FacetIndexingParams.DEFAULT, new MatchAllDocsQuery());
    DrillSidewaysResult dsr = ds.search(null, ddq, 10, fsp);

    assertEquals(100, dsr.hits.totalHits);
    assertEquals(2, dsr.facetResults.size());
    assertEquals("dim (0)\n  b (75)\n  a (25)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(0)));
    assertEquals("field (0)\n  less than 10 (10)\n  less than or equal to 10 (11)\n  over 90 (9)\n  90 or above (10)\n  over 1000 (0)\n", FacetTestUtils.toSimpleString(dsr.facetResults.get(1)));

    // Second search, drill down on dim=b:
    ddq = new DrillDownQuery(FacetIndexingParams.DEFAULT, new MatchAllDocsQuery());
    ddq.add(new CategoryPath("dim", "b"));
    dimSeen.clear();
    dsr = ds.search(null, ddq, 10, fsp);

    assertEquals(75, dsr.hits.totalHits);
    assertEquals(2, dsr.facetResults.size());
View Full Code Here

  /** Utility method to add a document and facets to an index/taxonomy. */
  private static void addFacets(FacetIndexingParams iParams, IndexWriter iw,
      TaxonomyWriter tw, String... strings) throws IOException {
    Document doc = new Document();
    FacetFields facetFields = new FacetFields(tw, iParams);
    facetFields.addFields(doc, Collections.singletonList(new CategoryPath(strings)));
    iw.addDocument(doc);
  }
View Full Code Here

    TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
    FacetFields facetFields = new FacetFields(taxoWriter);
   
    for (String cat : CATEGORIES) {
      Document doc = new Document();
      facetFields.addFields(doc, Collections.singletonList(new CategoryPath(cat, '/')));
      indexWriter.addDocument(doc);
    }
   
    IOUtils.close(indexWriter, taxoWriter);
  }
View Full Code Here

      }

      @Override
      public void run() {
        try {
          FacetSearchParams fsp = new FacetSearchParams(iParams, new CountFacetRequest(new CategoryPath("a"), 10),
              new CountFacetRequest(new CategoryPath("b"), 10));
          IndexSearcher searcher = new IndexSearcher(indexReader);
          FacetsCollector fc = FacetsCollector.create(fsp, indexReader, taxoReader);
          searcher.search(new MatchAllDocsQuery(), fc);
          results = fc.getFacetResults();
        } catch (Exception e) {
View Full Code Here

    File outputFile = _TestUtil.createTempFile("test", "tmp", TEMP_DIR);
    TFC.store(outputFile, indexReader, taxoReader, iParams);
   
    // Make the taxonomy grow without touching the index
    for (int i = 0; i < 10; i++) {
      taxoWriter.addCategory(new CategoryPath("foo", Integer.toString(i)));
    }
    taxoWriter.commit();
    TaxonomyReader newTaxoReader = TaxonomyReader.openIfChanged(taxoReader);
    assertNotNull(newTaxoReader);
    taxoReader.close();
View Full Code Here

      }

      @Override
      public void run() {
        try {
          FacetSearchParams fsp = new FacetSearchParams(iParams, new CountFacetRequest(new CategoryPath("a"), 10),
              new CountFacetRequest(new CategoryPath("b"), 10));
          IndexSearcher searcher = new IndexSearcher(indexReader);
          FacetsCollector fc = FacetsCollector.create(fsp, indexReader, taxoReader);
          searcher.search(new MatchAllDocsQuery(), fc);
          results = fc.getFacetResults();
        } catch (Exception e) {
View Full Code Here

    assertEquals("Wrong number of top count aggregated categories no complement!",3,parentResNoComp.subResults.size());
  }
 
  /** compute facets with certain facet requests and docs */
  private List<FacetResult> findFacets(boolean withComplement) throws IOException {
    FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(new CategoryPath("root","a"), 10));
    OldFacetsAccumulator sfa = new OldFacetsAccumulator(fsp, indexReader, taxoReader);
    sfa.setComplementThreshold(withComplement ? OldFacetsAccumulator.FORCE_COMPLEMENT : OldFacetsAccumulator.DISABLE_COMPLEMENT);
    FacetsCollector fc = FacetsCollector.create(sfa);
    searcher.search(new MatchAllDocsQuery(), fc);
   
View Full Code Here

  }
 
  private Document newDocument(TaxonomyWriter taxoWriter, int id) throws IOException {
    Document doc = new Document();
    FacetFields facetFields = new FacetFields(taxoWriter);
    facetFields.addFields(doc, Collections.singleton(new CategoryPath("A", Integer.toString(id, 16))));
    return doc;
  }
View Full Code Here

    String[] categories = new String[] { "a/b", "c/d", "a/e", "a/d", "c/g", "c/z", "b/a", "1/2", "b/c" };

    FacetFields facetFields = new FacetFields(taxoWriter, iParams);
    for (String cat : categories) {
      Document doc = new Document();
      facetFields.addFields(doc, Collections.singletonList(new CategoryPath(cat, '/')));
      indexWriter.addDocument(doc);
    }

    // Commit Changes
    IOUtils.close(indexWriter, taxoWriter);
View Full Code Here

TOP

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

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.