Examples of FacetFields


Examples of org.apache.lucene.facet.index.FacetFields

    // 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
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

    super.setup();
    if (facetFields == null) {
      boolean withFacets = getRunData().getConfig().get("with.facets", true);
      if (withFacets) {
        FacetSource facetsSource = getRunData().getFacetSource();
        facetFields = withFacets ? new FacetFields(getRunData().getTaxonomyWriter()) : null;
        facetsSource.getNextFacets(facets);
      }
    }
  }
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

 
  private void initIndex(Directory indexDir, Directory taxoDir) throws IOException {
    IndexWriterConfig conf = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
    IndexWriter indexWriter = new IndexWriter(indexDir, conf);
    DirectoryTaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
    FacetFields facetFields = new FacetFields(taxoWriter);
    indexWriter.addDocument(newDocument(facetFields, "Date/2010/March/12", "A/1"));
    indexWriter.addDocument(newDocument(facetFields, "Date/2010/March/23", "A/2"));
    indexWriter.addDocument(newDocument(facetFields, "Date/2010/April/17", "A/3"));
    indexWriter.addDocument(newDocument(facetFields, "Date/2010/May/18", "A/1"));
    indexWriter.addDocument(newDocument(facetFields, "Date/2011/January/1", "A/3"));
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

  public void test() throws Exception {
    Directory dir = newDirectory();
    Directory taxoDir = newDirectory();
    final IndexWriter w = new IndexWriter(dir, newIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random())));
    final DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir);
    final FacetFields facetFields = new FacetFields(tw);
    final AtomicBoolean stop = new AtomicBoolean();

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

    Thread indexer = new Thread() {
        @Override
        public void run() {
          try {
            Set<String> seen = new HashSet<String>();
            List<String> paths = new ArrayList<String>();
            while (true) {
              Document doc = new Document();
              List<CategoryPath> docPaths = new ArrayList<CategoryPath>();
              int numPaths = _TestUtil.nextInt(random(), 1, 5);
              for(int i=0;i<numPaths;i++) {
                String path;
                if (!paths.isEmpty() && random().nextInt(5) != 4) {
                  // Use previous path
                  path = paths.get(random().nextInt(paths.size()));
                } else {
                  // Create new path
                  path = null;
                  while (true) {
                    path = _TestUtil.randomRealisticUnicodeString(random());
                    if (path.length() != 0 && !seen.contains(path) && path.indexOf(FacetIndexingParams.DEFAULT_FACET_DELIM_CHAR) == -1) {
                      seen.add(path);
                      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);
              }
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

 
  private static void indexDocsWithFacetsNoTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter,
      ObjectToIntMap<CategoryPath> expectedCounts) throws IOException {
    Random random = random();
    int numDocs = atLeast(random, 2);
    FacetFields facetFields = new FacetFields(taxoWriter, fip);
    for (int i = 0; i < numDocs; i++) {
      Document doc = new Document();
      addFacets(doc, facetFields, false);
      indexWriter.addDocument(doc);
    }
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

 
  private static void indexDocsWithFacetsAndTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter,
      ObjectToIntMap<CategoryPath> expectedCounts) throws IOException {
    Random random = random();
    int numDocs = atLeast(random, 2);
    FacetFields facetFields = new FacetFields(taxoWriter, fip);
    for (int i = 0; i < numDocs; i++) {
      Document doc = new Document();
      addFacets(doc, facetFields, true);
      addField(doc);
      indexWriter.addDocument(doc);
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

 
  private static void indexDocsWithFacetsAndSomeTerms(IndexWriter indexWriter, TaxonomyWriter taxoWriter,
      ObjectToIntMap<CategoryPath> expectedCounts) throws IOException {
    Random random = random();
    int numDocs = atLeast(random, 2);
    FacetFields facetFields = new FacetFields(taxoWriter, fip);
    for (int i = 0; i < numDocs; i++) {
      Document doc = new Document();
      boolean hasContent = random.nextBoolean();
      if (hasContent) {
        addField(doc);
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

      public CategoryListIterator createCategoryListIterator(int partition) throws IOException {
        return new AssertingCategoryListIterator(super.createCategoryListIterator(partition));
      }
    });
    TaxonomyWriter taxoWriter = new DirectoryTaxonomyWriter(taxoDir);
    FacetFields facetFields = new FacetFields(taxoWriter, fip);
    indexTwoDocs(indexWriter, facetFields, false); // 1st segment, no content, with categories
    indexTwoDocs(indexWriter, null, true);         // 2nd segment, with content, no categories
    indexTwoDocs(indexWriter, facetFields, true)// 3rd segment ok
    indexTwoDocs(indexWriter, null, false);        // 4th segment, no content, or categories
    indexTwoDocs(indexWriter, null, true);         // 5th segment, with content, no categories
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

    final DirectoryTaxonomyWriter tw = new DirectoryTaxonomyWriter(taxoDir, OpenMode.CREATE, newTaxoWriterCache(numDocs.get()));
    final Thread[] indexThreads = new Thread[atLeast(4)];

    for (int i = 0; i < indexThreads.length; i++) {
      indexThreads[i] = new Thread() {
        private final FacetFields facetFields = new FacetFields(tw);
       
        @Override
        public void run() {
          Random random = random();
          while (numDocs.decrementAndGet() > 0) {
            try {
              Document doc = new Document();
              int numCats = random.nextInt(3) + 1; // 1-3
              List<CategoryPath> cats = new ArrayList<CategoryPath>(numCats);
              while (numCats-- > 0) {
                CategoryPath cp = newCategory();
                cats.add(cp);
                // add all prefixes to values
                int level = cp.length;
                while (level > 0) {
                  String s = cp.subpath(level).toString('/');
                  values.put(s, s);
                  --level;
                }
              }
              facetFields.addFields(doc, cats);
              iw.addDocument(doc);
            } catch (IOException e) {
              throw new RuntimeException(e);
            }
          }
View Full Code Here

Examples of org.apache.lucene.facet.index.FacetFields

    // main index:
    taxoWriter = new DirectoryTaxonomyWriter(taxoDir, IndexWriterConfig.OpenMode.CREATE);

    // Reused across documents, to add the necessary facet
    // fields:
    facetFields = new FacetFields(taxoWriter);

    add("Author/Bob", "Publish Date/2010/10/15");
    add("Author/Lisa", "Publish Date/2010/10/20");
    add("Author/Lisa", "Publish Date/2012/1/1");
    add("Author/Susan", "Publish Date/2012/1/7");
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.