Exemple #1
0
        public void TestFacetSelectionFilter()
        {
            var query = new MatchAllDocsQuery();

            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
            var request = new BrowseRequest()
            {
                Count  = 10,
                Offset = 0,
                Query  = query
            };
            var authors       = new string[] { "kathy", "sierra" };//kathy&sierra
            var sectionFilter = new BrowseSelection("author");

            sectionFilter.Values             = authors;
            sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd;
            request.AddSelection(sectionFilter);

            var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), new IFacetHandler[] { new MultiValueFacetHandler("author") }));
            var result  = browser.Browse(request);

            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));
            }
        }
Exemple #2
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));
            }
        }
Exemple #3
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));
            }
        }
Exemple #4
0
        public void TestFacetSelectionFilter()
        {
            var query = new MatchAllDocsQuery();
            Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
            var request = new BrowseRequest()
            {
                Count = 10,
                Offset = 0,
                Query = query
            };
            var authors = new string[] { "kathy", "sierra" };//kathy&sierra
            var sectionFilter = new BrowseSelection("author");
            sectionFilter.Values = authors;
            sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd;
            request.AddSelection(sectionFilter);

            var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), new IFacetHandler[] { new MultiValueFacetHandler("author") }));
            var result = browser.Browse(request);
            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 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));
            }
        }