Esempio n. 1
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(FacetHandler facetHandler)
 {
     List<string> dependsOn = facetHandler.DependsOn;
     BoboIndexReader indexReader = GetIndexReader();
     if (dependsOn.Count > 0)
     {
         List<string>.Enumerator iter = dependsOn.GetEnumerator();
         while (iter.MoveNext())
         {
             string fn = iter.Current;
             FacetHandler f = null;
             if (runtimeFacetHandlerMap.ContainsKey(fn))
             {
                 f = runtimeFacetHandlerMap[fn];
             }
             if (f == null)
             {
                 f = indexReader.GetFacetHandler(fn);
             }
             if (f == null)
             {
                 throw new System.IO.IOException("depended on facet handler: " + fn + ", but is not found");
             }
             facetHandler.PutDependedFacetHandler(f);
         }
     }
     facetHandler.Load(indexReader);
     runtimeFacetHandlerMap.Add(facetHandler.Name, facetHandler);
 }
 /// <summary>
 /// Adds a list of depended facet handlers
 /// </summary>
 /// <param name="facetHandler"></param>
 public void PutDependedFacetHandler(FacetHandler facetHandler)
 {
     this._dependedFacetHandlers[facetHandler.Name] = facetHandler;
 }
Esempio n. 3
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";
            Console.WriteLine(string.Format("prefix:{0}", prefix));
            Console.WriteLine("=============================");

            var faceHandlers = new FacetHandler[] { new SimpleFacetHandler("name") };
            var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers));
            var factSpec = new FacetSpec() {Prefix=prefix, 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());
            }
        }
Esempio n. 4
0
        public void TestRangeFacetHandler()
        {            
            var query = new MatchAllDocsQuery();
            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));                       

            var testRangeFacetHandlers = new List<FacetHandler>();
            testRangeFacetHandlers.Add(new RangeFacetHandler("year", true));//auto range
            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));

            for (var i = 0; i < testRangeFacetHandlers.Count; i++)
            {
                var request = new BrowseRequest()
                {
                    Count = 100,
                    Offset = 0,
                    Query = query,
                    Sort = new 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 FacetHandler[] { 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("");
            }
        }
Esempio n. 5
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));
            }
        }