/// <summary>
 /// Aggreggates float facet values from the provided
 /// <see cref="ValueSource"/>, and pulls ordinals from the
 /// provided <see cref="OrdinalsReader"/>. 
 /// </summary>
 public TaxonomyFacetSumValueSource(OrdinalsReader ordinalsReader, TaxonomyReader taxoReader,
     FacetsConfig config, FacetsCollector fc, ValueSource valueSource)
     : base(ordinalsReader.IndexFieldName, taxoReader, config)
 {
     this.ordinalsReader = ordinalsReader;
     SumValues(fc.GetMatchingDocs(), fc.KeepScores, valueSource);
 }
 public static void AfterClass()
 {
     reader.Dispose();
     reader = null;
     dir.Dispose();
     dir = null;
     taxoReader.Dispose(true);
     taxoReader = null;
     taxoDir.Dispose();
     taxoDir = null;
 }
        public Searcher(string mainFolder, string taxonomyFolder, string thumbsFolder)
        {
            MaxResultCount = 50;
            mainSearchManager = new SearchManager(FSDirectory.open(new java.io.File(mainFolder)));
            taxonomyReader = new DirectoryTaxonomyReader(FSDirectory.open(new java.io.File(taxonomyFolder)));

            analyzer = FindAPhotoAnalyzers.ForSearching();
            parser = new MultiFieldQueryParser(FieldName.DefaultSearchFields, analyzer);
            parser.setAllowLeadingWildcard(true);

            thumbSearchManager = new SearchManager(FSDirectory.open(new java.io.File(thumbsFolder)));

            using (var wrapper = mainSearchManager.Wrapper())
            {
                indexPreferences = new IndexPreferences(wrapper.IndexSearcher);
            }
        }
        /// <summary>
        /// Recursively prints stats for all ordinals. </summary>
        public static void PrintStats(TaxonomyReader r, TextWriter @out, bool printTree)
        {
            @out.WriteLine(r.Count + " total categories.");

            ChildrenIterator it = r.GetChildren(TaxonomyReader.ROOT_ORDINAL);
            int child;
            while ((child = it.Next()) != TaxonomyReader.INVALID_ORDINAL)
            {
                ChildrenIterator chilrenIt = r.GetChildren(child);
                int numImmediateChildren = 0;
                while (chilrenIt.Next() != TaxonomyReader.INVALID_ORDINAL)
                {
                    numImmediateChildren++;
                }
                FacetLabel cp = r.GetPath(child);
                @out.WriteLine("/" + cp.Components[0] + ": " + numImmediateChildren + " immediate children; " + (1 + CountAllChildren(r, child)) + " total categories");
                if (printTree)
                {
                    PrintAllChildren(@out, r, child, "  ", 1);
                }
            }
        }
Exemple #5
0
        // clean old stuff, reopen
        public virtual void Reinit(bool eraseIndex)
        {
            // cleanup index
            IOUtils.Dispose(indexWriter, indexReader, directory);
            indexWriter = null;
            indexReader = null;

            IOUtils.Dispose(taxonomyWriter, taxonomyReader, taxonomyDir);
            taxonomyWriter = null;
            taxonomyReader = null;

            // directory (default is ram-dir).
            directory   = CreateDirectory(eraseIndex, "index", "directory");
            taxonomyDir = CreateDirectory(eraseIndex, "taxo", "taxonomy.directory");

            // inputs
            ResetInputs();

            // release unused stuff
            GC.Collect();

            // Re-init clock
            SetStartTimeMillis();
        }
        private void CheckWriterParent(TaxonomyReader tr, TaxonomyWriter tw)
        {
            // check that the parent of the root ordinal is the invalid ordinal:
            Assert.AreEqual(TaxonomyReader.INVALID_ORDINAL, tw.GetParent(0));

            // check parent of non-root ordinals:
            for (int ordinal = 1; ordinal < tr.Size; ordinal++)
            {
                FacetLabel me = tr.GetPath(ordinal);
                int parentOrdinal = tw.GetParent(ordinal);
                FacetLabel parent = tr.GetPath(parentOrdinal);
                if (parent == null)
                {
                    Fail("Parent of " + ordinal + " is " + parentOrdinal + ", but this is not a valid category.");
                }
                // verify that the parent is indeed my parent, according to the
                // strings
                if (!me.Subpath(me.Length - 1).Equals(parent))
                {
                    Fail("Got parent " + parentOrdinal + " for ordinal " + ordinal + " but categories are " + Showcat(parent) + " and " + Showcat(me) + " respectively.");
                }
            }

            // check parent of of invalid ordinals:
            try
            {
                tw.GetParent(-1);
                Fail("getParent for -1 should throw exception");
            }
            catch (System.IndexOutOfRangeException)
            {
                // ok
            }
            try
            {
                tw.GetParent(TaxonomyReader.INVALID_ORDINAL);
                Fail("getParent for INVALID_ORDINAL should throw exception");
            }
            catch (System.IndexOutOfRangeException)
            {
                // ok
            }
            try
            {
                int parent = tw.GetParent(tr.Size);
                Fail("getParent for getSize() should throw exception, but returned " + parent);
            }
            catch (System.IndexOutOfRangeException)
            {
                // ok
            }
        }
