Examples of CategoryPath


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

    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

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

  private void verifyResults(Directory dir, Directory taxDir, FacetIndexingParams fip) throws IOException {
    DirectoryReader reader1 = DirectoryReader.open(dir);
    DirectoryTaxonomyReader taxReader = new DirectoryTaxonomyReader(taxDir);
    IndexSearcher searcher = newSearcher(reader1);
    FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(new CategoryPath("tag"), NUM_DOCS));
    FacetsCollector collector = FacetsCollector.create(fsp, reader1, taxReader);
    searcher.search(new MatchAllDocsQuery(), collector);
    FacetResult result = collector.getFacetResults().get(0);
    FacetResultNode node = result.getFacetResultNode();
    for (FacetResultNode facet: node.subResults) {
View Full Code Here

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

    for (int i = 1; i <= NUM_DOCS; i++) {
      Document doc = new Document();
      List<CategoryPath> categoryPaths = new ArrayList<CategoryPath>(i + 1);
      for (int j = i; j <= NUM_DOCS; j++) {
        int facetValue = asc? j: NUM_DOCS - j;
        categoryPaths.add(new CategoryPath("tag", Integer.toString(facetValue)));
      }
      FacetFields facetFields = new FacetFields(taxonomyWriter, fip);
      facetFields.addFields(doc, categoryPaths);
      writer.addDocument(doc);
    }   
View Full Code Here

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

        }
        _TestUtil.checkIndex(taxoDir);
       
        // verify faceted search
        int id = Integer.parseInt(indexReader.getIndexCommit().getUserData().get(VERSION_ID), 16);
        CategoryPath cp = new CategoryPath("A", Integer.toString(id, 16));
        IndexSearcher searcher = new IndexSearcher(indexReader);
        FacetsCollector fc = FacetsCollector.create(new FacetSearchParams(new CountFacetRequest(cp, 10)), indexReader, taxoReader);
        searcher.search(new MatchAllDocsQuery(), fc);
        assertEquals(1, (int) fc.getFacetResults().get(0).getFacetResultNode().value);
       
View Full Code Here

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

      HashSet<String> docDimensions = new HashSet<String>();
      while (numCategories-- > 0) {
        String dim = DIMENSIONS[random.nextInt(DIMENSIONS.length)];
        // we should only increment the expected count by 1 per document
        docDimensions.add(dim);
        categories.add(new CategoryPath(dim, Integer.toString(i), Integer.toString(numCategories)));
      }
      facetFields.addFields(doc, categories);
      doc.add(new StringField("docid", Integer.toString(i), Store.YES));
      doc.add(new TextField("foo", "content" + i, Store.YES));
      indexWriter.addDocument(doc);

      // update expected count per dimension
      for (String dim : docDimensions) {
        Integer val = expectedCounts.get(dim);
        if (val == null) {
          expectedCounts.put(dim, Integer.valueOf(1));
        } else {
          expectedCounts.put(dim, Integer.valueOf(val.intValue() + 1));
        }
      }
     
      if (random.nextDouble() < 0.2) { // add some documents that will be deleted
        doc = new Document();
        doc.add(new StringField("del", "key", Store.NO));
        facetFields.addFields(doc, Collections.singletonList(new CategoryPath("dummy")));
        indexWriter.addDocument(doc);
      }
    }
   
    indexWriter.commit();
View Full Code Here

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

  private void verifyFacetedSearch(Map<String,Integer> expectedCounts, FacetIndexingParams fip,
      DirectoryReader indexReader, TaxonomyReader taxoReader, IndexSearcher searcher) throws IOException {
    // run faceted search and assert expected counts
    ArrayList<FacetRequest> requests = new ArrayList<FacetRequest>(expectedCounts.size());
    for (String dim : expectedCounts.keySet()) {
      requests.add(new CountFacetRequest(new CategoryPath(dim), 5));
    }
    FacetSearchParams fsp = new FacetSearchParams(fip, requests);
    FacetsCollector fc = FacetsCollector.create(fsp, indexReader, taxoReader);
    MatchAllDocsQuery base = new MatchAllDocsQuery();
    searcher.search(base, fc);
View Full Code Here

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

 
  private void verifyDrillDown(Map<String,Integer> expectedCounts, FacetIndexingParams fip, DirectoryReader indexReader,
      TaxonomyReader taxoReader, IndexSearcher searcher) throws IOException {
    // verify drill-down
    for (String dim : expectedCounts.keySet()) {
      CategoryPath drillDownCP = new CategoryPath(dim);
      FacetSearchParams fsp = new FacetSearchParams(fip, new CountFacetRequest(drillDownCP, 10));
      DrillDownQuery drillDown = new DrillDownQuery(fip, new MatchAllDocsQuery());
      drillDown.add(drillDownCP);
      TotalHitCountCollector total = new TotalHitCountCollector();
      FacetsCollector fc = FacetsCollector.create(fsp, indexReader, taxoReader);
View Full Code Here

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

    for (int i = 0; i < foundOrdinals.length; i++) {
      foundOrdinals[i] = false; // init to be on the safe side
    }
    foundOrdinals[0] = true; // ROOT ordinals isn't indexed
    // mark 'dummy' category ordinal as seen
    int dummyOrdinal = taxoReader.getOrdinal(new CategoryPath("dummy"));
    if (dummyOrdinal > 0) {
      foundOrdinals[dummyOrdinal] = true;
    }
   
    int partitionSize = fip.getPartitionSize();
    int numPartitions = (int) Math.ceil(taxoReader.getSize() / (double) partitionSize);
    final IntsRef ordinals = new IntsRef(32);
    for (String dim : DIMENSIONS) {
      CategoryListParams clp = fip.getCategoryListParams(new CategoryPath(dim));
      int partitionOffset = 0;
      for (int partition = 0; partition < numPartitions; partition++, partitionOffset += partitionSize) {
        final CategoryListIterator cli = clp.createCategoryListIterator(partition);
        for (AtomicReaderContext context : indexReader.leaves()) {
          if (cli.setNextReader(context)) { // not all fields may exist in all segments
View Full Code Here

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

    Directory indexDir = newDirectory();
    Directory taxoDir = newDirectory();
   
    // set custom CLP fields for two dimensions and use the default ($facets) for the other two
    HashMap<CategoryPath,CategoryListParams> params = new HashMap<CategoryPath,CategoryListParams>();
    params.put(new CategoryPath(DIMENSIONS[0]), new CategoryListParams(DIMENSIONS[0]) {
      @Override
      public OrdinalPolicy getOrdinalPolicy(String dimension) {
        return OrdinalPolicy.ALL_PARENTS;
      }
    });
    params.put(new CategoryPath(DIMENSIONS[1]), new CategoryListParams(DIMENSIONS[1]) {
      @Override
      public OrdinalPolicy getOrdinalPolicy(String dimension) {
        return OrdinalPolicy.ALL_PARENTS;
      }
    });
View Full Code Here

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

public class IndexAndTaxonomyRevisionTest extends ReplicatorTestCase {
 
  private Document newDocument(TaxonomyWriter taxoWriter) throws IOException {
    Document doc = new Document();
    FacetFields ff = new FacetFields(taxoWriter);
    ff.addFields(doc, Collections.singleton(new CategoryPath("A")));
    return doc;
  }
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.