Exemple #1
0
        public void Test1Filter()
        {
            BrowseRequest             request = CreateRequest(1, "prop3");
            FacetCountCollectorSource facetCountCollectorSource = attributesFacetHandler.GetFacetCountCollectorSource(request.GetSelection(AttributeHandlerName), request.GetFacetSpec(AttributeHandlerName));
            RandomAccessFilter        randomAccessFilter        = attributesFacetHandler.BuildFilter(request.GetSelection(AttributeHandlerName));
            DocIdSetIterator          iterator = randomAccessFilter.GetDocIdSet(boboReader).Iterator();
            int docId = iterator.NextDoc();

            int[] docIds = new int[2];
            int   i      = 0;

            while (docId != DocIdSetIterator.NO_MORE_DOCS)
            {
                docIds[i] = docId;
                i++;
                docId = iterator.NextDoc();
            }
            Assert.AreEqual(Arrays.ToString(new int[] { 1, 2 }), Arrays.ToString(docIds));

            BrowseResult res = browser.Browse(request);

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

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

            Assert.AreEqual(1, facet.FacetValueHitCount);
        }
Exemple #2
0
        public virtual BrowseResult Browse(BrowseRequest req)
        {
            BoboBrowser browser = null;

            try
            {
                browser = new BoboBrowser(_boboReader);
                return(browser.Browse(req));
            }
            catch (Exception e)
            {
                logger.Error(e.Message, e);
                return(new BrowseResult());
            }
            finally
            {
                if (browser != null)
                {
                    try
                    {
                        browser.Dispose();
                    }
                    catch (Exception e)
                    {
                        logger.Error(e.Message);
                    }
                }
            }
        }
Exemple #3
0
        /// <summary>
        /// Gets the unprocessed results for a search query.
        /// </summary>
        /// <param name="query">The query</param>
        /// <param name="searchLimit">The max number of results we want</param>
        /// <param name="offset">The number of already processed results to skip.</param>
        /// <returns>The results of the search unfiltered for the user.</returns>
        protected override RawSearchResultSet GetRawSearchResults(Query query, int searchLimit, int offset)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var br = new BrowseRequest();

            br.Count  = searchLimit;
            br.Query  = query;
            br.Offset = offset;

            // execute the query
            IBrowsable browser = new BoboBrowser(this.boboReader);

            var browseResult = browser.Browse(br);

            stopwatch.Stop();

            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Lucene(faceted/BoboBrowse): {0} total hits ({1}ms)", browseResult.NumHits, stopwatch.ElapsedMilliseconds));

            PortalFeatureTrace.TraceInstance.LogSearch(FeatureTraceCategory.Search, browseResult.NumHits, stopwatch.ElapsedMilliseconds, string.Format("Lucene(faceted/BoboBrowse): {0} total hits ({1}ms)", browseResult.NumHits, stopwatch.ElapsedMilliseconds));

            return(this.ConvertBoboBrowseResultsToRawSearchResultSet(browseResult, offset, Enumerable.Empty <FacetConstraints>()));
        }
