Exemplo n.º 1
0
        /// <summary>
        /// Creates a browser request from the passed in key value pair query string
        /// </summary>
        /// <param name="querystring"></param>
        /// <param name="page"></param>
        /// <param name="useOffset"></param>
        /// <param name="itemsPerPage"></param>
        /// <returns></returns>
        public virtual BrowseRequest CreateBrowseRequest(List <KeyValuePair <string, string> > querystring, int?page = null, bool useOffset = false, int itemsPerPage = 10)
        {
            Query query         = null;
            var   compiledQuery = BuildBaseQuery(querystring);

            if (compiledQuery != null)
            {
                var luceneParams = compiledQuery as LuceneSearchCriteria;
                query = luceneParams?.Query ?? throw new ArgumentException("Provided ISearchCriteria dos not match the allowed ISearchCriteria. Ensure you only use an ISearchCriteria created from the current SearcherProvider");
            }

            var offset = 0;

            if (!page.HasValue)
            {
                page = 1;
            }
            var count = page.Value * itemsPerPage;

            if (useOffset)
            {
                offset = (page.Value - 1) * itemsPerPage;
                count  = itemsPerPage;
            }

            var browseRequest = new BrowseRequest
            {
                Offset            = offset,
                Count             = count,
                Query             = query,
                FetchStoredFields = true,
                Sort = DetermineSort(querystring)
            };

            var facetSelection = QueryStringParser.ParseQueryString(querystring, FacetFields);

            foreach (var facetField in facetSelection)
            {
                if (facetField.Value.Any())
                {
                    var sel = new BrowseSelection(facetField.Key.Alias.FacetFieldAlias());
                    foreach (var selection in facetField.Value)
                    {
                        if (!string.IsNullOrEmpty(selection))
                        {
                            sel.AddValue(selection);
                        }
                    }
                    sel.SelectionOperation = facetField.Key.SelectionOperation;
                    browseRequest.AddSelection(sel);
                }
            }

            return(browseRequest);
        }
Exemplo n.º 2
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);
        }
        public override RandomAccessFilter BuildRandomAccessFilter(string value, IDictionary <string, string> selectionProperty)
        {
            List <RandomAccessFilter> filterList = new List <RandomAccessFilter>();

            string[] vals = value.Split(new string[] { m_sep }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < vals.Length; ++i)
            {
                SimpleFacetHandler handler = m_facetHandlers[i];
                BrowseSelection    sel     = new BrowseSelection(handler.Name);
                sel.AddValue(vals[i]);
                filterList.Add(handler.BuildFilter(sel));
            }
            return(new RandomAccessAndFilter(filterList));
        }
Exemplo n.º 4
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());
                    }
                }
            }
        }
Exemplo n.º 5
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);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        public BrowseRequest CreateRequest(int minHitCount, BrowseSelection.ValueOperation operation, params string[] terms)
        {
            BrowseRequest req = new BrowseRequest();

            BrowseSelection sel = new BrowseSelection(AttributeHandlerName);

            foreach (String term in terms)
            {
                sel.AddValue(term);
            }
            sel.SetSelectionProperties(selectionProperties);
            sel.SelectionOperation = (operation);
            req.AddSelection(sel);
            req.Count = (50);
            FacetSpec fs = new FacetSpec();

            fs.MinHitCount = (minHitCount);
            req.SetFacetSpec(AttributeHandlerName, fs);
            return(req);
        }
        public BrowseRequest CreateRequest(int minHitCount, BrowseSelection.ValueOperation operation, params string[] terms)
        {
            BrowseRequest req = new BrowseRequest();

            BrowseSelection sel = new BrowseSelection(AttributeHandlerName);
            foreach (String term in terms)
            {
                sel.AddValue(term);
            }
            sel.SetSelectionProperties(selectionProperties);
            sel.SelectionOperation = (operation);
            req.AddSelection(sel);
            req.Count = (50);
            FacetSpec fs = new FacetSpec();
            fs.MinHitCount = (minHitCount);
            req.SetFacetSpec(AttributeHandlerName, fs);
            return req;
        }
        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;
        }