Beispiel #1
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));
        }
Beispiel #2
0
        public void TestFacetHandlerLoad()
        {
            var reader = IndexReader.Open(_ramDir, true);

            var list = new List <IFacetHandler>();
            var h1   = new NoopFacetHandler("A");

            list.Add(h1);

            var s2 = new HashSet <string>();

            s2.Add("A");
            s2.Add("C");
            s2.Add("D");
            var h2 = new NoopFacetHandler("B", s2);

            list.Add(h2);

            var s3 = new HashSet <string>();

            s3.Add("A");
            s2.Add("D");
            var h3 = new NoopFacetHandler("C", s3);

            list.Add(h3);

            var s4 = new HashSet <string>();

            s4.Add("A");
            var h4 = new NoopFacetHandler("D", s4);

            list.Add(h4);

            var s5 = new HashSet <string>();

            s5.Add("E");
            var h5 = new NoopFacetHandler("E", s5);

            list.Add(h5);


            using (var boboReader = BoboIndexReader.GetInstance(reader, list, null))
            {
                using (var browser = new BoboBrowser(boboReader))
                {
                    var s6 = new HashSet <string>();
                    s6.Add("A");
                    s6.Add("B");
                    s6.Add("C");
                    s6.Add("D");
                    browser.SetFacetHandler(new NoopFacetHandler("runtime", s6));

                    var expected = new HashSet <string>();
                    expected.Add("A");
                    expected.Add("B");
                    expected.Add("C");
                    expected.Add("D");
                    expected.Add("E");
                    expected.Add("runtime");

                    var facetsLoaded = browser.FacetNames;

                    foreach (var name in facetsLoaded)
                    {
                        if (expected.Contains(name))
                        {
                            expected.Remove(name);
                        }
                        else
                        {
                            Assert.Fail(name + " is not in expected set.");
                        }
                    }

                    if (expected.Count > 0)
                    {
                        Assert.Fail("some facets not loaded: " + string.Join(", ", expected.ToArray()));
                    }
                }
            }
        }