/// <summary>
        /// Constructor
        /// </summary>
        /// <param name="reader">Index reader</param>
        /// <param name="facetHandlers">List of facet handlers</param>
        /// <param name="facetHandlerFactories">List of factories to create facet handler instances at runtime.</param>
        /// <param name="workArea">A service locator that can be used to inject custom objects.</param>
        /// <param name="autoClose">True to close the underlying IndexReader when this instance is closed.</param>
        /// <returns>A new BoboIndexReader instance.</returns>
        public static BoboIndexReader GetInstance(IndexReader reader, IEnumerable <IFacetHandler> facetHandlers, IEnumerable <IRuntimeFacetHandlerFactory> facetHandlerFactories, WorkArea workArea, bool autoClose)
        {
            BoboIndexReader boboReader = new BoboIndexReader(reader, facetHandlers, facetHandlerFactories, workArea, autoClose);

            boboReader.FacetInit();
            return(boboReader);
        }
 public BoboSubBrowser(BoboIndexReader reader)
     : base(reader)
 {
     _reader = reader;
     _runtimeFacetHandlerMap        = new Dictionary <string, IFacetHandler>();
     _runtimeFacetHandlerFactoryMap = reader.RuntimeFacetHandlerFactoryMap;
     _allFacetHandlerMap            = null;
 }
Beispiel #3
0
        public void TestNumberRangeWithInt()
        {
            // Field.
            string field = "number";

            // Lucene index.
            using (IndexReader reader = IndexReader.Open(this._indexDir, true))
            {
                // Bobo reader.
                using (BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader, this._facetHandlers))
                {
                    // Request.
                    BrowseRequest browseRequest = new BrowseRequest();
                    browseRequest.Count             = 10;
                    browseRequest.Offset            = 0;
                    browseRequest.FetchStoredFields = true;

                    // Selection.
                    BrowseSelection sel = new BrowseSelection(field);
                    browseRequest.AddSelection(sel);

                    // Query.
                    MatchAllDocsQuery query = new MatchAllDocsQuery();

                    // Output.
                    FacetSpec spec = new FacetSpec();
                    spec.OrderBy  = FacetSpec.FacetSortSpec.OrderValueAsc;
                    spec.MaxCount = 10;
                    browseRequest.SetFacetSpec(field, spec);

                    // Browse.
                    IBrowsable browser = new BoboBrowser(boboReader);
                    using (BrowseResult result = browser.Browse(browseRequest))
                    {
                        // Results.
                        int         totalHits = result.NumHits;
                        BrowseHit[] hits      = result.Hits;
                        IDictionary <String, IFacetAccessible> facetMap = result.FacetMap;
                        IFacetAccessible   facets    = facetMap[field];
                        List <BrowseFacet> facetVals = facets.GetFacets().ToList();

                        // Check.
                        Assert.AreEqual(10, totalHits);
                        Assert.AreEqual(5, facetVals.Count());
                        Assert.AreEqual("[0000000000 TO 0000001000](3)", facetVals[0].ToString());
                        Assert.AreEqual("[0000001000 TO 0000010000](3)", facetVals[1].ToString());
                        Assert.AreEqual("[0000010000 TO 0000100000](2)", facetVals[2].ToString());
                        Assert.AreEqual("[0000100000 TO 0001000000](3)", facetVals[3].ToString());
                        Assert.AreEqual("[0001000000 TO *](3)", facetVals[4].ToString());
                    }
                }
            }
        }
Beispiel #4
0
 public static void GatherSubReaders(IList <BoboIndexReader> readerList, BoboIndexReader reader)
 {
     BoboIndexReader[] subReaders = reader.SubReaders;
     if (subReaders == null)
     {
         readerList.Add(reader);
     }
     else
     {
         for (int i = 0; i < subReaders.Length; i++)
         {
             GatherSubReaders(readerList, subReaders[i]);
         }
     }
 }
        public virtual BoboIndexReader Copy(IndexReader index)
        {
            if (_subReaders != null)
            {
                throw new InvalidOperationException("this BoboIndexReader has subreaders");
            }
            BoboIndexReader copy = new BoboIndexReader(index);

            copy._facetHandlerMap = this._facetHandlerMap;
            copy._facetHandlers   = this._facetHandlers;
            copy._runtimeFacetHandlerFactories  = this._runtimeFacetHandlerFactories;
            copy._runtimeFacetHandlerFactoryMap = this._runtimeFacetHandlerFactoryMap;
            copy._workArea = this._workArea;
            copy._facetDataMap.PutAll(this._facetDataMap);
            copy._srcReader = index;
            copy._starts    = this._starts;
            return(copy);
        }
Beispiel #6
0
        public void TestRangeFacetHandler()
        {
            var query = new MatchAllDocsQuery();

            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));

            var testRangeFacetHandlers = new List <IFacetHandler>();

            //testRangeFacetHandlers.Add(new RangeFacetHandler("year", true));//auto range // NightOwl888 - Auto range is no longer a feature.
            testRangeFacetHandlers.Add(new RangeFacetHandler("year", new List <string>(new string[] { "[* TO 2000]", "[2000 TO 2005]", "[2006 TO 2010]", "[2011 TO *]" })));
            //testRangeFacetHandlers.Add(new RangeFacetHandler("price", "price", new NumberFieldFactory(), true)); // NightOwl888 - Auto range is no longer a feature.

            for (var i = 0; i < testRangeFacetHandlers.Count; i++)
            {
                var request = new BrowseRequest()
                {
                    Count  = 100,
                    Offset = 0,
                    Query  = query,
                    Sort   = new Lucene.Net.Search.Sort(new SortField("price", SortField.DOUBLE, false)).GetSort()
                };

                var sectionFilter = new BrowseSelection("category");
                sectionFilter.NotValues          = new string[] { "5" };
                sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd;
                request.AddSelection(sectionFilter);

                var faceHandler  = testRangeFacetHandlers[i];
                var faceHandlers = new IFacetHandler[] { faceHandler, new SimpleFacetHandler("category") };
                var browser      = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers));
                var factSpec     = new FacetSpec()
                {
                    OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc
                };
                request.SetFacetSpec(faceHandler.Name, factSpec);
                var result = browser.Browse(request);
                Console.WriteLine(string.Format("total hits:{0}", result.NumHits));
                foreach (var facet in result.FacetMap[faceHandler.Name].GetFacets())
                {
                    Console.WriteLine(facet.ToString());
                }
                Console.WriteLine("");
            }
        }
Beispiel #7
0
        public void TestSimpleBrowser()
        {
            var query = new TermQuery(new Term("name", "asp.net"));

            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
            var request = new BrowseRequest()
            {
                Count  = 10,
                Offset = 0,
                Query  = query,
                Sort   = new Lucene.Net.Search.Sort(new SortField("price", SortField.DOUBLE, false)).GetSort()
            };

            var facetHandlers = new IFacetHandler[] { new SimpleFacetHandler("category") };
            var browser       = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), facetHandlers));
            var facetSpec     = new FacetSpec()
            {
                OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc, MinHitCount = 1
            };

            request.SetFacetSpec("category", facetSpec);

            var result = browser.Browse(request);

            Console.WriteLine(string.Format("total hits:{0}", result.NumHits));
            Console.WriteLine("===========================");
            foreach (var facet in result.FacetMap["category"].GetFacets())
            {
                var category = _categories.First(k => k.Value == int.Parse(facet.Value.ToString()));
                Console.WriteLine("{0}:({1})", category.Key, facet.FacetValueHitCount);
            }
            Console.WriteLine("===========================");
            for (var i = 0; i < result.Hits.Length; i++)
            {
                var doc      = browser.Doc(result.Hits[i].DocId);
                var category = _categories.First(k => k.Value == int.Parse(doc.GetField("category").StringValue)).Key;
                Console.WriteLine(string.Format("{2} - {0} ${1} by {3}", doc.GetField("name").StringValue, doc.GetField("price").StringValue, category, doc.GetField("author").StringValue));
            }
        }
        public override Document Document(int docid)
        {
            if (_subReaders != null)
            {
                int             readerIndex = ReaderIndex(docid, _starts, _subReaders.Length);
                BoboIndexReader subReader   = _subReaders[readerIndex];
                return(subReader.Document(docid - _starts[readerIndex]));
            }
            else
            {
                Document doc           = base.Document(docid);
                var      facetHandlers = _facetHandlerMap.Values;
                foreach (var facetHandler in facetHandlers)
                {
                    string[] vals = facetHandler.GetFieldValues(this, docid);
                    if (vals != null)
                    {
                        string[] values     = doc.GetValues(facetHandler.Name);
                        var      storedVals = new HashSet <string>(values);

                        foreach (string val in vals)
                        {
                            storedVals.Add(val);
                        }
                        doc.RemoveField(facetHandler.Name);

                        foreach (var val in storedVals)
                        {
                            doc.Add(new Field(facetHandler.Name,
                                              val,
                                              Field.Store.NO,
                                              Field.Index.NOT_ANALYZED));
                        }
                    }
                }
                return(doc);
            }
        }
        /// <summary>
        /// Find all the leaf sub-readers and wrap each in BoboIndexReader.
        /// </summary>
        /// <param name="reader">reader</param>
        /// <param name="workArea">workArea</param>
        /// <returns></returns>
        private static IndexReader[] CreateSubReaders(IndexReader reader, WorkArea workArea)
        {
            List <IndexReader> readerList = new List <IndexReader>();

            ReaderUtil.GatherSubReaders(readerList, reader);
            IndexReader[]     subReaders = (IndexReader[])readerList.ToArray();
            BoboIndexReader[] boboReaders;
            var subReaderCount = subReaders.Count();

            if (subReaders != null && subReaderCount > 0)
            {
                boboReaders = new BoboIndexReader[subReaderCount];
                for (int i = 0; i < subReaderCount; i++)
                {
                    boboReaders[i] = new BoboIndexReader(subReaders[i], null, null, workArea, true, false);
                }
            }
            else
            {
                boboReaders = new BoboIndexReader[] { new BoboIndexReader(reader, null, null, workArea, true, false) };
            }
            return(boboReaders);
        }
Beispiel #10
0
        public void TestMultiValPath()
        {
            IndexReader     reader     = IndexReader.Open(directory, true);
            BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader, facetHandlers);

            BoboBrowser   browser = new BoboBrowser(boboReader);
            BrowseRequest req     = new BrowseRequest();

            BrowseSelection sel = new BrowseSelection(PathHandlerName);

            sel.AddValue("/a");
            var propMap = new Dictionary <String, String>();

            propMap.Put(PathFacetHandler.SEL_PROP_NAME_DEPTH, "0");
            propMap.Put(PathFacetHandler.SEL_PROP_NAME_STRICT, "false");
            sel.SetSelectionProperties(propMap);

            req.AddSelection(sel);

            FacetSpec fs = new FacetSpec();

            fs.MinHitCount = (1);
            req.SetFacetSpec(PathHandlerName, fs);

            BrowseResult res = browser.Browse(req);

            Assert.AreEqual(res.NumHits, 1);
            IFacetAccessible          fa     = res.GetFacetAccessor(PathHandlerName);
            IEnumerable <BrowseFacet> facets = fa.GetFacets();

            Console.WriteLine(facets);
            Assert.AreEqual(1, facets.Count());
            BrowseFacet facet = facets.Get(0);

            Assert.AreEqual(2, facet.FacetValueHitCount);
        }
Beispiel #11
0
        /// <summary>
        /// Sets runtime facet handler. If has the same name as a preload handler, for the
        /// duration of this browser, this one will be used.
        /// </summary>
        /// <param name="facetHandler">Runtime facet handler</param>
        public virtual void SetFacetHandler(IFacetHandler facetHandler)
        {
            IEnumerable <string> dependsOn = facetHandler.DependsOn;
            BoboIndexReader      reader    = (BoboIndexReader)IndexReader;

            if (dependsOn.Count() > 0)
            {
                foreach (var fn in dependsOn)
                {
                    var f = _runtimeFacetHandlerMap.Get(fn);
                    if (f == null)
                    {
                        f = reader.GetFacetHandler(fn);
                    }
                    if (f == null)
                    {
                        throw new System.IO.IOException("depended on facet handler: " + fn + ", but is not found");
                    }
                    facetHandler.PutDependedFacetHandler(f);
                }
            }
            facetHandler.LoadFacetData(reader);
            _runtimeFacetHandlerMap.Put(facetHandler.Name, facetHandler);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reader">Index reader</param>
 /// <param name="facetHandlers">List of facet handlers</param>
 /// <param name="autoClose">True to close the underlying IndexReader when this instance is closed.</param>
 /// <returns>A new BoboIndexReader instance.</returns>
 public static BoboIndexReader GetInstance(IndexReader reader, IEnumerable <IFacetHandler> facetHandlers, bool autoClose)
 {
     return(BoboIndexReader.GetInstance(reader, facetHandlers, new IRuntimeFacetHandlerFactory[0], new WorkArea(), autoClose));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reader">Index reader</param>
 /// <returns>A new BoboIndexReader instance.</returns>
 public static BoboIndexReader GetInstance(IndexReader reader)
 {
     return(BoboIndexReader.GetInstance(reader, null, null, new WorkArea(), false));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reader">Index reader</param>
 /// <param name="autoClose">True to close the underlying IndexReader when this instance is closed.</param>
 /// <returns>A new BoboIndexReader instance.</returns>
 public static BoboIndexReader GetInstance(IndexReader reader, bool autoClose)
 {
     return(BoboIndexReader.GetInstance(reader, null, null, new WorkArea(), autoClose));
 }
Beispiel #15
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:BoboBrowser"/> class with the specified <see cref="T:BoboIndexReader"/> instance.
 /// </summary>
 /// <param name="reader">An open <see cref="T:BoboIndexReader"/> instance.</param>
 public BoboBrowser(BoboIndexReader reader)
     : base(CreateBrowsables(reader))
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reader">Index reader</param>
 /// <param name="workArea">A service locator that can be used to inject custom objects.</param>
 /// <returns>A new BoboIndexReader instance.</returns>
 public static BoboIndexReader GetInstance(IndexReader reader, WorkArea workArea)
 {
     return(BoboIndexReader.GetInstance(reader, null, null, workArea, false));
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="reader">Index reader</param>
 /// <param name="facetHandlers">List of facet handlers</param>
 /// <param name="facetHandlerFactories">List of factories to create facet handler instances at runtime.</param>
 /// <param name="workArea">A service locator that can be used to inject custom objects.</param>
 /// <returns>A new BoboIndexReader instance.</returns>
 public static BoboIndexReader GetInstance(IndexReader reader, IEnumerable <IFacetHandler> facetHandlers, IEnumerable <IRuntimeFacetHandlerFactory> facetHandlerFactories, WorkArea workArea)
 {
     return(BoboIndexReader.GetInstance(reader, facetHandlers, facetHandlerFactories, workArea, false));
 }