Exemple #7
0
 /// <summary>
 /// Create a new <see cref="DrillSideways"/> instance.
 /// </summary>
 public DrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader taxoReader)
     : this(searcher, config, taxoReader, null)
 {
 }
Exemple #8
0
 public virtual Facets GetTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector c)
 {
     return(GetTaxonomyFacetCounts(taxoReader, config, c, FacetsConfig.DEFAULT_INDEX_FIELD_NAME));
 }
 /// <summary>
 /// Create {@code TaxonomyFacetCounts}, which also
 ///  counts all facet labels.  Use this for a non-default
 ///  <seealso cref="OrdinalsReader"/>; otherwise use {@link
 ///  FastTaxonomyFacetCounts}. 
 /// </summary>
 public TaxonomyFacetCounts(OrdinalsReader ordinalsReader, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)
     : base(ordinalsReader.IndexFieldName, taxoReader, config)
 {
     this.ordinalsReader = ordinalsReader;
     Count(fc.GetMatchingDocs);
 }
Exemple #10
0
 /// <summary>
 /// Create a new {@code DrillSideways} instance, where some
 ///  dimensions were indexed with {@link
 ///  SortedSetDocValuesFacetField} and others were indexed
 ///  with <seealso cref="FacetField"/>. 
 /// </summary>
 public DrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader taxoReader, SortedSetDocValuesReaderState state)
 {
     this.searcher = searcher;
     this.config = config;
     this.taxoReader = taxoReader;
     this.state = state;
 }
Exemple #11
0
 /// <summary>
 /// Create a new {@code DrillSideways} instance. </summary>
 public DrillSideways(IndexSearcher searcher, FacetsConfig config, TaxonomyReader taxoReader)
     : this(searcher, config, taxoReader, null)
 {
 }
 /// <summary>
 /// Create <see cref="FastTaxonomyFacetCounts"/>, using the
 /// specified <paramref name="indexFieldName"/> for ordinals.  Use
 /// this if you had set <see cref="FacetsConfig.SetIndexFieldName"/>
 /// to change the index
 /// field name for certain dimensions. 
 /// </summary>
 public FastTaxonomyFacetCounts(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)
     : base(indexFieldName, taxoReader, config)
 {
     Count(fc.GetMatchingDocs());
 }
 /// <summary>
 /// Create <see cref="TaxonomyFacetSumIntAssociations"/> against
 /// the default index field. 
 /// </summary>
 public TaxonomyFacetSumIntAssociations(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)
     : this(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, taxoReader, config, fc)
 {
 }