Exemple #4
0
        /// <summary>
        /// Executes the browse request
        /// </summary>
        /// <param name="browseRequest"></param>
        /// <param name="facetHandlers"></param>
        /// <param name="addDefaultFacetHandlers"></param>
        /// <returns></returns>
        public virtual BrowseResult Browse(BrowseRequest browseRequest, List <FacetHandler> facetHandlers = null, bool addDefaultFacetHandlers = true)
        {
            facetHandlers = facetHandlers ?? new List <FacetHandler>();

            if (addDefaultFacetHandlers)
            {
                foreach (var facetField in FacetFields)
                {
                    var facetAlias = facetField.Alias.FacetFieldAlias();
                    facetHandlers.Add(facetField.CreateFacetHandler());
                    var facetSpec = new FacetSpec
                    {
                        OrderBy         = facetField.ValueOrderBy,
                        ExpandSelection = facetField.ExpandSelection,
                        MinHitCount     = facetField.MinHitCount
                    };

                    browseRequest.SetFacetSpec(facetAlias, facetSpec);
                }
            }

            var searchProvider = ExamineManager.Instance.SearchProviderCollection[SearchProvider] as LuceneSearcher;
            var searcher       = (IndexSearcher)searchProvider.GetSearcher();
            var reader         = searcher.GetIndexReader();

            var boboReader = BoboIndexReader.GetInstance(reader, facetHandlers);

            IBrowsable browser = new BoboBrowser(boboReader);

            return(browser.Browse(browseRequest));
        }
        public BrowseResult Browse(BrowseRequest browseRequest)
        {
            string indexDir = HostingEnvironment.MapPath(ConfigurationManager.AppSettings["LuceneIndexDirectory"]);

            // This is the equivalent code to what is specified in the "/LuceneIndex/bobo.spring" file. You could just as well
            // specify this configuration here and pass it to another overload of BoboIndexReader.GetInstance that accepts
            // an IEnumerable<IFacetHandler> as an argument.

            //var facetHandlers = new List<IFacetHandler>();
            //facetHandlers.Add(new SimpleFacetHandler("color") { TermCountSize = BoboBrowse.Net.Facets.TermCountSize.Small });
            //facetHandlers.Add(new SimpleFacetHandler("category") { TermCountSize = BoboBrowse.Net.Facets.TermCountSize.Medium });
            //facetHandlers.Add(new PathFacetHandler("city") { Separator = "/" });
            //facetHandlers.Add(new PathFacetHandler("makemodel") { Separator = "/" });
            //facetHandlers.Add(new RangeFacetHandler("year", new PredefinedTermListFactory<int>("00000000000000000000"), new string[] { "[1993 TO 1994]", "[1995 TO 1996]", "[1997 TO 1998]", "[1999 TO 2000]", "[2001 TO 2002]" }));
            //facetHandlers.Add(new RangeFacetHandler("price", new PredefinedTermListFactory<float>("00000000000000000000"), new string[] { "[2001 TO 6700]", "[6800 TO 9900]", "[10000 TO 13100]", "[13200 TO 17300]", "[17400 TO 19500]" }));
            //facetHandlers.Add(new RangeFacetHandler("mileage", new PredefinedTermListFactory<int>("00000000000000000000"), new string[] { "[* TO 12500]", "[12501 TO 15000]", "[15001 TO 17500]", "[17501 TO *]" }));
            //facetHandlers.Add(new MultiValueFacetHandler("tags"));


            System.IO.DirectoryInfo idxDir = new System.IO.DirectoryInfo(indexDir);
            using (IndexReader reader = IndexReader.Open(FSDirectory.Open(idxDir), true))
            {
                using (BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader))
                {
                    using (BoboBrowser browser = new BoboBrowser(boboReader))
                    {
                        return(browser.Browse(browseRequest));
                    }
                }
            }
        }
Exemple #6
0
        public void TestLogging()
        {
            // Set up a simple Log4Net configuration that logs in memory.
            var memAppend = new log4net.Appender.MemoryAppender();

#if NETCOREAPP1_0
            var repository = LogManager.GetRepository(Assembly.GetEntryAssembly());
            BasicConfigurator.Configure(repository, memAppend);
#else
            BasicConfigurator.Configure(memAppend);
#endif

            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);

            Directory ramIndexDir = CreateIndex();
            using (DirectoryReader srcReader = DirectoryReader.Open(ramIndexDir))
            {
                using (BoboMultiReader boboReader = BoboMultiReader.GetInstance(srcReader, _facetHandlers))
                {
                    using (BoboBrowser boboBrowser = new BoboBrowser(boboReader))
                    {
                        using (BrowseResult result = boboBrowser.Browse(br))
                        {
                        }
                    }
                }
            }

            var events = memAppend.GetEvents();

            Assert.AreEqual(3, events.Length);
            StringAssert.StartsWith("facetHandler loaded: id, took:", events[0].RenderedMessage);
            StringAssert.StartsWith("facetHandler loaded: make, took:", events[1].RenderedMessage);
            StringAssert.StartsWith("facetHandler loaded: mycolor, took:", events[2].RenderedMessage);
        }
