Examples of CategoryPath


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

  public void testTopLevelSettings() {
    FacetIndexingParams ifip = new PerDimensionIndexingParams(Collections.<CategoryPath, CategoryListParams>emptyMap());
    assertNotNull("Missing default category list", ifip.getAllCategoryListParams());
    assertEquals("Expected default category list field is $facets", "$facets", ifip.getCategoryListParams(null).field);
    String expectedDDText = "a" + ifip.getFacetDelimChar() + "b";
    CategoryPath cp = new CategoryPath("a", "b");
    assertEquals("wrong drill-down term", new Term("$facets", expectedDDText), DrillDownQuery.term(ifip,cp));
    char[] buf = new char[20];
    int numchars = ifip.drillDownTermText(cp, buf);
    assertEquals("3 characters should be written", 3, numchars);
    assertEquals("wrong drill-down term text", expectedDDText, new String(buf, 0, numchars));
View Full Code Here

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

  @Test
  public void testCategoryListParamsAddition() {
    CategoryListParams clp = new CategoryListParams("clp");
    PerDimensionIndexingParams tlfip = new PerDimensionIndexingParams(
        Collections.<CategoryPath,CategoryListParams> singletonMap(new CategoryPath("a"), clp));
    assertEquals("Expected category list field is " + clp.field,
        clp.field, tlfip.getCategoryListParams(new CategoryPath("a")).field);
    assertNotSame("Unexpected default category list " + clp.field, clp, tlfip.getCategoryListParams(null));
  }
View Full Code Here

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

  @Test
  public void testDefaultSettings() {
    FacetIndexingParams dfip = FacetIndexingParams.DEFAULT;
    assertNotNull("Missing default category list", dfip.getAllCategoryListParams());
    assertEquals("all categories have the same CategoryListParams by default",
        dfip.getCategoryListParams(null), dfip.getCategoryListParams(new CategoryPath("a")));
    assertEquals("Expected default category list field is $facets", "$facets", dfip.getCategoryListParams(null).field);
    String expectedDDText = "a"
        + dfip.getFacetDelimChar() + "b";
    CategoryPath cp = new CategoryPath("a", "b");
    assertEquals("wrong drill-down term", new Term("$facets",
        expectedDDText), DrillDownQuery.term(dfip,cp));
    char[] buf = new char[20];
    int numchars = dfip.drillDownTermText(cp, buf);
    assertEquals("3 characters should be written", 3, numchars);
View Full Code Here

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

    }
   
    // build the PerDimensionIndexingParams
    HashMap<CategoryPath,CategoryListParams> clps = new HashMap<CategoryPath,CategoryListParams>();
    for (String dim : dimensions) {
      CategoryPath cp = new CategoryPath(dim);
      CategoryListParams clp = randomCategoryListParams("$" + dim);
      clps.put(cp, clp);
    }
    PerDimensionIndexingParams indexingParams = new PerDimensionIndexingParams(clps);
   
    // index some documents
    Directory indexDir = newDirectory();
    Directory taxoDir = newDirectory();
    IndexWriter indexWriter = new IndexWriter(indexDir, newIndexWriterConfig(TEST_VERSION_CURRENT, null).setMaxBufferedDocs(2));
    TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
    FacetFields facetFields = new FacetFields(taxoWriter, indexingParams);
    int ndocs = atLeast(random, 10);
    for (int i = 0; i < ndocs; i++) {
      Document doc = new Document();
      int numCategories = random.nextInt(numDimensions) + 1;
      ArrayList<CategoryPath> categories = new ArrayList<CategoryPath>();
      for (int j = 0; j < numCategories; j++) {
        String dimension = dimensions[random.nextInt(dimensions.length)];
        categories.add(new CategoryPath(dimension, Integer.toString(i)));
      }
      facetFields.addFields(doc, categories);
      indexWriter.addDocument(doc);
    }
    IOUtils.close(indexWriter, taxoWriter);
   
    // test the multi iterator
    DirectoryReader indexReader = DirectoryReader.open(indexDir);
    TaxonomyReader taxoReader = new DirectoryTaxonomyReader(taxoDir);
    CategoryListIterator[] iterators = new CategoryListIterator[numDimensions];
    for (int i = 0; i < iterators.length; i++) {
      CategoryListParams clp = indexingParams.getCategoryListParams(new CategoryPath(dimensions[i]));
      IntDecoder decoder = clp.createEncoder().createMatchingDecoder();
      iterators[i] = new DocValuesCategoryListIterator(clp.field, decoder);
    }
    MultiCategoryListIterator cli = new MultiCategoryListIterator(iterators);
    for (AtomicReaderContext context : indexReader.leaves()) {
      assertTrue("failed to init multi-iterator", cli.setNextReader(context));
      IntsRef ordinals = new IntsRef();
      final int maxDoc = context.reader().maxDoc();
      for (int i = 0; i < maxDoc; i++) {
        cli.getOrdinals(i, ordinals);
        assertTrue("document " + i + " does not have categories", ordinals.length > 0);
        for (int j = 0; j < ordinals.length; j++) {
          CategoryPath cp = taxoReader.getPath(ordinals.ints[j]);
          assertNotNull("ordinal " + ordinals.ints[j] + " not found in taxonomy", cp);
          if (cp.length == 2) {
            int globalDoc = i + context.docBase;
            assertEquals("invalid category for document " + globalDoc, globalDoc, Integer.parseInt(cp.components[1]));
          }
View Full Code Here

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

      String[] components = new String[depth];
      for (int k = 0; k < depth; k++) {
        components[k] = Integer.toString(random.nextInt(maxValue));
        addItem();
      }
      CategoryPath cp = new CategoryPath(components);
      facets.add(cp);
      addBytes(cp.toString().length()); // very rough approximation
    }
  }
View Full Code Here

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

      ChildrenIterator chilrenIt = r.getChildren(child);
      int numImmediateChildren = 0;
      while (chilrenIt.next() != TaxonomyReader.INVALID_ORDINAL) {
        numImmediateChildren++;
      }
      CategoryPath cp = r.getPath(child);
      out.println("/" + cp + ": " + numImmediateChildren + " immediate children; " + (1+countAllChildren(r, child)) + " total categories");
      if (printTree) {
        printAllChildren(out, r, child, "  ", 1);
      }
    }
View Full Code Here

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

 
  private Document newDocument(FacetFields facetFields, String... categories) throws IOException {
    Document doc = new Document();
    List<CategoryPath> cats = new ArrayList<CategoryPath>();
    for (String cat : categories) {
      cats.add(new CategoryPath(cat, '/'));
    }
    facetFields.addFields(doc, cats);
    return doc;
  }
View Full Code Here

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

      String[][] drillDowns, int[] numResults) throws IOException {
    CategoryPath[][] cps = new CategoryPath[drillDowns.length][];
    for (int i = 0; i < cps.length; i++) {
      cps[i] = new CategoryPath[drillDowns[i].length];
      for (int j = 0; j < cps[i].length; j++) {
        cps[i][j] = new CategoryPath(drillDowns[i][j], '/');
      }
    }
    DrillDownQuery ddq = new DrillDownQuery(FacetIndexingParams.DEFAULT, new MatchAllDocsQuery());
    for (CategoryPath[] cats : cps) {
      ddq.add(cats);
    }
   
    List<FacetRequest> facetRequests = new ArrayList<FacetRequest>();
    for (CategoryPath[] cats : cps) {
      for (int i = 0; i < cats.length; i++) {
        CategoryPath cp = cats[i];
        int numres = numResults == null ? 2 : numResults[i];
        // for each drill-down, add itself as well as its parent as requests, so
        // we get the drill-sideways
        facetRequests.add(new CountFacetRequest(cp, numres));
        CountFacetRequest parent = new CountFacetRequest(cp.subpath(cp.length - 1), numres);
        if (!facetRequests.contains(parent) && parent.categoryPath.length > 0) {
          facetRequests.add(parent);
        }
      }
    }
View Full Code Here

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

  }
 
  // Following LUCENE-4461 - ensure requesting the (exact) same request more
  // than once does not alter the results
  public void testTwoSameRequests() throws Exception {
    final CountFacetRequest facetRequest = new CountFacetRequest(new CategoryPath("root"), 10);
    FacetSearchParams fsp = new FacetSearchParams(fip, facetRequest);
   
    FacetsCollector fc = FacetsCollector.create(fsp, indexReader, taxoReader);
    searcher.search(new MatchAllDocsQuery(), fc);
   
    final String expected = fc.getFacetResults().get(0).toString();

    // now add the same facet request with duplicates (same instance and same one)
    fsp = new FacetSearchParams(fip, facetRequest, facetRequest, new CountFacetRequest(new CategoryPath("root"), 10));

    // make sure the search params holds 3 requests now
    assertEquals(3, fsp.facetRequests.size());
   
    fc = FacetsCollector.create(fsp, indexReader, taxoReader);
View Full Code Here

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

                      paths.add(path);
                      break;
                    }
                  }
                }
                docPaths.add(new CategoryPath("field", path));
              }
              try {
                facetFields.addFields(doc, docPaths);
                w.addDocument(doc);
              } catch (IOException ioe) {
                throw new RuntimeException(ioe);
              }

              if (tw.getSize() >= ordLimit) {
                break;
              }
            }
          } finally {
            stop.set(true);
          }
        }
      };

    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());
          int topN = _TestUtil.nextInt(random(), 1, 20);
          CountFacetRequest cfr = new CountFacetRequest(new CategoryPath("field"), topN);
          FacetSearchParams fsp = new FacetSearchParams(cfr);
          FacetsCollector fc = FacetsCollector.create(fsp, pair.searcher.getIndexReader(), pair.taxonomyReader);
          pair.searcher.search(new MatchAllDocsQuery(), fc);
          List<FacetResult> results = fc.getFacetResults();
          FacetResult fr = results.get(0);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.