private static void Main(string[] args)
        {
            var originalByteCount = GC.GetTotalMemory(true);
            _target = new FacetSearcher(SetupIndexPhysicalTest(), new FacetSearcherConfiguration {MemoryOptimizer = new DefaultMemoryOptimizer(20, 5000), MinimumCountInTotalDatasetForFacet = 1});

            var stopwatchAll = new Stopwatch();
            stopwatchAll.Start();

            var queryParser = new MultiFieldQueryParser(Version.LUCENE_30,
                new[] {"title", "bodies"},
                new StandardAnalyzer(Version.LUCENE_30)
                );

            var facetFieldInfos = new List<FacetFieldInfo>
            {
                new FacetFieldInfo {FieldName = "userdisplayname", MaxToFetchExcludingSelections = 20},
                new FacetFieldInfo {FieldName = "tag", MaxToFetchExcludingSelections = 20},
            };

            for (var i = 0; i < 100; i++)
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var query = queryParser.Parse("mysql");
                var actual = _target.SearchWithFacets(query, 100, facetFieldInfos);
                stopwatch.Stop();

                foreach (var groupy in actual.Facets.Select(x => x.FacetFieldName).Distinct())
                {
                    var @group = groupy;
                    File.WriteAllLines(@"d:\\temp2\\" + group + ".txt", actual.Facets.Where(x => x.FacetFieldName == group).Select(x => x.Value + ":" + x.Count));
                }
                var vs = stopwatch.ElapsedMilliseconds;
                Console.WriteLine("Took " + vs + " ms");
            }
            stopwatchAll.Stop();
            var vs2 = stopwatchAll.ElapsedMilliseconds;
            Console.WriteLine("Took " + vs2 + " ms - i.e " + vs2/100 + "ms/query");

            GC.Collect();
            GC.WaitForPendingFinalizers();
            var finalByteCount = GC.GetTotalMemory(true);

            Console.WriteLine("START: " + originalByteCount + " END:" + finalByteCount);
            Console.WriteLine("DIFF: " + (finalByteCount - originalByteCount));
        }
Beispiel #2
0
        public static SearchResult MultiSearch(string term, List<FacetMatch> filters)
        {
            var result = new SearchResult();

            if (_directory == null)
            {
                _directory = new RAMDirectory(FSDirectory.Open(@"c:\test\luceneindex"));
            }

            //var reader = IndexReader.Open(FSDirectory.Open(@"c:\test\luceneindex"), true);
            var reader = IndexReader.Open(_directory, true);

            var searcher = new FacetSearcher(reader);
            var analyzer = new StandardAnalyzer(Version.LUCENE_30);
            var queryParser = new QueryParser(Version.LUCENE_30, "name", analyzer);
            queryParser.AllowLeadingWildcard = true;

            var query = queryParser.Parse("*" + term + "*");
            query = CreateFacetedQuery(query, filters, "");

            //var query = new TermQuery(new Term(term + "*"));
            var facetFields = new List<FacetFieldInfo>();
            var db = new Database();

            facetFields.Add(new FacetFieldInfo()
            {
                FieldName = "category"
            });

            foreach (var specType in db.GetSpecTypes())
            {
                facetFields.Add(new FacetFieldInfo()
                {
                    FieldName = specType,
                    Selections = filters.Where(f => f.FacetName == specType).Select(f => f.FacetValue).ToList()
                });
            }

            var actual = searcher.SearchWithFacets(query, 200, facetFields);

            if (actual.Hits.TotalHits > 0)
            {
                foreach (var hit in actual.Hits.ScoreDocs)
                {
                    var doc = searcher.Doc(hit.Doc);

                    result.Products.Add(new Product()
                    {
                        Name = doc.GetField("name").StringValue,
                        Id = int.Parse(doc.GetField("id").StringValue)
                    });
                }

                foreach (var facet in actual.Facets)
                {
                    result.Facets.Add(new FacetMatch()
                    {
                        FacetName = facet.FacetFieldName,
                        FacetValue = facet.Value,
                        HitCount = facet.Count
                    });
                }
            }

            result.Facets = result.Facets.OrderBy(f => f.FacetName).ThenBy(f => f.FacetValue).ToList();
            var groups = result.Facets.GroupBy(g => g.FacetName);
            return result;
        }
        private static void Maina(string[] args)
        {
            _target = new FacetSearcher(SetupIndex());
            Warmup();

            var facetFieldInfos = new List<FacetFieldInfo>
            {
                new FacetFieldInfo {FieldName = "color", MaxToFetchExcludingSelections = 20},
                new FacetFieldInfo {FieldName = "type", MaxToFetchExcludingSelections = 20},
            };

            var stopwatchAll = new Stopwatch();
            stopwatchAll.Start();
            for (var i = 0; i < 100; i++)
            {
                var stopwatch = new Stopwatch();
                stopwatch.Start();
                var actual = _target.SearchWithFacets(new MatchAllDocsQuery(), 100, facetFieldInfos);
                stopwatch.Stop();
                var vs = stopwatch.ElapsedMilliseconds;
                Console.WriteLine("Took " + vs + " ms");
            }
            stopwatchAll.Stop();
            var vs2 = stopwatchAll.ElapsedMilliseconds;
            Console.WriteLine("Took " + vs2 + " ms - i.e " + vs2/100 + "ms/query");
        }