示例#1
0
        //Lookup by group int value (Alternative Syntax)
        private void LookupGroupsByIntAlt(Directory directory)
        {
            Filter groupEndDocs = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("groupEnd", "x"))));

            IndexReader indexReader = DirectoryReader.Open(directory);

            IndexSearcher indexSearcher = new IndexSearcher(indexReader);

            GroupingSearch groupingSearch = new GroupingSearch(groupEndDocs);

            groupingSearch.SetGroupSort(new Sort());

            groupingSearch.SetIncludeScores(true);

            Query query = NumericRangeQuery.NewInt32Range("Repetition", 1, 2, true, false);

            var groupsResult = groupingSearch.Search(indexSearcher, query, 0, 10);             //search(indexSearcher, query, groupOffset, groupLimit);

            indexReader.Dispose();
        }
示例#2
0
        //Lookup by group string value (Alternative Syntax)
        private void LookupGroupsByStringAlt(Directory directory)
        {
            Filter groupEndDocs = new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("groupEnd", "x"))));

            IndexReader indexReader = DirectoryReader.Open(directory);

            IndexSearcher indexSearcher = new IndexSearcher(indexReader);

            GroupingSearch groupingSearch = new GroupingSearch(groupEndDocs);

            groupingSearch.SetGroupSort(new Sort());

            groupingSearch.SetIncludeScores(true);

            TermQuery query = new TermQuery(new Term("Category", "Cat 1"));

            var groupsResult = groupingSearch.Search(indexSearcher, query, 0, 10);             //search(indexSearcher, query, groupOffset, groupLimit);

            indexReader.Dispose();
        }
示例#3
0
        private IEnumerable <KeyValuePair <string, int> > _GroupBy(int skip, int pageSize, string fieldName)
        {
            GroupingSearch groupingSearch = new GroupingSearch(fieldName);

            groupingSearch.SetGroupSort(Sort.RELEVANCE);
            groupingSearch.SetFillSortFields(false);
            groupingSearch.SetCachingInMB(40.0, true);
            groupingSearch.SetAllGroups(true);
            // Render groupsResult...
            try
            {
                var reader = DirectoryReader.Open(_directory);

                var searcher = new Lucene.Net.Search.IndexSearcher(reader);

                Sort groupSort   = Sort.RELEVANCE;
                int  groupOffset = 0;
                int  groupLimit  = 10000000;

                string rawQuery = _queryProvider.GetBooleanQuery().ToString();

                if (!rawQuery.Contains("isdeleted"))
                {
                    rawQuery += "+isdeleted:0";
                }
                var queryParser = new QueryParser(LuceneVersion.LUCENE_48, "isdeleted", analyzer);

                queryParser.AllowLeadingWildcard = _queryProvider.GetContainsWildCard();

                var query = queryParser.Parse(rawQuery);

                ITopGroups <object> result = groupingSearch.Search(searcher, query, groupOffset, groupLimit);

                if (result.Groups == null || result.Groups.Count() <= 0)
                {
                    return(new List <KeyValuePair <string, int> >());
                }

                var d = result.Groups.OrderByDescending(p => p.TotalHits).ToList();

                if (d.FirstOrDefault().GroupValue == null)
                {
                    d.RemoveAt(0);
                }

                _groupCount = d.Count;

                if (pageSize > d.Count)
                {
                    pageSize = d.Count;
                }
                d = d.Skip(skip).Take(pageSize).ToList();

                if (d.Count > 0)
                {
                    var rs = d.Select(p => new KeyValuePair <string, int>(((BytesRef)p.GroupValue)?.Utf8ToString(), p.TotalHits)).ToList();

                    return(rs);
                }
                else
                {
                    return(new List <KeyValuePair <string, int> >());
                }
            }

            catch
            {
                throw;
            }

            finally
            {
            }
        }