Exemple #7
0
        public void TestNotValuesForSimpleFacetHandler()
        {
            BrowseRequest br = new BrowseRequest();

            br.Count  = 20;
            br.Offset = 0;

            BrowseSelection colorSel = new BrowseSelection("color");

            colorSel.AddValue("red");
            br.AddSelection(colorSel);

            BrowseSelection idSel = new BrowseSelection("id");

            idSel.AddNotValue("0");
            br.AddSelection(idSel);

            BrowseResult result         = null;
            BoboBrowser  boboBrowser    = null;
            int          expectedHitNum = (_documentSize / 2) - 1;

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

                        Assert.AreEqual(expectedHitNum, result.NumHits);

                        StringBuilder buffer = new StringBuilder();
                        BrowseHit[]   hits   = result.Hits;

                        for (int i = 0; i < hits.Length; ++i)
                        {
                            int expectedID = (i + 1) * 2;
                            Assert.AreEqual(expectedID, int.Parse(hits[i].GetField("id")));
                            if (i != 0)
                            {
                                buffer.Append('\n');
                            }
                            buffer.Append("id=" + hits[i].GetField("id") + "," + "color=" + hits[i].GetField("color"));
                        }
                        log.Info(buffer.ToString());
                    }
                }
            }
        }
        public void PerformSearch(BoboFacetRequest request)
        {
            using (var boboReader = BoboIndexReader.GetInstance(Searcher.IndexReader, request.FacetHandlers))
                using (var browser = new BoboBrowser(boboReader))
                {
                    var results = browser.Browse(request.BrowseRequest);

                    _browseHits = results.Hits;

                    foreach (var facet in results.FacetMap)
                    {
                        Facets.Add(facet.Key, CreateFacetResult(facet.Value));
                    }

                    TotalItemCount = results.NumHits;
                }
        }
Exemple #9
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 (DirectoryReader srcReader = DirectoryReader.Open(ramIndexDir))
            {
                using (BoboMultiReader boboReader = BoboMultiReader.GetInstance(srcReader, _facetHandlers))
                {
                    using (BoboBrowser boboBrowser = new BoboBrowser(boboReader))
                    {
                        using (BrowseResult result = boboBrowser.Browse(br))
                        {
                            Assert.AreEqual(expectedHitNum, result.NumHits);
                        }
                    }
                }
            }
        }
Exemple #10
0
        /// <summary>
        /// Override to get faceted results
        /// </summary>
        /// <param name="query">The query</param>
        /// <param name="searchLimit">The max number of results we want</param>
        /// <param name="offset">The number of already processed results to skip.</param>
        /// <returns>The results of the search unfiltered for the user.</returns>
        protected override RawSearchResultSet GetRawSearchResults(ICrmEntityQuery query, int searchLimit, int offset)
        {
            var stopwatch = new Stopwatch();

            stopwatch.Start();

            var br = new BrowseRequest();

            br.Count  = searchLimit;
            br.Sort   = this.GetSortField(query);
            br.Query  = this.CreateQuery(query);
            br.Offset = offset;

            this.AddFacetConstraints(br, query.FacetConstraints);

            // add preconfigured facet specs
            foreach (var fieldToSpec in this.specs)
            {
                br.SetFacetSpec(fieldToSpec.Key, fieldToSpec.Value);
            }

            // execute the query
            IBrowsable browser = new BoboBrowser(this.boboReader);

            foreach (var facetConfiguration in this.config.GetConfiguredFacets())
            {
                if (facetConfiguration.FacetHandlerType == FacetHandlerType.Dynamic)
                {
                    browser.SetFacetHandler(facetConfiguration.FacetHandler);
                }
            }
            var browseResult = browser.Browse(br);

            stopwatch.Stop();

            ADXTrace.Instance.TraceInfo(TraceCategory.Application, string.Format("Lucene(faceted/BoboBrowse): {0} total hits ({1}ms)", browseResult.NumHits, stopwatch.ElapsedMilliseconds));

            PortalFeatureTrace.TraceInstance.LogSearch(FeatureTraceCategory.Search, browseResult.NumHits, stopwatch.ElapsedMilliseconds, string.Format("Lucene(faceted/BoboBrowse): {0} total hits ({1}ms)", browseResult.NumHits, stopwatch.ElapsedMilliseconds));

            return(this.ConvertBoboBrowseResultsToRawSearchResultSet(browseResult, offset, query.FacetConstraints));
        }
Exemple #11
0
        public void TestNotValuesForRangeFacetHandler()
        {
            Console.WriteLine("TestNotValuesForRangeFacetHandler");
            BrowseResult result      = null;
            BoboBrowser  boboBrowser = null;

            using (Directory ramIndexDir = CreateIndexTwo())
            {
                using (IndexReader srcReader = IndexReader.Open(ramIndexDir, true))
                {
                    using (boboBrowser = new BoboBrowser(BoboIndexReader.GetInstance(srcReader, _facetHandlers, null)))
                    {
                        BrowseRequest br = new BrowseRequest();
                        br.Count  = (20);
                        br.Offset = (0);

                        if (_idRanges == null)
                        {
                            log.Error("_idRanges cannot be null in order to test NOT on RangeFacetHandler");
                        }
                        BrowseSelection idSel = new BrowseSelection("idRange");
                        //int rangeIndex = 2; // Not used
                        idSel.AddNotValue(_idRanges[0]);
                        int expectedHitNum = 1;
                        br.AddSelection(idSel);
                        BooleanQuery q = new BooleanQuery();
                        q.Add(NumericRangeQuery.NewIntRange("NUM", 10, 10, true, true), Occur.MUST_NOT);
                        q.Add(new MatchAllDocsQuery(), Occur.MUST);
                        br.Query = q;

                        result = boboBrowser.Browse(br);

                        Assert.AreEqual(expectedHitNum, result.NumHits);
                        for (int i = 0; i < result.NumHits; i++)
                        {
                            Console.WriteLine(result.Hits[i]);
                        }
                    }
                }
            }
        }
Exemple #12
0
        public virtual BrowseResult Browse(BrowseRequest req) // throws BrowseException
        {
            BrowseResult result = BrowseService_Fields.EMPTY_RESULT;

            if (req.Offset < 0)
            {
                throw new BrowseException("Invalid offset: " + req.Offset);
            }
            if (_reader != null)
            {
                BoboBrowser browser;
                try
                {
                    browser = new BoboBrowser(_reader);
                }
                catch (Exception e)
                {
                    throw new BrowseException("failed to create BoboBrowser", e);
                }
                result = browser.Browse(req);
            }
            return(result);
        }
Exemple #13
0
        static void Main(string[] args)
        {
            Lucene.Net.Util.Version version = Lucene.Net.Util.Version.LUCENE_29;

            var      dir      = new RAMDirectory();
            Analyzer analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(version),
                                                            new Dictionary <string, Analyzer> {
                { "organization", new KeywordAnalyzer() }
            });

            // Add content to the index
            var indexWriter = new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);

            foreach (var document in CreateDocuments(CreateTestData()))
            {
                indexWriter.AddDocument(document);
            }

            indexWriter.Commit();
            indexWriter.Dispose();

            var orgFieldName   = "organization";
            var titleFieldName = "title";
            var createdAtName  = "created_at";

            var rangeFacetName = "rangeFacet";

            //var orgFacetHandler = new PathFacetHandler(orgFieldName);
            //orgFacetHandler.SetSeparator("/");
            var          orgFacetHandler       = new MultiValueFacetHandler(orgFieldName);
            FacetHandler titleFacetHandler     = new MultiValueFacetHandler(titleFieldName);
            var          createdAtFacetHandler = new SimpleFacetHandler(createdAtName);
            //var ranges = new List<string> { "[2000/01/01 TO 2000/12/30]", "[2001/01/01 TO 2007/12/30]" };
            var ranges = new List <string> {
                "[20000101 TO 20001230]", "[20040101 TO *]"
            };
            var rangeFacetHandler = new RangeFacetHandler(rangeFacetName, createdAtName, ranges);


            IndexReader reader = IndexReader.Open(dir, true);

            // decorate it with a bobo index reader
            BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader, new[] { orgFacetHandler, titleFacetHandler, createdAtFacetHandler, rangeFacetHandler });

            // creating a browse request
            var browseRequest = new BrowseRequest {
                Count = 10, Offset = 0, FetchStoredFields = true
            };

            // add a selection
            //var orgSelection = new BrowseSelection(orgFieldName);
            //orgSelection.AddValue("A/B");
            //browseRequest.AddSelection(orgSelection);

            var titleSelction = new BrowseSelection(titleFieldName);

            //titleSelction.AddValue("Læge");
            browseRequest.AddSelection(titleSelction);

            browseRequest.AddSelection(new BrowseSelection(rangeFacetName));

            // parse a query
            var   parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "name", new KeywordAnalyzer());
            Query q      = parser.Parse("an*");

            browseRequest.Query = q;

            // add the facet output specs
            var orgSpec = new FacetSpec {
                OrderBy = FacetSpec.FacetSortSpec.OrderValueAsc
            };

            browseRequest.SetFacetSpec(orgFieldName, orgSpec);
            var titleSpec = new FacetSpec {
                MinHitCount = 1, OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc
            };

            browseRequest.SetFacetSpec(titleFieldName, titleSpec);
            //var createdAtSpec = new FacetSpec { MinHitCount = 1, OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc };
            //browseRequest.SetFacetSpec(createdAtName, createdAtSpec);
            var rangeSpec = new FacetSpec {
                MinHitCount = 1, OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc
            };

            browseRequest.SetFacetSpec(rangeFacetName, rangeSpec);

            // perform browse
            IBrowsable browser = new BoboBrowser(boboReader);

            BrowseResult result = browser.Browse(browseRequest);

            // Showing results now
            int totalHits = result.NumHits;

            BrowseHit[] hits = result.Hits;

            Dictionary <String, IFacetAccessible> facetMap = result.FacetMap;

            IFacetAccessible orgFacets = facetMap[orgFieldName];

            Console.WriteLine("Facets {0}:", orgFieldName);
            foreach (BrowseFacet facet in orgFacets.GetFacets())
            {
                Console.WriteLine(facet.ToString());
            }

            IFacetAccessible titleFacets = facetMap[titleFieldName];

            Console.WriteLine("Facets {0}:", titleFieldName);
            foreach (BrowseFacet facet in titleFacets.GetFacets())
            {
                Console.WriteLine(facet.ToString());
            }

            if (facetMap.ContainsKey(createdAtName))
            {
                IFacetAccessible createdAtFacets = facetMap[createdAtName];
                Console.WriteLine("Facets {0}:", createdAtName);
                foreach (BrowseFacet facet in createdAtFacets.GetFacets())
                {
                    Console.WriteLine(facet.ToString());
                }
            }


            if (facetMap.ContainsKey(rangeFacetName))
            {
                Console.WriteLine("-------------------------------------");
                IFacetAccessible rangeFacets = facetMap[rangeFacetName];
                Console.WriteLine("Facets {0}:", rangeFacets);
                foreach (BrowseFacet facet in rangeFacets.GetFacets())
                {
                    Console.WriteLine(facet.ToString());
                }
                Console.WriteLine("-------------------------------------");
            }


            Console.WriteLine("Actual items (total: {0}) query: {1}:", totalHits, q);
            for (int i = 0; i < hits.Length; ++i)
            {
                BrowseHit browseHit = hits[i];
                Console.WriteLine("id = {0}, Name = {1}, Organizations = {{{2}}}, Titles = {{{3}}}, Created at = {4}", browseHit.StoredFields.Get("id"), browseHit.StoredFields.Get("name"), string.Join(", ", browseHit.StoredFields.GetValues("organization").Distinct()), string.Join(", ", browseHit.StoredFields.GetValues("title").Distinct()), browseHit.StoredFields.Get("created_at"));
            }
        }