Exemple #14
0
 public DrillSidewaysAnonymousInnerClassHelper(TestRangeFacetCounts outerInstance, IndexSearcher s, FacetsConfig config, TaxonomyReader tr)
     : base(s, config, tr)
 {
     this.outerInstance = outerInstance;
 }
 /// <summary>
 /// Aggreggates float facet values from the provided
 /// <see cref="ValueSource"/>, pulling ordinals using <see cref="DocValuesOrdinalsReader"/>
 /// against the default indexed
 /// facet field <see cref="FacetsConfig.DEFAULT_INDEX_FIELD_NAME"/>. 
 /// </summary>
 public TaxonomyFacetSumValueSource(TaxonomyReader taxoReader, FacetsConfig config,
     FacetsCollector fc, ValueSource valueSource)
     : this(new DocValuesOrdinalsReader(FacetsConfig.DEFAULT_INDEX_FIELD_NAME),
           taxoReader, config, fc, valueSource)
 {
 }
 private static int CountAllChildren(TaxonomyReader r, int ord)
 {
     int count = 0;
     ChildrenIterator it = r.GetChildren(ord);
     int child;
     while ((child = it.Next()) != TaxonomyReader.INVALID_ORDINAL)
     {
         count += 1 + CountAllChildren(r, child);
     }
     return count;
 }
 private static void PrintAllChildren(TextWriter @out, TaxonomyReader r, int ord, string indent, int depth)
 {
     ChildrenIterator it = r.GetChildren(ord);
     int child;
     while ((child = it.Next()) != TaxonomyReader.INVALID_ORDINAL)
     {
         @out.WriteLine(indent + "/" + r.GetPath(child).Components[depth]);
         PrintAllChildren(@out, r, child, indent + "  ", depth + 1);
     }
 }
 private static FacetsCollector PerformSearch(TaxonomyReader tr, IndexReader ir, IndexSearcher searcher)
 {
     FacetsCollector fc = new FacetsCollector();
     FacetsCollector.Search(searcher, new MatchAllDocsQuery(), 10, fc);
     return fc;
 }
        public static void BeforeClass()
        {
            dir = NewDirectory();
            taxoDir = NewDirectory();
            // preparations - index, taxonomy, content

            var taxoWriter = new DirectoryTaxonomyWriter(taxoDir);

            // Cannot mix ints & floats in the same indexed field:
            config = new FacetsConfig();
            config.SetIndexFieldName("int", "$facets.int");
            config.SetMultiValued("int", true);
            config.SetIndexFieldName("float", "$facets.float");
            config.SetMultiValued("float", true);

            var writer = new RandomIndexWriter(Random(), dir);

            // index documents, 50% have only 'b' and all have 'a'
            for (int i = 0; i < 110; i++)
            {
                Document doc = new Document();
                // every 11th document is added empty, this used to cause the association
                // aggregators to go into an infinite loop
                if (i % 11 != 0)
                {
                    doc.Add(new IntAssociationFacetField(2, "int", "a"));
                    doc.Add(new FloatAssociationFacetField(0.5f, "float", "a"));
                    if (i % 2 == 0) // 50
                    {
                        doc.Add(new IntAssociationFacetField(3, "int", "b"));
                        doc.Add(new FloatAssociationFacetField(0.2f, "float", "b"));
                    }
                }
                writer.AddDocument(config.Build(taxoWriter, doc));
            }

            taxoWriter.Dispose();
            reader = writer.Reader;
            writer.Dispose();
            taxoReader = new DirectoryTaxonomyReader(taxoDir);
        }
Exemple #20
0
 public DrillSidewaysAnonymousInnerClassHelper2(TestRangeFacetCounts outerInstance, IndexSearcher indexSearcher, FacetsConfig facetsConfig, TaxonomyReader org, ValueSource valueSource, DoubleRange[] doubleRanges, Filter filter)
     : base(indexSearcher, facetsConfig, org)
 {
     this.outerInstance   = outerInstance;
     this.vs              = valueSource;
     this.ranges          = doubleRanges;
     this.fastMatchFilter = filter;
 }
 /// <summary>
 /// Create <see cref="FastTaxonomyFacetCounts"/>, which also
 /// counts all facet labels. 
 /// </summary>
 public FastTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)
     : this(FacetsConfig.DEFAULT_INDEX_FIELD_NAME, taxoReader, config, fc)
 {
 }
 /// <summary>
 /// Sole constructor.
 /// </summary>
 protected internal FloatTaxonomyFacets(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config)
     : base(indexFieldName, taxoReader, config)
 {
     values = new float[taxoReader.Count];
 }
 /// <summary>
 /// Sole constructor. </summary>
 protected internal IntTaxonomyFacets(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config)
     : base(indexFieldName, taxoReader, config)
 {
     values = new int[taxoReader.Size];
 }
 /// <summary>
 /// Create <see cref="TaxonomyFacetSumIntAssociations"/> against
 /// the specified index field. 
 /// </summary>
 public TaxonomyFacetSumIntAssociations(string indexFieldName, TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector fc)
     : base(indexFieldName, taxoReader, config)
 {
     SumValues(fc.GetMatchingDocs());
 }
        /// <summary>
        /// Get the taxonomy facet caounts
        /// </summary>
        /// <param name="taxoReader">The taxonomy reader.</param>
        /// <param name="config">The facet configuration.</param>
        /// <param name="collector">The result collector.</param>
        /// <param name="indexFieldName">The index field name.</param>
        /// <returns>The facets.</returns>
        private Facets GetTaxonomyFacetCounts(TaxonomyReader taxoReader, FacetsConfig config, FacetsCollector collector, string indexFieldName)
        {
            Facets facets = new FastTaxonomyFacetCounts(indexFieldName, taxoReader, config, collector);

            return(facets);
        }