• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Search.QueryWrapperFilter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Lucene.Net.Search.QueryWrapperFilter的典型用法代码示例。如果您正苦于以下问题:C# QueryWrapperFilter类的具体用法?C# QueryWrapperFilter怎么用?C# QueryWrapperFilter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



QueryWrapperFilter类属于Lucene.Net.Search命名空间,在下文中一共展示了QueryWrapperFilter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: DocIdSetAnonymousInnerClassHelper

 public DocIdSetAnonymousInnerClassHelper(QueryWrapperFilter outerInstance, Bits acceptDocs, AtomicReaderContext privateContext, Lucene.Net.Search.Weight weight)
 {
     this.OuterInstance = outerInstance;
     this.AcceptDocs = acceptDocs;
     this.PrivateContext = privateContext;
     this.Weight = weight;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:7,代码来源:QueryWrapperFilter.cs


示例2: SearchCore

        private static IList<int> SearchCore(SearchFilter searchFilter, out int totalHits)
        {
            if (!Directory.Exists(LuceneCommon.IndexDirectory))
            {
                totalHits = 0;
                return new int[0];
            }

            SortField sortField = GetSortField(searchFilter);
            int numRecords = searchFilter.Skip + searchFilter.Take;

            using (var directory = new LuceneFileSystem(LuceneCommon.IndexDirectory))
            {
                var searcher = new IndexSearcher(directory, readOnly: true);
                var query = ParseQuery(searchFilter);

                var filterTerm = searchFilter.IncludePrerelease ? "IsLatest" : "IsLatestStable";
                var termQuery = new TermQuery(new Term(filterTerm, Boolean.TrueString));
                Filter filter = new QueryWrapperFilter(termQuery);
                

                var results = searcher.Search(query, filter: filter, n: numRecords, sort: new Sort(sortField));
                var keys = results.scoreDocs.Skip(searchFilter.Skip)
                                            .Select(c => ParseKey(searcher.Doc(c.doc).Get("Key")))
                                            .ToList();

                totalHits = results.totalHits;
                searcher.Close();
                return keys;
            }
        }
开发者ID:rhillaardvark,项目名称:chocolatey.org,代码行数:31,代码来源:LuceneSearchService.cs


示例3: TestBasic

		public virtual void  TestBasic()
		{
			Directory dir = new RAMDirectory();
			IndexWriter writer = new IndexWriter(dir, new StandardAnalyzer(), true, IndexWriter.MaxFieldLength.LIMITED);
			Document doc = new Document();
			doc.Add(new Field("field", "value", Field.Store.NO, Field.Index.ANALYZED));
			writer.AddDocument(doc);
			writer.Close();
			
			TermQuery termQuery = new TermQuery(new Term("field", "value"));
			
			// should not throw exception with primitive query
			QueryWrapperFilter qwf = new QueryWrapperFilter(termQuery);
			
			IndexSearcher searcher = new IndexSearcher(dir, true);
			TopDocs hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
			Assert.AreEqual(1, hits.totalHits);
			
			// should not throw exception with complex primitive query
			BooleanQuery booleanQuery = new BooleanQuery();
			booleanQuery.Add(termQuery, Occur.MUST);
			booleanQuery.Add(new TermQuery(new Term("field", "missing")), Occur.MUST_NOT);
			qwf = new QueryWrapperFilter(termQuery);
			
			hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
			Assert.AreEqual(1, hits.totalHits);
			
			// should not throw exception with non primitive Query (doesn't implement
			// Query#createWeight)
			qwf = new QueryWrapperFilter(new FuzzyQuery(new Term("field", "valu")));
			
			hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
			Assert.AreEqual(1, hits.totalHits);
		}
开发者ID:Rationalle,项目名称:ravendb,代码行数:34,代码来源:TestQueryWrapperFilter.cs


示例4: SearchCore

        private IQueryable<Package> SearchCore(SearchFilter searchFilter, out int totalHits)
        {
            int numRecords = searchFilter.Skip + searchFilter.Take;

            var searcher = new IndexSearcher(_directory, readOnly: true);
            var query = ParseQuery(searchFilter);

            // IF searching by relevance, boost scores by download count.
            if (searchFilter.SortProperty == SortProperty.Relevance)
            {
                var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
                query = new CustomScoreQuery(query, downloadCountBooster);
            }

            var filterTerm = searchFilter.IncludePrerelease ? "IsLatest" : "IsLatestStable";
            var termQuery = new TermQuery(new Term(filterTerm, Boolean.TrueString));
            var filter = new QueryWrapperFilter(termQuery);
            var results = searcher.Search(query, filter: filter, n: numRecords, sort: new Sort(GetSortField(searchFilter)));
            totalHits = results.totalHits;

            if (results.totalHits == 0 || searchFilter.CountOnly)
            {
                return Enumerable.Empty<Package>().AsQueryable();
            }

            var packages = results.scoreDocs
                                  .Skip(searchFilter.Skip)
                                  .Select(sd => PackageFromDoc(searcher.Doc(sd.doc)))
                                  .ToList();
            return packages.AsQueryable();
        }
开发者ID:ChrisMissal,项目名称:NuGetGallery,代码行数:31,代码来源:LuceneSearchService.cs


示例5: TestBasic

        public virtual void TestBasic()
        {
            Directory dir = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
            Document doc = new Document();
            doc.Add(NewTextField("field", "value", Field.Store.NO));
            writer.AddDocument(doc);
            IndexReader reader = writer.Reader;
            writer.Dispose();

            TermQuery termQuery = new TermQuery(new Term("field", "value"));

            // should not throw exception with primitive query
            QueryWrapperFilter qwf = new QueryWrapperFilter(termQuery);

            IndexSearcher searcher = NewSearcher(reader);
            TopDocs hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
            Assert.AreEqual(1, hits.TotalHits);
            hits = searcher.Search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
            Assert.AreEqual(1, hits.TotalHits);

            // should not throw exception with complex primitive query
            BooleanQuery booleanQuery = new BooleanQuery();
            booleanQuery.Add(termQuery, Occur.MUST);
            booleanQuery.Add(new TermQuery(new Term("field", "missing")), Occur.MUST_NOT);
            qwf = new QueryWrapperFilter(termQuery);

            hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
            Assert.AreEqual(1, hits.TotalHits);
            hits = searcher.Search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
            Assert.AreEqual(1, hits.TotalHits);

            // should not throw exception with non primitive Query (doesn't implement
            // Query#createWeight)
            qwf = new QueryWrapperFilter(new FuzzyQuery(new Term("field", "valu")));

            hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
            Assert.AreEqual(1, hits.TotalHits);
            hits = searcher.Search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
            Assert.AreEqual(1, hits.TotalHits);

            // test a query with no hits
            termQuery = new TermQuery(new Term("field", "not_exist"));
            qwf = new QueryWrapperFilter(termQuery);
            hits = searcher.Search(new MatchAllDocsQuery(), qwf, 10);
            Assert.AreEqual(0, hits.TotalHits);
            hits = searcher.Search(new MatchAllDocsQuery(), new CachingWrapperFilter(qwf), 10);
            Assert.AreEqual(0, hits.TotalHits);
            reader.Dispose();
            dir.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:51,代码来源:TestQueryWrapperFilter.cs


示例6: SearchCore

        private SearchResults SearchCore(SearchFilter searchFilter)
        {
            // Get index timestamp
            DateTime timestamp = File.GetLastWriteTimeUtc(LuceneCommon.GetIndexMetadataPath());

            int numRecords = searchFilter.Skip + searchFilter.Take;

            var searcher = new IndexSearcher(_directory, readOnly: true);
            var query = ParseQuery(searchFilter);

            // IF searching by relevance, boost scores by download count.
            if (searchFilter.SortOrder == SortOrder.Relevance)
            {
                var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
                query = new CustomScoreQuery(query, downloadCountBooster);
            }

            var filterTerm = searchFilter.IncludePrerelease ? "IsLatest" : "IsLatestStable";
            Query filterQuery = new TermQuery(new Term(filterTerm, Boolean.TrueString));
            if (searchFilter.CuratedFeed != null)
            {
                var feedFilterQuery = new TermQuery(new Term("CuratedFeedKey", searchFilter.CuratedFeed.Key.ToString(CultureInfo.InvariantCulture)));
                BooleanQuery conjunctionQuery = new BooleanQuery();
                conjunctionQuery.Add(filterQuery, Occur.MUST);
                conjunctionQuery.Add(feedFilterQuery, Occur.MUST);
                filterQuery = conjunctionQuery;
            }

            Filter filter = new QueryWrapperFilter(filterQuery);
            var results = searcher.Search(query, filter: filter, n: numRecords, sort: new Sort(GetSortField(searchFilter)));
            
            if (results.TotalHits == 0 || searchFilter.CountOnly)
            {
                return new SearchResults(results.TotalHits, timestamp);
            }

            var packages = results.ScoreDocs
                                  .Skip(searchFilter.Skip)
                                  .Select(sd => PackageFromDoc(searcher.Doc(sd.Doc)))
                                  .ToList();
            return new SearchResults(
                results.TotalHits,
                timestamp,
                packages.AsQueryable());
        }
开发者ID:henrycomein,项目名称:NuGetGallery,代码行数:45,代码来源:LuceneSearchService.cs


示例7: SearchAsync

        public Task<IEnumerable<SearchResultItem>> SearchAsync(string searchText, int projectId)
        {
            return Task.Run(() =>
            {
                //new searcher each time, 
                //  because they don't see commits from any writer after being opened.
                //  even in huge deployments though, TD's number of concurrent searches
                //  would be tiny... not worth coding a mechanism to detect updates and
                //  reuse a searcher until the index is updated. In actuality, index
                //  updates would certainly be more frequent than index searches.
                
                var searcher = new IndexSearcher(TdIndexDirectory, true);
                
                var fields = new[] {"id", "title", "details", "tags", "events"};
                var parser = new MultiFieldQueryParser(Version.LUCENE_30,
                    fields,
                    TdIndexAnalyzer);

                var query = parser.Parse(searchText);
                
                
                var collector = TopScoreDocCollector.Create(20, true);
                if (projectId != default(int))
                {
                    var filterQuery = new BooleanQuery();
                    filterQuery.Add(new TermQuery(new Term("projectid", projectId.ToString())), Occur.MUST);
                    var filter = new QueryWrapperFilter(filterQuery);
                    searcher.Search(query, filter, collector);
                }
                else
                {
                    searcher.Search(query, collector);
                }
                return collector.TopDocs().ScoreDocs.Select(d =>
                {
                    var document = searcher.Doc(d.Doc);
                    return new SearchResultItem
                    {
                        Id = int.Parse(document.Get("id")),
                        SearchScore = d.Score
                    };
                });
            });
        }
开发者ID:sadiqna,项目名称:TicketDesk,代码行数:44,代码来源:LuceneSearchLocatorProvider.cs


示例8: TestQueries

 public virtual void TestQueries()
 {
     int n = AtLeast(4);
     for (int i = 0; i < n; i++)
     {
         Filter odd = new QueryWrapperFilter(new TermQuery(new Term("oddeven", "odd")));
         AssertQuery(new MatchAllDocsQuery(), null);
         AssertQuery(new TermQuery(new Term("english", "one")), null);
         AssertQuery(new MatchAllDocsQuery(), odd);
         AssertQuery(new TermQuery(new Term("english", "four")), odd);
         BooleanQuery bq = new BooleanQuery();
         bq.Add(new TermQuery(new Term("english", "one")), BooleanClause.Occur.SHOULD);
         bq.Add(new TermQuery(new Term("oddeven", "even")), BooleanClause.Occur.SHOULD);
         AssertQuery(bq, null);
         // force in order
         bq.Add(new TermQuery(new Term("english", "two")), BooleanClause.Occur.SHOULD);
         bq.MinimumNumberShouldMatch = 2;
         AssertQuery(bq, null);
     }
 }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:20,代码来源:TestExpressionSorts.cs


示例9: SetUp

        public void SetUp()
        {
            directory = new RAMDirectory();
            IndexWriter writer =
               new IndexWriter(directory, new WhitespaceAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);

            DateTime cal = new DateTime(1041397200000L * TimeSpan.TicksPerMillisecond); // 2003 January 01

            for (int i = 0; i < MAX; i++)
            {
                Document doc = new Document();
                doc.Add(new Field("key", "" + (i + 1), Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("owner", (i < MAX / 2) ? "bob" : "sue", Field.Store.YES, Field.Index.NOT_ANALYZED));
                doc.Add(new Field("date", (cal.Ticks / TimeSpan.TicksPerMillisecond).ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                writer.AddDocument(doc);

                cal.AddMilliseconds(1);
            }

            writer.Close();

            searcher = new IndexSearcher(directory, true);

            // query for everything to make life easier
            BooleanQuery bq = new BooleanQuery();
            bq.Add(new TermQuery(new Term("owner", "bob")), BooleanClause.Occur.SHOULD);
            bq.Add(new TermQuery(new Term("owner", "sue")), BooleanClause.Occur.SHOULD);
            query = bq;

            // date filter matches everything too
            //Date pastTheEnd = parseDate("2099 Jan 1");
            // dateFilter = DateFilter.Before("date", pastTheEnd);
            // just treat dates as strings and select the whole range for now...
            dateFilter = new TermRangeFilter("date", "", "ZZZZ", true, true);

            bobFilter = new QueryWrapperFilter(
                new TermQuery(new Term("owner", "bob")));
            sueFilter = new QueryWrapperFilter(
                new TermQuery(new Term("owner", "sue")));
        }
开发者ID:Nangal,项目名称:lucene.net,代码行数:40,代码来源:ChainedFilterTest.cs


示例10: SearchCore

        private IQueryable<Package> SearchCore(SearchFilter searchFilter, out int totalHits)
        {
            int numRecords = searchFilter.Skip + searchFilter.Take;

            var searcher = new IndexSearcher(_directory, readOnly: true);
            var query = ParseQuery(searchFilter);

            // IF searching by relevance, boost scores by download count.
            if (searchFilter.SortProperty == SortProperty.Relevance)
            {
                var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
                query = new CustomScoreQuery(query, downloadCountBooster);
            }

            var filterTerm = searchFilter.IncludePrerelease ? "IsLatest" : "IsLatestStable";
            Query filterQuery = new TermQuery(new Term(filterTerm, Boolean.TrueString));
            if (searchFilter.CuratedFeedKey.HasValue)
            {
                var feedFilterQuery = new TermQuery(new Term("CuratedFeedKey", searchFilter.CuratedFeedKey.Value.ToString(CultureInfo.InvariantCulture)));
                BooleanQuery conjunctionQuery = new BooleanQuery();
                conjunctionQuery.Add(filterQuery, Occur.MUST);
                conjunctionQuery.Add(feedFilterQuery, Occur.MUST);
                filterQuery = conjunctionQuery;
            }

            Filter filter = new QueryWrapperFilter(filterQuery);
            var results = searcher.Search(query, filter: filter, n: numRecords, sort: new Sort(GetSortField(searchFilter)));
            totalHits = results.TotalHits;

            if (results.TotalHits == 0 || searchFilter.CountOnly)
            {
                return Enumerable.Empty<Package>().AsQueryable();
            }

            var packages = results.ScoreDocs
                                  .Skip(searchFilter.Skip)
                                  .Select(sd => PackageFromDoc(searcher.Doc(sd.Doc)))
                                  .ToList();
            return packages.AsQueryable();
        }
开发者ID:KuduApps,项目名称:NuGetGallery,代码行数:40,代码来源:LuceneSearchService.cs


示例11: SearchCore

        private SearchResults SearchCore(SearchFilter searchFilter)
        {
            // Get index timestamp
            DateTime timestamp = File.GetLastWriteTimeUtc(LuceneCommon.IndexMetadataPath);

            int numRecords = searchFilter.Skip + searchFilter.Take;

            var searcher = new IndexSearcher(_directory, readOnly: true);
            var query = ParseQuery(searchFilter);

            // If searching by relevance, boost scores by download count.
            if (searchFilter.SortProperty == SortProperty.Relevance)
            {
                var downloadCountBooster = new FieldScoreQuery("DownloadCount", FieldScoreQuery.Type.INT);
                query = new CustomScoreQuery(query, downloadCountBooster);
            }

            var filterTerm = searchFilter.IncludePrerelease ? "IsLatest" : "IsLatestStable";
            Query filterQuery = new TermQuery(new Term(filterTerm, Boolean.TrueString));

            Filter filter = new QueryWrapperFilter(filterQuery);
            var results = searcher.Search(query, filter: filter, n: numRecords, sort: new Sort(GetSortField(searchFilter)));

            if (results.TotalHits == 0 || searchFilter.CountOnly)
            {
                return new SearchResults(results.TotalHits, timestamp);
            }

            var packages = results.ScoreDocs
                                  .Skip(searchFilter.Skip)
                                  .Select(sd => PackageFromDoc(searcher.Doc(sd.Doc)))
                                  .ToList();

            return new SearchResults(
                results.TotalHits,
                timestamp,
                packages.AsQueryable());
        }
开发者ID:chocolatey,项目名称:chocolatey.org,代码行数:38,代码来源:LuceneSearchService.cs


示例12: SetUp

        public override void SetUp()
        {
            base.SetUp();
            directory = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory);
            // we use the default Locale/TZ since LuceneTestCase randomizes it
            var cal = new DateTime(1970, 1, 1, 0, 0, 0, (int)TestUtil.NextLong(Random(), 0, long.MaxValue), new GregorianCalendar());

            for (int i = 0; i < Max; i++)
            {
                Document doc = new Document();
                doc.Add(NewStringField("key", "" + (i + 1), Field.Store.YES));
                doc.Add(NewStringField("owner", (i < Max / 2) ? "bob" : "sue", Field.Store.YES));
                doc.Add(NewStringField("date", cal.ToString(CultureInfo.InvariantCulture), Field.Store.YES));
                writer.AddDocument(doc);

                cal = cal.AddDays(1);
            }
            reader = writer.Reader;
            writer.Dispose();

            searcher = NewSearcher(reader);

            // query for everything to make life easier
            BooleanQuery bq = new BooleanQuery();
            bq.Add(new TermQuery(new Term("owner", "bob")), BooleanClause.Occur.SHOULD);
            bq.Add(new TermQuery(new Term("owner", "sue")), BooleanClause.Occur.SHOULD);
            query = bq;

            // date filter matches everything too
            //Date pastTheEnd = parseDate("2099 Jan 1");
            // dateFilter = DateFilter.Before("date", pastTheEnd);
            // just treat dates as strings and select the whole range for now...
            dateFilter = TermRangeFilter.NewStringRange("date", "", "ZZZZ", true, true);

            bobFilter = new QueryWrapperFilter(new TermQuery(new Term("owner", "bob")));
            sueFilter = new QueryWrapperFilter(new TermQuery(new Term("owner", "sue")));
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:38,代码来源:ChainedFilterTest.cs


示例13: ProcessNextInQueue

        /// <summary>
        /// Processes the next tweet from the queue
        /// </summary>
        public void ProcessNextInQueue()
        {
            //read the tweets with a MinValue as their index date
            TermQuery query = new TermQuery(new Term(Settings.FIELD_TWEET_DATE_INDEXED, "0"));
            Filter filter = new QueryWrapperFilter(query);
            TopDocs results = _tweetSearcher.Search(query, filter, 1);

            //if no results, return
            if (results.totalHits == 0)
                return;

            Document tweetDoc = _tweetSearcher.Doc(results.scoreDocs[0].doc);

            //construct the tweet
            Tweet tweetToProcess = GetTweetFromDocument(tweetDoc);

            Console.WriteLine("Processing Tweet " + tweetToProcess.TweetId);

            //get the indexes
            var indexes = GetIndexesFromDocument(tweetDoc);

            //index the urls from the tweet
            _urlIndexer.IndexUrlsInTweet(tweetToProcess, indexes);
        }
开发者ID:RodH257,项目名称:RetrEave,代码行数:27,代码来源:StreamQueuedTweetsProcessor.cs


示例14: Search


//.........这里部分代码省略.........
                    if ((modifiedBeginDate.Date > DateTime.MinValue.Date) || (modifiedEndDate.Date < DateTime.MaxValue.Date))
                    {
                        TermRangeQuery lastModifiedDateFilter = new TermRangeQuery(
                            "LastModUtc",
                            modifiedBeginDate.Date.ToString("s"),
                            modifiedEndDate.Date.ToString("s"),
                            true,
                            true);

                        filterQuery.Add(lastModifiedDateFilter, Occur.MUST);
                    }

                    //if ((!DisableSearchFeatureFilters) && (featureGuid != Guid.Empty))
                    //{
                    //    BooleanQuery featureFilter = new BooleanQuery();

                    //    featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.MUST);

                    //    filterQuery.Add(featureFilter, Occur.MUST);
                    //}

                    if ((featureGuids != null) && (featureGuids.Length > 0))
                    {
                        BooleanQuery featureFilter = new BooleanQuery();

                        foreach (Guid featureGuid in featureGuids)
                        {
                            featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.SHOULD);
                        }

                        filterQuery.Add(featureFilter, Occur.MUST);
                    }

                    Filter filter = new QueryWrapperFilter(filterQuery); // filterQuery won't affect result scores

                    using (IndexSearcher searcher = new IndexSearcher(searchDirectory))
                    {

                        //http://stackoverflow.com/questions/9872933/migrating-lucene-hitcollector-2-x-to-collector-3-x
                        //TopScoreDocCollector collector = TopScoreDocCollector.Create(maxResults, true);

                        int maxResults = int.MaxValue;
                        TopDocs hits = searcher.Search(searchQuery, filter, maxResults);

                        int startHit = 0;
                        if (pageNumber > 1)
                        {
                            startHit = ((pageNumber - 1) * pageSize);
                        }

                        totalHits = hits.TotalHits;

                        int end = startHit + pageSize;
                        if (totalHits <= end)
                        {
                            end = totalHits;
                        }

                        int itemsAdded = 0;
                        int itemsToAdd = end;

                        QueryScorer scorer = new QueryScorer(searchQuery);
                        SimpleHTMLFormatter formatter = new SimpleHTMLFormatter("<span class='searchterm'>", "</span>");
                        Highlighter highlighter = new Highlighter(formatter, scorer);

                        highlighter.TextFragmenter = new SimpleFragmenter(highlightedFragmentSize);
开发者ID:joedavis01,项目名称:mojoportal,代码行数:67,代码来源:IndexHelper.cs


示例15: Browse

        public static IndexItemCollection Browse(
            int siteId,
            Guid featureGuid,
            DateTime modifiedBeginDate,
            DateTime modifiedEndDate,
            int pageNumber,
            int pageSize,
            out int totalHits)
        {
            totalHits = 0;

            IndexItemCollection results = new IndexItemCollection();

            using (Lucene.Net.Store.Directory searchDirectory = GetDirectory(siteId))
            {
                Filter filter = null;
                BooleanQuery filterQuery = null;

                if ((modifiedBeginDate.Date > DateTime.MinValue.Date) || (modifiedEndDate.Date < DateTime.MaxValue.Date))
                {
                    filterQuery = new BooleanQuery(); // won't be used to score the results

                    TermRangeQuery lastModifiedDateFilter = new TermRangeQuery(
                        "LastModUtc",
                        modifiedBeginDate.Date.ToString("s"),
                        modifiedEndDate.Date.ToString("s"),
                        true,
                        true);

                    filterQuery.Add(lastModifiedDateFilter, Occur.MUST);

                }

                if (featureGuid != Guid.Empty)
                {
                    if (filterQuery == null) { filterQuery = new BooleanQuery(); }

                    BooleanQuery featureFilter = new BooleanQuery();

                    featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.MUST);

                    filterQuery.Add(featureFilter, Occur.MUST);
                }

                if (filterQuery != null)
                {
                    filter = new QueryWrapperFilter(filterQuery); // filterQuery won't affect result scores
                }

                MatchAllDocsQuery matchAllQuery = new MatchAllDocsQuery();

                using (IndexSearcher searcher = new IndexSearcher(searchDirectory))
                {
                    int maxResults = int.MaxValue;

                    TopDocs hits = searcher.Search(matchAllQuery, filter, maxResults);

                    int startHit = 0;
                    if (pageNumber > 1)
                    {
                        startHit = ((pageNumber - 1) * pageSize);
                    }

                    totalHits = hits.TotalHits;

                    if (startHit > totalHits)
                    {
                        startHit = totalHits;
                    }

                    int end = startHit + pageSize;
                    if (totalHits <= end)
                    {
                        end = totalHits;
                    }

                    int itemsAdded = 0;
                    int itemsToAdd = end;

                    for (int i = startHit; i < itemsToAdd; i++)
                    {
                        Document doc = searcher.Doc(hits.ScoreDocs[i].Doc);
                        IndexItem indexItem = new IndexItem(doc, hits.ScoreDocs[i].Score);

                        results.Add(indexItem);
                        itemsAdded += 1;

                    }

                    results.ItemCount = itemsAdded;
                    results.PageIndex = pageNumber;

                    results.ExecutionTime = DateTime.Now.Ticks; // -0;

                }

                //    using (IndexReader reader = IndexReader.Open(searchDirectory, false))
                //    {

                //        totalHits = reader.NumDocs();
//.........这里部分代码省略.........
开发者ID:joedavis01,项目名称:mojoportal,代码行数:101,代码来源:IndexHelper.cs


示例16: GetRecentModifiedContent

        public static List<IndexItem> GetRecentModifiedContent(
            int siteId,
            Guid[] featureGuids,
            DateTime modifiedSinceDate,
            int maxItems)
        {
            int totalHits = 0;

            List<IndexItem> results = new List<IndexItem>();

            using (Lucene.Net.Store.Directory searchDirectory = GetDirectory(siteId))
            {
                Filter filter = null;
                BooleanQuery filterQuery = new BooleanQuery(); // won't be used to score the results

                BooleanQuery excludeFilter = new BooleanQuery();
                excludeFilter.Add(new TermQuery(new Term("ExcludeFromRecentContent", "false")), Occur.MUST);
                filterQuery.Add(excludeFilter, Occur.MUST);

                TermRangeQuery lastModifiedDateFilter = new TermRangeQuery(
                    "LastModUtc",
                    modifiedSinceDate.Date.ToString("s"),
                    DateTime.MaxValue.ToString("s"),
                    true,
                    true);

                filterQuery.Add(lastModifiedDateFilter, Occur.MUST);

                // we only want public content, that is both page and module roles must have "All Users"
                // which means even unauthenticated users
                Term pageRole = new Term("Role", "All Users");
                TermQuery pageRoleFilter = new TermQuery(pageRole);
                filterQuery.Add(pageRoleFilter, Occur.MUST);

                Term moduleRole = new Term("ModuleRole", "All Users");
                TermQuery moduleRoleFilter = new TermQuery(moduleRole);

                filterQuery.Add(moduleRoleFilter, Occur.MUST);

                if ((featureGuids != null)&&(featureGuids.Length > 0))
                {
                    BooleanQuery featureFilter = new BooleanQuery();

                    foreach (Guid featureGuid in featureGuids)
                    {
                        featureFilter.Add(new TermQuery(new Term("FeatureId", featureGuid.ToString())), Occur.SHOULD);

                    }

                    filterQuery.Add(featureFilter, Occur.MUST);

                }

                filter = new QueryWrapperFilter(filterQuery); // filterQuery won't affect result scores

                MatchAllDocsQuery matchAllQuery = new MatchAllDocsQuery();

                using (IndexSearcher searcher = new IndexSearcher(searchDirectory))
                {

                    int maxResults = int.MaxValue;
                    TopDocs hits = searcher.Search(matchAllQuery, filter, maxResults);
                    totalHits = hits.TotalHits;

                    for (int i = 0; i < totalHits; i++)
                    {
                        Document doc = searcher.Doc(hits.ScoreDocs[i].Doc);
                        IndexItem indexItem = new IndexItem(doc, hits.ScoreDocs[i].Score);

                        results.Add(indexItem);

                    }

                }

            }

            // sort all descending on lastmodutc
            results.Sort();

            if (results.Count <= maxItems)
            {
                return results;
            }
            else
            {
                List<IndexItem> finalResults = new List<IndexItem>();
                for (int i = 0; i < maxItems; i++)
                {
                    finalResults.Add(results[i]);
                }

                return finalResults;

            }
        }
开发者ID:joedavis01,项目名称:mojoportal,代码行数:96,代码来源:IndexHelper.cs


示例17: CalculateOpenBitSetDisi

 protected OpenBitSetDISI CalculateOpenBitSetDisi(string facetAttributeFieldName, string value)
 {
     var facetQuery = new TermQuery(new Term(facetAttributeFieldName, value));
     var facetQueryFilter = new QueryWrapperFilter(facetQuery);
     return new OpenBitSetDISI(facetQueryFilter.GetDocIdSet(IndexReader).Iterator(), IndexReader.MaxDoc);
 }
开发者ID:modulexcite,项目名称:MultiFacetLuceneNet,代码行数:6,代码来源:FacetSearcher.cs


示例18: TestWithCachingFilter

        public void TestWithCachingFilter()
        {
            Directory dir = new RAMDirectory();
            Analyzer analyzer = new WhitespaceAnalyzer();

            IndexWriter writer = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
            writer.Close();

            Searcher searcher = new IndexSearcher(dir, true);

            Query query = new TermQuery(new Term("none", "none"));

            QueryWrapperFilter queryFilter = new QueryWrapperFilter(query);
            CachingWrapperFilter cachingFilter = new CachingWrapperFilter(queryFilter);

            searcher.Search(query, cachingFilter, 1);

            CachingWrapperFilter cachingFilter2 = new CachingWrapperFilter(queryFilter);
            Filter[] chain = new Filter[2];
            chain[0] = cachingFilter;
            chain[1] = cachingFilter2;
            ChainedFilter cf = new ChainedFilter(chain);

            // throws java.lang.ClassCastException: org.apache.lucene.util.OpenBitSet cannot be cast to java.util.BitSet
            searcher.Search(new MatchAllDocsQuery(), cf, 1);
        }
开发者ID:Nangal,项目名称:lucene.net,代码行数:26,代码来源:ChainedFilterTest.cs


示例19: TestQueryWrapperFilter

        public virtual void TestQueryWrapperFilter()
        {
            Directory d = NewDirectory();
            RandomIndexWriter w = new RandomIndexWriter(Random(), d, Similarity, TimeZone);
            Document doc = new Document();
            doc.Add(NewStringField("field", "a", Field.Store.NO));
            w.AddDocument(doc);
            IndexReader r = w.Reader;
            w.Dispose();

            Filter filter = new QueryWrapperFilter(AssertingQuery.Wrap(Random(), new TermQuery(new Term("field", "a"))));
            IndexSearcher s = NewSearcher(r);
            Debug.Assert(s is AssertingIndexSearcher);
            // this used to fail
            s.Search(new ConstantScoreQuery(filter), new TotalHitCountCollector());

            // check the rewrite
            Query rewritten = (new ConstantScoreQuery(filter)).Rewrite(r);
            Assert.IsTrue(rewritten is ConstantScoreQuery);
            Assert.IsTrue(((ConstantScoreQuery)rewritten).Query is AssertingQuery);

            r.Dispose();
            d.Dispose();
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:24,代码来源:TestConstantScoreQuery.cs


示例20: TestWithCachingFilter

        public virtual void TestWithCachingFilter()
        {
            Directory dir = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
            IndexReader reader = writer.Reader;
            writer.Dispose();

            IndexSearcher searcher = NewSearcher(reader);

            Query query = new TermQuery(new Term("none", "none"));

            QueryWrapperFilter queryFilter = new QueryWrapperFilter(query);
            CachingWrapperFilter cachingFilter = new CachingWrapperFilter(queryFilter);

            searcher.Search(query, cachingFilter, 1);

            CachingWrapperFilter cachingFilter2 = new CachingWrapperFilter(queryFilter);
            Filter[] chain = new Filter[2];
            chain[0] = cachingFilter;
            chain[1] = cachingFilter2;
            ChainedFilter cf = new ChainedFilter(chain);

            // throws java.lang.ClassCastException: org.apache.lucene.util.OpenBitSet cannot be cast to java.util.BitSet
            searcher.Search(new MatchAllDocsQuery(), cf, 1);
            reader.Dispose();
            dir.Dispose();
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:27,代码来源:ChainedFilterTest.cs



注:本文中的Lucene.Net.Search.QueryWrapperFilter类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Search.ScoreDoc类代码示例发布时间:2022-05-26
下一篇:
C# Search.Query类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap