コード例 #1
1
 public override IFacetCountCollector GetFacetCountCollector(BrowseSelection sel, FacetSpec ospec)
 {
     return new CompactMultiValueFacetCountCollector(sel, _dataCache, Name, ospec);
 }
コード例 #2
0
        public void TestAutoComplete()
        {
            var query = new MatchAllDocsQuery();

            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
            var request = new BrowseRequest()
            {
                Count  = 10,
                Offset = 0,
                Query  = query
            };

            //var prefix = "java"; // NightOwl888: Prefix is no longer a feature
            //Console.WriteLine(string.Format("prefix:{0}", prefix));
            //Console.WriteLine("=============================");

            var faceHandlers = new IFacetHandler[] { new SimpleFacetHandler("name") };
            var browser      = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers));
            var factSpec     = new FacetSpec()
            {
                OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc
            };

            request.SetFacetSpec("name", factSpec);

            var result = browser.Browse(request);

            foreach (var facet in result.FacetMap["name"].GetFacets())
            {
                Console.WriteLine(facet.ToString());
            }
        }
コード例 #3
0
 public RunnerThread(AtomicLong timeCounter, int numIters, FacetSpec fspec, IEnumerable<IFacetAccessible> list1)
 {
     _timeCounter = timeCounter;
     _numIters = numIters;
     _fspec = fspec;
     _list1 = list1;
 }
コード例 #4
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);
        }
コード例 #5
0
 public RunnerThread(AtomicLong timeCounter, int numIters, FacetSpec fspec, IEnumerable <IFacetAccessible> list1)
 {
     _timeCounter = timeCounter;
     _numIters    = numIters;
     _fspec       = fspec;
     _list1       = list1;
 }
コード例 #6
0
 static IFacetAccessible BuildSubAccessible(string name, int segment, FacetSpec fspec)
 {
     SimpleFacetHandler.SimpleFacetCountCollector collector = new SimpleFacetHandler.SimpleFacetCountCollector(name, MakeFacetDataCache(),
                                                                                                               numDocsPerSeg * segment, null, fspec);
     collector.CollectAll();
     return(collector);
 }
コード例 #7
0
 public RunnerThread(AtomicInt64 timeCounter, int numIters, FacetSpec fspec, ICollection <IFacetAccessible> list1)
 {
     _timeCounter = timeCounter;
     _numIters    = numIters;
     _fspec       = fspec;
     _list1       = list1;
 }
コード例 #8
0
        static IFacetAccessible BuildSubAccessible(string name, int segment, FacetSpec fspec)
        {

            SimpleFacetHandler.SimpleFacetCountCollector collector = new SimpleFacetHandler.SimpleFacetCountCollector(name, MakeFacetDataCache(), numDocsPerSeg * segment, null, fspec);
            collector.CollectAll();
            return collector;
        }
コード例 #9
0
        public static void Main(string[] args)
        {
            int nThreads = 2;
            int numIters = 200;

            string fname1 = "facet1";
            //string fname2 = "facet2"; // NOT USED
            FacetSpec fspec = new FacetSpec();

            fspec.ExpandSelection = (true);
            fspec.MaxCount        = (50);
            fspec.MinHitCount     = (1);
            fspec.OrderBy         = FacetSpec.FacetSortSpec.OrderHitsDesc;

            List <IFacetAccessible> list1 = new List <IFacetAccessible>(numSegs);

            for (int i = 0; i < numSegs; ++i)
            {
                list1.Add(BuildSubAccessible(fname1, i, fspec));
            }

            //List<FacetAccessible> list2 = new List<FacetAccessible>(numSegs);
            //for (int i = 0; i < numSegs; ++i)
            //{
            //    list2.add(BuildSubAccessible(fname2, i, fspec));
            //}

            AtomicLong timeCounter = new AtomicLong();

            Thread[]       threads      = new Thread[nThreads];
            RunnerThread[] threadStates = new RunnerThread[nThreads];
            for (int i = 0; i < threads.Length; ++i)
            {
                var threadState = new RunnerThread(timeCounter, numIters, fspec, list1);
                threadStates[i] = threadState;
                threads[i]      = new Thread(new ThreadStart(threadState.Run));
            }


            //		System.out.println("press key to start load test... ");
            //		{
            //			BufferedReader br = new BufferedReader(new InputStreamReader(
            //					System.in));
            //			int ch = br.read();
            //			char c = (char) ch;
            //		}
            foreach (Thread t in threads)
            {
                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

            Console.WriteLine("average time: " + timeCounter.Get() / numIters / nThreads + " ms");
        }
コード例 #10
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());
                    }
                }
            }
        }
コード例 #11
0
        public void TestPriceRangeWithFloatAndSelection()
        {
            // Field.
            string field = "pricefloat";

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

                    // Selection.
                    BrowseSelection sel = new BrowseSelection(field);
                    sel.AddValue("[000000.000 TO 000999.220]");
                    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(7, totalHits);
                        Assert.AreEqual(1, facetVals.Count);
                        Assert.AreEqual("[000000.000 TO 000999.220](7)", facetVals[0].ToString());
                    }
                }
            }
        }
コード例 #12
0
        private FacetSpec.FacetSortSpec ParseFacetSort(string facetSortString, FacetSpec.FacetSortSpec defaultSort)
        {
            FacetSpec.FacetSortSpec defaultFacetSortSpec;

            if ("count".Equals(facetSortString))
            {
                defaultFacetSortSpec = FacetSpec.FacetSortSpec.OrderHitsDesc;
            }
            else if ("index".Equals(facetSortString))
            {
                defaultFacetSortSpec = FacetSpec.FacetSortSpec.OrderValueAsc;
            }
            else
            {
                defaultFacetSortSpec = defaultSort;
            }
            return defaultFacetSortSpec;
        }
コード例 #13
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("");
            }
        }
コード例 #14
0
        private static void DoBrowse(BoboBrowser browser)
        {
            String q = "java";
            QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_CURRENT, "b", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_CURRENT));
            Query query = parser.Parse(q);
            BrowseRequest br = new BrowseRequest();
            //br.setQuery(query);
            br.Offset = 0;
            br.Count = 0;

            BrowseSelection geoSel = new BrowseSelection("geo_region");
            geoSel.AddValue("5227");
            BrowseSelection industrySel = new BrowseSelection("industry_norm");
            industrySel.AddValue("1");

            //br.AddSelection(geoSel);
            br.AddSelection(industrySel);

            FacetSpec regionSpec = new FacetSpec();
            regionSpec.ExpandSelection = true;
            regionSpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;
            regionSpec.MaxCount = 5;

            FacetSpec industrySpec=new FacetSpec();
            industrySpec.ExpandSelection = true;
            industrySpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;
            industrySpec.MaxCount = 5;
        

            FacetSpec numEndorserSpec=new FacetSpec();
            numEndorserSpec.ExpandSelection = true;
    
		    br.SetFacetSpec("industry_norm", industrySpec);
            br.SetFacetSpec("geo_region", regionSpec);
            br.SetFacetSpec("num_endorsers_norm", numEndorserSpec);

		    long start = System.Environment.TickCount;
		    BrowseResult res = browser.Browse(br);
		    long end = System.Environment.TickCount;

            Console.WriteLine("result: " + res);
            Console.WriteLine("took: " + (end-start));
        }
コード例 #15
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));
            }
        }
コード例 #16
0
        public void TestMultiValPath()
        {
            DirectoryReader reader     = DirectoryReader.Open(directory);
            BoboMultiReader boboReader = BoboMultiReader.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);
            ICollection <BrowseFacet> facets = fa.GetFacets();

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

            Assert.AreEqual(2, facet.FacetValueHitCount);
        }
コード例 #17
0
 public override IFacetCountCollector GetFacetCountCollector(BrowseSelection sel, FacetSpec fspec)
 {
     return null;
 }
コード例 #18
0
ファイル: BasicTests.cs プロジェクト: yao-yi/BoboBrowse.Net
        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));
            }
        }
コード例 #19
0
ファイル: BasicTests.cs プロジェクト: yao-yi/BoboBrowse.Net
        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("");
            }
        }
コード例 #20
0
ファイル: BasicTests.cs プロジェクト: yao-yi/BoboBrowse.Net
        public void TestAutoComplete()
        {
            var query = new MatchAllDocsQuery();
            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
            var request = new BrowseRequest()
            {
                Count = 10,
                Offset = 0,
                Query = query
            };

            //var prefix = "java"; // NightOwl888: Prefix is no longer a feature
            //Console.WriteLine(string.Format("prefix:{0}", prefix));
            //Console.WriteLine("=============================");

            var faceHandlers = new IFacetHandler[] { new SimpleFacetHandler("name") };
            var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers));
            var factSpec = new FacetSpec() { OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc };
            request.SetFacetSpec("name", factSpec);

            var result = browser.Browse(request);

            foreach (var facet in result.FacetMap["name"].GetFacets())
            {
                Console.WriteLine(facet.ToString());
            }
        }
コード例 #21
0
 internal CompactMultiValueFacetCountCollector(BrowseSelection sel, FacetDataCache dataCache, string name, FacetSpec ospec)
     : base(sel, dataCache, name, ospec)
 {
     _array = _dataCache.orderArray;
 }
コード例 #22
0
 /// <summary>
 /// Sets a <see cref="T:FacetSpec"/> and its related field name.
 /// <see cref="T:FacetSpec"/> specifies how facets are to be returned on the <see cref="T:BrowseResult"/>.
 /// </summary>
 /// <param name="name">field name</param>
 /// <param name="facetSpec">Facet spec</param>
 public virtual void SetFacetSpec(string name, FacetSpec facetSpec)
 {
     FacetSpecs.Add(name, facetSpec);
 }
コード例 #23
0
        public BrowseRequest ConvertBrowseRequest(BoboRequest boboRequest)
        {
            Query query = this.queryBuilder.ParseQuery(boboRequest.Query, boboRequest.Df);
            Sort sort = this.queryBuilder.ParseSort(boboRequest.Sort);

            var browseRequest = new BrowseRequest();
            browseRequest.Offset = boboRequest.Start;
            browseRequest.Count = boboRequest.Rows;
            browseRequest.Query = query;

            if (sort != null)
            {
                SortField[] sortFields = sort.GetSort();
                if (sortFields != null && sortFields.Length > 0)
                {
                    browseRequest.Sort = sortFields;
                }
            }

            var selMap = new Dictionary<string, BrowseSelection>();
            foreach (var selection in boboRequest.Selections)
            {
                BrowseSelection sel = selMap.ContainsKey(selection.Name) ? selMap[selection.Name] : null;
                if (sel == null)
                {
                    sel = new BrowseSelection(selection.Name);
                    selMap.Add(selection.Name, sel);
                }
                foreach (var val in selection.Values)
                {
                    sel.AddValue(val);
                }

                sel.SelectionOperation = selection.SelectionOperation;

                sel.SetSelectionProperty("depth", selection.Depth.ToString());
                sel.SetSelectionProperty("strict", selection.Strict.ToString().ToLower());
            }
            if (selMap.Count > 0)
            {
                var sels = selMap.Values;
                foreach (var sel in sels)
                {
                    browseRequest.AddSelection(sel);
                }
            }

            if (boboRequest.Facet == true)
            {
                foreach (var facet in boboRequest.Facets)
                {
                    FacetSpec fspec = new FacetSpec();
                    browseRequest.SetFacetSpec(facet.Name, fspec);

                    fspec.MinHitCount = facet.MinCount == int.MinValue ? 0 : facet.MinCount;
                    fspec.MaxCount = facet.Limit == int.MinValue ? 100 : facet.Limit;
                    fspec.ExpandSelection = facet.Expand;
                    fspec.OrderBy = ParseFacetSort(facet.Sort, FacetSpec.FacetSortSpec.OrderHitsDesc);
                }
            }

            return browseRequest;
        }
コード例 #24
0
        public virtual void Browse(
            BrowseRequest req,
            Weight weight,
            Collector collector,
            IDictionary <string, IFacetAccessible> facetMap,
            int start)
        {
            if (_reader == null)
            {
                return;
            }


            //      initialize all RuntimeFacetHandlers with data supplied by user at run-time.
            _runtimeFacetHandlers = new List <IRuntimeFacetHandler>(_runtimeFacetHandlerFactoryMap.Count());

            IEnumerable <string> runtimeFacetNames = _runtimeFacetHandlerFactoryMap.Keys;

            foreach (string facetName in runtimeFacetNames)
            {
                var sfacetHandler = this.GetFacetHandler(facetName);
                if (sfacetHandler != null)
                {
                    logger.Warn("attempting to reset facetHandler: " + sfacetHandler);
                    continue;
                }
                IRuntimeFacetHandlerFactory factory = (IRuntimeFacetHandlerFactory)_runtimeFacetHandlerFactoryMap.Get(facetName);

                try
                {
                    FacetHandlerInitializerParam data = req.GetFacetHandlerData(facetName);
                    if (data == null)
                    {
                        data = FacetHandlerInitializerParam.EMPTY_PARAM;
                    }
                    if (data != FacetHandlerInitializerParam.EMPTY_PARAM || !factory.IsLoadLazily)
                    {
                        IRuntimeFacetHandler facetHandler = factory.Get(data);
                        if (facetHandler != null)
                        {
                            _runtimeFacetHandlers.Add(facetHandler); // add to a list so we close them after search
                            this.SetFacetHandler(facetHandler);
                        }
                    }
                }
                catch (Exception e)
                {
                    throw new BrowseException("error trying to set FacetHandler : " + facetName + ":" + e.Message, e);
                }
            }
            // done initialize all RuntimeFacetHandlers with data supplied by user at run-time.

            IEnumerable <string> fields = FacetNames;

            List <Filter>            preFilterList         = new List <Filter>();
            List <FacetHitCollector> facetHitCollectorList = new List <FacetHitCollector>();

            Filter baseFilter = req.Filter;

            if (baseFilter != null)
            {
                preFilterList.Add(baseFilter);
            }

            int  selCount          = req.SelectionCount;
            bool isNoQueryNoFilter = IsNoQueryNoFilter(req);

            bool isDefaultSearch = isNoQueryNoFilter && selCount == 0;

            try
            {
                foreach (string name in fields)
                {
                    BrowseSelection sel   = req.GetSelection(name);
                    FacetSpec       ospec = req.GetFacetSpec(name);

                    var handler = GetFacetHandler(name);

                    if (handler == null)
                    {
                        logger.Error("facet handler: " + name + " is not defined, ignored.");
                        continue;
                    }

                    FacetHitCollector facetHitCollector = null;

                    RandomAccessFilter filter = null;
                    if (sel != null)
                    {
                        filter = handler.BuildFilter(sel);
                    }

                    if (ospec == null)
                    {
                        if (filter != null)
                        {
                            preFilterList.Add(filter);
                        }
                    }
                    else
                    {
                        /*FacetSpec fspec = new FacetSpec(); // OrderValueAsc,
                        *  fspec.setMaxCount(0);
                        *  fspec.setMinHitCount(1);
                        *
                        *  fspec.setExpandSelection(ospec.isExpandSelection());*/
                        FacetSpec fspec = ospec;

                        facetHitCollector = new FacetHitCollector();
                        facetHitCollector.facetHandler = handler;

                        if (isDefaultSearch)
                        {
                            facetHitCollector._collectAllSource = handler.GetFacetCountCollectorSource(sel, fspec);
                        }
                        else
                        {
                            facetHitCollector._facetCountCollectorSource = handler.GetFacetCountCollectorSource(sel, fspec);
                            if (ospec.ExpandSelection)
                            {
                                if (isNoQueryNoFilter && sel != null && selCount == 1)
                                {
                                    facetHitCollector._collectAllSource = handler.GetFacetCountCollectorSource(sel, fspec);
                                    if (filter != null)
                                    {
                                        preFilterList.Add(filter);
                                    }
                                }
                                else
                                {
                                    if (filter != null)
                                    {
                                        facetHitCollector._filter = filter;
                                    }
                                }
                            }
                            else
                            {
                                if (filter != null)
                                {
                                    preFilterList.Add(filter);
                                }
                            }
                        }
                    }
                    if (facetHitCollector != null)
                    {
                        facetHitCollectorList.Add(facetHitCollector);
                    }
                }

                Filter finalFilter = null;
                if (preFilterList.Count > 0)
                {
                    if (preFilterList.Count == 1)
                    {
                        finalFilter = preFilterList.First();
                    }
                    else
                    {
                        finalFilter = new AndFilter(preFilterList);
                    }
                }

                this.FacetHitCollectorList = facetHitCollectorList;

                try
                {
                    if (weight == null)
                    {
                        var q = req.Query;
                        if (q == null)
                        {
                            q = new MatchAllDocsQuery();
                        }
                        weight = CreateWeight(q);
                    }
                    Search(weight, finalFilter, collector, start, req.MapReduceWrapper);
                }
                finally
                {
                    foreach (FacetHitCollector facetCollector in facetHitCollectorList)
                    {
                        string name = facetCollector.facetHandler.Name;
                        List <IFacetCountCollector> resultcollector = null;
                        resultcollector = facetCollector._countCollectorList;
                        if (resultcollector == null || resultcollector.Count == 0)
                        {
                            resultcollector = facetCollector._collectAllCollectorList;
                        }
                        if (resultcollector != null)
                        {
                            FacetSpec fspec = req.GetFacetSpec(name);
                            Debug.Assert(fspec != null);
                            if (resultcollector.Count == 1)
                            {
                                facetMap.Put(name, resultcollector[0]);
                            }
                            else
                            {
                                List <IFacetAccessible> finalList = new List <IFacetAccessible>(resultcollector.Count);
                                foreach (IFacetCountCollector fc in resultcollector)
                                {
                                    finalList.Add((IFacetAccessible)fc);
                                }
                                CombinedFacetAccessible combinedCollector = new CombinedFacetAccessible(fspec, finalList);
                                facetMap.Put(name, combinedCollector);
                            }
                        }
                    }
                }
            }
            catch (Exception ioe)
            {
                throw new BrowseException(ioe.Message, ioe);
            }
        }
コード例 #25
0
		public override IFacetCountCollector GetFacetCountCollector(BrowseSelection sel, FacetSpec fspec)
		{
			return new RangeFacetCountCollector(Name, _innerHandler.GetDataCache(), fspec, _predefinedRanges, false);
		}
コード例 #26
0
        public void TestFacetNameForSimpleFacetHandler()
        {
            BrowseRequest br = new BrowseRequest();
            br.Count = 20;
            br.Offset = 0;

            BrowseSelection colorSel = new BrowseSelection("mycolor");
            colorSel.AddValue("yellow");
            br.AddSelection(colorSel);

            BrowseSelection makeSel = new BrowseSelection("make");
            makeSel.AddValue("rav4");
            br.AddSelection(makeSel);

            FacetSpec spec = new FacetSpec();
            spec.ExpandSelection = true;
            spec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;
            spec.MaxCount = 15;

            br.SetFacetSpec("mycolor", spec);
            br.SetFacetSpec("id", spec);
            br.SetFacetSpec("make", spec);

            int expectedHitNum = 3;

            Directory ramIndexDir = CreateIndex();
            using (IndexReader srcReader = IndexReader.Open(ramIndexDir, true))
            {
                using (BoboIndexReader boboReader = BoboIndexReader.GetInstance(srcReader, _facetHandlers, null))
                {
                    using (BoboBrowser boboBrowser = new BoboBrowser(boboReader))
                    {
                        using (BrowseResult result = boboBrowser.Browse(br))
                        {

                            Assert.AreEqual(expectedHitNum, result.NumHits);
                        }
                    }
                }
            }
        }
コード例 #27
0
 public override IFacetCountCollector GetFacetCountCollector(BrowseSelection sel, FacetSpec fspec)
 {
     var list = BuildAllRangeStrings();
     return new DynamicRangeFacetCountCollector(this, Name, dataFacetHandler, fspec, list);
 }
コード例 #28
0
 internal DynamicRangeFacetCountCollector(DynamicRangeFacetHandler parent, string name, RangeFacetHandler handler, FacetSpec fspec, IEnumerable<string> predefinedList)
     : base(name, handler, fspec, predefinedList, false)
 {
     this.parent = parent;
 }
コード例 #29
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());
                    }
                }
            }
        }
コード例 #30
0
        public void TestFacetNameForSimpleFacetHandler()
        {
            BrowseRequest br = new BrowseRequest();
            br.Count = 20;
            br.Offset = 0;

            BrowseSelection colorSel = new BrowseSelection("mycolor");
            colorSel.AddValue("yellow");
            br.AddSelection(colorSel);

            BrowseSelection makeSel = new BrowseSelection("make");
            makeSel.AddValue("rav4");
            br.AddSelection(makeSel);

            FacetSpec spec = new FacetSpec();
            spec.ExpandSelection = true;
            spec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;
            spec.MaxCount = 15;

            br.SetFacetSpec("mycolor", spec);
            br.SetFacetSpec("id", spec);
            br.SetFacetSpec("make", spec);

            BrowseResult result = null;
            BoboBrowser boboBrowser = null;
            int expectedHitNum = 3;
            try
            {
                Directory ramIndexDir = CreateIndex();
                IndexReader srcReader = IndexReader.Open(ramIndexDir, true);
                boboBrowser = new BoboBrowser(BoboIndexReader.GetInstance(srcReader, _facetHandlers, null));
                result = boboBrowser.Browse(br);

                Assert.AreEqual(expectedHitNum, result.NumHits);
            }
            catch (BrowseException e)
            {
                Assert.Fail(e.Message);
            }
            catch (System.IO.IOException ioe)
            {
                Assert.Fail(ioe.Message);
            }
            finally
            {
                if (boboBrowser != null)
                {
                    try
                    {
                        boboBrowser.Close();
                    }
                    catch (System.IO.IOException e)
                    {
                        Assert.Fail(e.Message);
                    }
                }
            }
        }
コード例 #31
0
        public static void Main(string[] args)
        {
            int nThreads = 2;
            int numIters = 200;

            string fname1 = "facet1";
            //string fname2 = "facet2"; // NOT USED
            FacetSpec fspec = new FacetSpec();
            fspec.ExpandSelection = (true);
            fspec.MaxCount = (50);
            fspec.MinHitCount = (1);
            fspec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;

            List<IFacetAccessible> list1 = new List<IFacetAccessible>(numSegs);
            for (int i = 0; i < numSegs; ++i)
            {
                list1.Add(BuildSubAccessible(fname1, i, fspec));
            }

            //List<FacetAccessible> list2 = new List<FacetAccessible>(numSegs);
            //for (int i = 0; i < numSegs; ++i)
            //{
            //    list2.add(BuildSubAccessible(fname2, i, fspec));
            //}		
            
            AtomicLong timeCounter = new AtomicLong();
            Thread[] threads = new Thread[nThreads];
            RunnerThread[] threadStates = new RunnerThread[nThreads];
            for (int i = 0; i < threads.Length; ++i)
            {
                var threadState = new RunnerThread(timeCounter, numIters, fspec, list1);
                threadStates[i] = threadState;
                threads[i] = new Thread(new ThreadStart(threadState.Run));
            }


            //		System.out.println("press key to start load test... ");
            //		{
            //			BufferedReader br = new BufferedReader(new InputStreamReader(
            //					System.in));
            //			int ch = br.read();
            //			char c = (char) ch;
            //		}
            foreach (Thread t in threads)
            {
                t.Start();
            }

            foreach (Thread t in threads)
            {
                t.Join();
            }

            Console.WriteLine("average time: " + timeCounter.Get() / numIters / nThreads + " ms");
        }
コード例 #32
0
 /// <summary>
 /// Sets a <see cref="T:FacetSpec"/> and its related field name.
 /// <see cref="T:FacetSpec"/> specifies how facets are to be returned on the <see cref="T:BrowseResult"/>.
 /// </summary>
 /// <param name="name">field name</param>
 /// <param name="facetSpec">Facet spec</param>
 public virtual void SetFacetSpec(string name, FacetSpec facetSpec)
 {
     FacetSpecs.Add(name, facetSpec);
 }
コード例 #33
0
        public void TestMultiValueFacetHandler()
        {
            var query = new MatchAllDocsQuery();
            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
            var request = new BrowseRequest()
            {
                Count = 100,
                Offset = 0,
                Query = query,
                Sort = new Sort(new SortField("path", SortField.STRING, false)).GetSort()
            };

            var faceHandlers = new FacetHandler[] { new MultiValueFacetHandler("path") };
            var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers));
            var factSpec = new FacetSpec() { OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc };
            request.SetFacetSpec("path", factSpec);

            var result = browser.Browse(request);
            Console.WriteLine(string.Format("total hits:{0}", result.NumHits));
            Console.WriteLine("===========================");
            foreach (var facet in result.FacetMap["path"].GetFacets())
            {
                Console.WriteLine(facet.ToString());               
            }
            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));
            }
        }