Exemple #14
0
        public void testRuntimeFilteredDateRange()
        {
            Lucene.Net.Util.Version version = Lucene.Net.Util.Version.LUCENE_29;

            var      dir      = new RAMDirectory();
            Analyzer analyzer = new PerFieldAnalyzerWrapper(new StandardAnalyzer(version),
                                                            new Dictionary <string, Analyzer> {
                { "organization", new KeywordAnalyzer() }
            });

            // Add content to the index
            var indexWriter = new IndexWriter(dir, analyzer, IndexWriter.MaxFieldLength.UNLIMITED);

            foreach (var document in CreateDocuments())
            {
                indexWriter.AddDocument(document);
            }

            indexWriter.Commit();
            indexWriter.Dispose();



            //var ranges = new List<string> { "[2000/01/01 TO 2001/12/30]", "[2007/01/01 TO 2007/12/30]" };
            ////var handler = new FilteredRangeFacetHandler("filtered_date", "date", ranges);
            //var handler = new RangeFacetHandler("date", new PredefinedTermListFactory<DateTime>("yyyy/MM/dd"), ranges);

            //IndexReader reader = IndexReader.Open(dir, true);

            //// decorate it with a bobo index reader
            //BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader, new[] { handler });
            //IBrowsable browser = new BoboBrowser(boboReader);

            //var req = new BrowseRequest();
            //req.SetFacetSpec("filtered_date", new FacetSpec());


            //BrowseResult result = browser.Browse(req);

            //// Showing results now
            //int totalHits = result.NumHits;
            //BrowseHit[] hits = result.Hits;

            //Dictionary<String, IFacetAccessible> facetMap = result.FacetMap;


            // queries
            var dateRange = new List <String>();

            dateRange.Add("[" + DateTools.DateToString(new DateTime(1999, 1, 1), DateTools.Resolution.DAY) + " TO " + DateTools.DateToString(new DateTime(2000, 12, 30), DateTools.Resolution.DAY) + "]");
            dateRange.Add("[" + DateTools.DateToString(new DateTime(2001, 1, 1), DateTools.Resolution.DAY) + " TO *]");


            // color facet handler
            var dateHandler = new RangeFacetHandler("date", dateRange);
            var titleFacet  = new SimpleFacetHandler("title");
            var handlerList = new List <FacetHandler>()
            {
                dateHandler, titleFacet
            };


            // opening a lucene index
            IndexReader reader = IndexReader.Open(dir);

            // decorate it with a bobo index reader
            BoboIndexReader boboReader = BoboIndexReader.GetInstance(reader, handlerList);

            // creating a browse request
            var br = new BrowseRequest {
                Count = 10, Offset = 0
            };

            // add a selection
            BrowseSelection sel = new BrowseSelection("title");

            //sel.AddValue("bodyintitle");
            br.AddSelection(sel);

            // parse a query
            var   parser = new QueryParser(version, "id", new StandardAnalyzer(version));
            Query q      = parser.Parse("*:*");

            br.Query = q;

            // add the facet output specs
            FacetSpec dateSpec = new FacetSpec();

            dateSpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;
            br.SetFacetSpec("date", dateSpec);
            FacetSpec titleSpec = new FacetSpec();

            titleSpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;
            br.SetFacetSpec("title", titleSpec);

            // perform browse
            var          browser = new BoboBrowser(boboReader);
            BrowseResult result  = browser.Browse(br);

            int totalHits = result.NumHits;

            BrowseHit[] hits = result.Hits;

            Dictionary <String, IFacetAccessible> facetMap = result.FacetMap;

            IFacetAccessible dateFacets = facetMap["date"];

            Debug.WriteLine("Facets date:");
            foreach (BrowseFacet facetVal in dateFacets.GetFacets())
            {
                Debug.WriteLine("Facet " + facetVal.Value + "(" + facetVal.HitCount + ")");
            }

            IFacetAccessible orgFacets = facetMap["title"];

            Debug.WriteLine("Facets title:");
            foreach (BrowseFacet facet in orgFacets.GetFacets())
            {
                Debug.WriteLine(facet.ToString());
            }

            int i = 42;
        }
        private BrowseResult PerformSearch(Query query, string indexPath, IEnumerable<Models.SelectionGroup> selectionGroups)
        {
            string[] FieldNames = new string[] { "Material", "Style", "Mounting", "Brand" };

            var handlers = new List<FacetHandler>();

            foreach (string field in FieldNames)
            {
                handlers.Add(new SimpleFacetHandler(field));
            }

            // Run the search

            // create the index reader
            var directory = FSDirectory.Open(new System.IO.DirectoryInfo(indexPath));
            var indexReader = DirectoryReader.Open(directory, true);

            //// This is how to get a searcher for executing the search, not for working with facets
            //IndexSearcher indexSearcher = new IndexSearcher(directory, true);
            //indexSearcher.Search(

            // Decorate it with the Bobo index reader
            BoboIndexReader boboReader = BoboIndexReader.GetInstance(indexReader, handlers);

            // create a browse request
            BrowseRequest browseRequest = new BrowseRequest();

            // NOTE: these must be used in production to page the results
            browseRequest.Count = 50;
            browseRequest.Offset = 0;

            browseRequest.FetchStoredFields = true;

            //Query query = new QueryParser(
            //        Lucene.Net.Util.Version.LUCENE_29,
            //        "title",
            //        new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)
            //    ).Parse(model.Phrase);

            if (selectionGroups != null)
            {
                // Add the selections to the search

                foreach (var group in selectionGroups)
                {
                    BrowseSelection sel = new BrowseSelection(group.Name);
                    foreach (var value in group.Selections)
                    {
                        sel.AddValue(value);
                    }
                    browseRequest.AddSelection(sel);
                }

            }

            browseRequest.Query = query;

            //// add the facet output specs
            //FacetSpec brandSpec = new FacetSpec();
            //brandSpec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;

            //browseRequest.SetFacetSpec("Brand", brandSpec);

            foreach (var name in FieldNames)
            {
                // add the facet output specs
                FacetSpec spec = new FacetSpec();
                //spec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;

                // NOTE: if this is a secondary search, we want to get the facets with 0
                // hits so the checkboxes can be set on the UI...or otherwise program the UI
                // to disable and set to 0 all of the selections that aren't in the result
                if (selectionGroups != null)
                {
                    spec.MinHitCount = 0;
                }

                browseRequest.SetFacetSpec(name, spec);
            }

            // perform browse
            IBrowsable browser = new BoboBrowser(boboReader);

            BrowseResult result = browser.Browse(browseRequest);

            return result;
        }
        private BrowseResult PerformAutoCompleteLookup(string prefix, string indexPath)
        {
            FacetHandler handler = new MultiValueFacetHandler("title");

            Directory directory = FSDirectory.Open(new System.IO.DirectoryInfo(indexPath));
            IndexReader indexReader = IndexReader.Open(directory, true);

            // decorate it with a bobo index reader
            BoboIndexReader boboReader = BoboIndexReader.GetInstance(indexReader, new FacetHandler[] { handler });

            BrowseRequest browseRequest = new BrowseRequest();
            browseRequest.Count = 8;
            browseRequest.Offset = 0;
            browseRequest.FetchStoredFields = true;

            // add a selection
            BrowseSelection sel = new BrowseSelection("title");
            //sel.AddValue("alexey");
            browseRequest.AddSelection(sel);

            // parse a query
            // NOTE: this was "Entity" originally
            QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "title", new KeywordAnalyzer());
            Query q = parser.Parse("SPListItem");
            browseRequest.Query = q;

            // add the facet output specs
            FacetSpec spec = new FacetSpec();
            spec.Prefix = prefix;
            spec.OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc;

            browseRequest.SetFacetSpec("title", spec);

            // perform browse
            IBrowsable browser = new BoboBrowser(boboReader);

            BrowseResult result = browser.Browse(browseRequest);

            return result;

            //// Showing results now
            //Dictionary<String, IFacetAccessible> facetMap = result.FacetMap;

            //IFacetAccessible colorFacets = facetMap["Body"];

            //IEnumerable<BrowseFacet> facetVals = colorFacets.GetFacets();

            //Debug.WriteLine("Facets:");

            //int count = 0;
            //foreach (BrowseFacet facet in facetVals)
            //{
            //    count++;
            //    Debug.WriteLine(facet.ToString());
            //}
            //Debug.WriteLine("Total = " + count);
        }