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

C# Search.FilteredQuery类代码示例

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

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



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

示例1: SearchEx

 public static LuceneResultNode SearchEx(IndexBase index, SearchNode node)
 {
     try
     {
         var query = MultiFieldQueryParser.Parse(Lucene.Net.Util.Version.LUCENE_29, node.Queries, node.Fields, node.Occurs, new PanGuAnalyzer(true));
         foreach (NumberRangeNode n in node.NumberRangeFiters)
         {
             query = new FilteredQuery(query, NumericRangeFilter.NewIntRange(n.FieldName, n.MinValue, n.MaxValue, true, true));
         }
         foreach (LongRangeNode lr in node.LongRnageFilters)
         {
             query = new FilteredQuery(query, NumericRangeFilter.NewLongRange(lr.FieldName, lr.MinValue, lr.MaxValue, true, true));
         }
         foreach (ContainFilterNode cf in node.ContainFilters)
         {
             query = new FilteredQuery(query, new ContainFilter(new Term(cf.FieldName, cf.Text)));
         }
         return ResponseSearch(index, query, node, 0);
     }
     catch (Lucene.Net.QueryParsers.ParseException)
     {
         return new LuceneResultNode() { AllCount = 0, Result = new List<string>() };
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
开发者ID:uvbs,项目名称:MyProjects,代码行数:28,代码来源:Searcher.cs


示例2: Search

        public static void Search(JsonWriter jsonWriter,
            NuGetSearcherManager searcherManager,
            string scheme,
            string q,
            bool includePrerelease,
            int skip,
            int take,
            string feed,
            bool includeExplanation)
        {
            var searcher = searcherManager.Get();

            try
            {
                Query query = MakeSearchQuery(q, searcher);

                Filter filter = null;

                if (searcher.TryGetFilter(false, includePrerelease, feed, out filter))
                {
                    // Filter before running the query (make the search set smaller)
                    query = new FilteredQuery(query, filter);
                }

                TopDocs topDocs = searcher.Search(query, skip + take);

                ResponseFormatter.WriteSearchResult(jsonWriter, searcher, scheme, topDocs, skip, take, includePrerelease, includeExplanation, query);
            }
            finally
            {
                searcherManager.Release(searcher);
            }
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:33,代码来源:ServiceImpl.cs


示例3: VisitWithinRadius

        protected virtual Lucene.Net.Search.Query VisitWithinRadius(WithinRadiusNode node, LuceneQueryMapperState mappingState)
        {
            SpatialContext ctx = SpatialContext.GEO;
           
            var strategy = new PointVectorStrategy(ctx, Sitecore.ContentSearch.Spatial.Common.Constants.LocationFieldName);

            if (node.Latitude is double && node.Longitude is double && node.Radius is double)
            {
                var distance = DistanceUtils.Dist2Degrees((double)node.Radius, DistanceUtils.EARTH_MEAN_RADIUS_MI);
                Circle circle = ctx.MakeCircle((double)node.Longitude,(double)node.Latitude, distance);

                var spatialArgs = new SpatialArgs(SpatialOperation.IsWithin, circle);
                var dq = strategy.MakeQuery(spatialArgs);

                DistanceReverseValueSource valueSource = new DistanceReverseValueSource(strategy, circle.GetCenter(), distance);
                ValueSourceFilter vsf = new ValueSourceFilter(new QueryWrapperFilter(dq), valueSource, 0, distance);
                var filteredSpatial = new FilteredQuery(new MatchAllDocsQuery(), vsf);
                mappingState.FilterQuery = filteredSpatial;
                Lucene.Net.Search.Query spatialRankingQuery = new FunctionQuery(valueSource);
                Random r = new Random(DateTime.Now.Millisecond);
                var randomNumber = r.Next(10000101,11000101);
                Lucene.Net.Search.Query dummyQuery = Lucene.Net.Search.NumericRangeQuery.NewIntRange("__smallcreateddate", randomNumber, Int32.Parse(DateTime.Now.ToString("yyyyMMdd")), true, true);
                BooleanQuery bq = new BooleanQuery();

                bq.Add(filteredSpatial, Occur.MUST);
                bq.Add(spatialRankingQuery, Occur.MUST);
                bq.Add(dummyQuery, Occur.SHOULD);
                return bq;
            }
            throw new NotSupportedException("Wrong parameters type, Radius, latitude and longitude must be of type double");
        }
开发者ID:Igentics,项目名称:Sitecore.ContentSearch.Spatial,代码行数:31,代码来源:LuceneQueryMapperWithSpatial.cs


示例4: Test1

        public virtual void Test1()
        {
            BooleanQuery q = new BooleanQuery();

            PhraseQuery phraseQuery = new PhraseQuery();
            phraseQuery.Slop = 1;
            phraseQuery.Add(new Term(FIELD, "w1"));
            phraseQuery.Add(new Term(FIELD, "w2"));
            q.Add(phraseQuery, Occur.MUST);
            q.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true), Occur.SHOULD);
            q.Add(Snear(Sf("w3", 2), St("w2"), St("w3"), 5, true), Occur.SHOULD);

            Query t = new FilteredQuery(new TermQuery(new Term(FIELD, "xx")), new ItemizedFilter(new int[] { 1, 3 }));
            t.Boost = 1000;
            q.Add(t, Occur.SHOULD);

            t = new ConstantScoreQuery(new ItemizedFilter(new int[] { 0, 2 }));
            t.Boost = 30;
            q.Add(t, Occur.SHOULD);

            DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
            dm.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true));
            dm.Add(new TermQuery(new Term(FIELD, "QQ")));

            BooleanQuery xxYYZZ = new BooleanQuery();
            xxYYZZ.Add(new TermQuery(new Term(FIELD, "xx")), Occur.SHOULD);
            xxYYZZ.Add(new TermQuery(new Term(FIELD, "yy")), Occur.SHOULD);
            xxYYZZ.Add(new TermQuery(new Term(FIELD, "zz")), Occur.MUST_NOT);

            dm.Add(xxYYZZ);

            BooleanQuery xxW1 = new BooleanQuery();
            xxW1.Add(new TermQuery(new Term(FIELD, "xx")), Occur.MUST_NOT);
            xxW1.Add(new TermQuery(new Term(FIELD, "w1")), Occur.MUST_NOT);

            dm.Add(xxW1);

            DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
            dm2.Add(new TermQuery(new Term(FIELD, "w1")));
            dm2.Add(new TermQuery(new Term(FIELD, "w2")));
            dm2.Add(new TermQuery(new Term(FIELD, "w3")));
            dm.Add(dm2);

            q.Add(dm, Occur.SHOULD);

            BooleanQuery b = new BooleanQuery();
            b.MinimumNumberShouldMatch = 2;
            b.Add(Snear("w1", "w2", 1, true), Occur.SHOULD);
            b.Add(Snear("w2", "w3", 1, true), Occur.SHOULD);
            b.Add(Snear("w1", "w3", 3, true), Occur.SHOULD);

            q.Add(b, Occur.SHOULD);

            Qtest(q, new int[] { 0, 1, 2 });
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:55,代码来源:TestComplexExplanations.cs


示例5: Search

        public static void Search(JsonWriter jsonWriter, NuGetSearcherManager searcherManager, string q, bool countOnly, bool includePrerelease, string sortBy, int skip, int take, string feed, bool ignoreFilter, bool luceneQuery)
        {
            if (jsonWriter == null)
            {
                throw new ArgumentNullException(nameof(jsonWriter));
            }

            if (searcherManager == null)
            {
                throw new ArgumentNullException(nameof(searcherManager));
            }

            var searcher = searcherManager.Get();
            try
            {
                // The old V2 search service would treat "id:" queries (~match) in the same way as it did "packageid:" (==match).
                // If "id:" is in the query, replace it.
                if (luceneQuery && !string.IsNullOrEmpty(q) && q.StartsWith("id:", StringComparison.OrdinalIgnoreCase))
                {
                    q = "packageid:" + q.Substring(3);
                }

                // Build the query
                Query query = NuGetQuery.MakeQuery(q, searcher.Owners);

                // Build filter
                bool includeUnlisted = ignoreFilter;
                includePrerelease = ignoreFilter || includePrerelease;
                feed = ignoreFilter ? null : feed;

                Filter filter = null;
                if (!ignoreFilter && searcher.TryGetFilter(includeUnlisted, includePrerelease, feed, out filter))
                {
                    // Filter before running the query (make the search set smaller)
                    query = new FilteredQuery(query, filter);
                }

                if (countOnly)
                {
                    DocumentCountImpl(jsonWriter, searcher, query);
                }
                else
                {
                    ListDocumentsImpl(jsonWriter, searcher, query, sortBy, skip, take);
                }
            }
            finally
            {
                searcherManager.Release(searcher);
            }
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:51,代码来源:GalleryServiceImpl.cs


示例6: GetQuery

        /// <summary>
        /// (non-Javadoc)
        /// @see org.apache.lucene.xmlparser.QueryObjectBuilder#process(org.w3c.dom.Element)
        /// </summary>
        public virtual Query GetQuery(XmlElement e)
        {
            XmlElement filterElement = DOMUtils.GetChildByTagOrFail(e, "Filter");
            filterElement = DOMUtils.GetFirstChildOrFail(filterElement);
            Filter f = filterFactory.GetFilter(filterElement);

            XmlElement queryElement = DOMUtils.GetChildByTagOrFail(e, "Query");
            queryElement = DOMUtils.GetFirstChildOrFail(queryElement);
            Query q = queryFactory.GetQuery(queryElement);

            FilteredQuery fq = new FilteredQuery(q, f);
            fq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return fq;
        }
开发者ID:apache,项目名称:lucenenet,代码行数:18,代码来源:FilteredQueryBuilder.cs


示例7: AutoComplete

        public static void AutoComplete(JsonWriter jsonWriter, NuGetSearcherManager searcherManager, string q, string id, bool includePrerelease, int skip, int take, bool includeExplanation)
        {
            var searcher = searcherManager.Get();
            try
            {
                Filter filter = null;

                if (q != null)
                {
                    Query query = MakeAutoCompleteQuery(q,
                        searcher.DocIdMapping,
                        searcher.Downloads,
                        searcher.Rankings,
                        searcher.QueryBoostingContext);

                    if (searcher.TryGetFilter(false, includePrerelease, null, out filter))
                    {
                        // Filter before running the query (make the search set smaller)
                        query = new FilteredQuery(query, filter);
                    }

                    TopDocs topDocs = searcher.Search(query, skip + take);
                    ResponseFormatter.WriteAutoCompleteResult(jsonWriter, searcher, topDocs, skip, take, includeExplanation, query);
                }
                else
                {
                    Query query = MakeAutoCompleteVersionQuery(id);

                    if (searcher.TryGetFilter(false, includePrerelease, null, out filter))
                    {
                        // Filter before running the query (make the search set smaller)
                        query = new FilteredQuery(query, filter);
                    }

                    TopDocs topDocs = searcher.Search(query, 1);
                    ResponseFormatter.WriteAutoCompleteVersionResult(jsonWriter, searcher, includePrerelease, topDocs);
                }
            }
            finally
            {
                searcherManager.Release(searcher);
            }
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:43,代码来源:ServiceImpl.cs


示例8: Test1

		public virtual void  Test1()
		{
			
			BooleanQuery q = new BooleanQuery();
			
			q.Add(qp.Parse("\"w1 w2\"~1"), Occur.MUST);
			q.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true), Occur.SHOULD);
			q.Add(Snear(Sf("w3", 2), St("w2"), St("w3"), 5, true), Occur.SHOULD);
			
			Query t = new FilteredQuery(qp.Parse("xx"), new ItemizedFilter(new int[]{1, 3}));
			t.SetBoost(1000);
			q.Add(t, Occur.SHOULD);
			
			t = new ConstantScoreQuery(new ItemizedFilter(new int[]{0, 2}));
			t.SetBoost(30);
			q.Add(t, Occur.SHOULD);
			
			DisjunctionMaxQuery dm = new DisjunctionMaxQuery(0.2f);
			dm.Add(Snear(St("w2"), Sor("w5", "zz"), 4, true));
			dm.Add(qp.Parse("QQ"));
			dm.Add(qp.Parse("xx yy -zz"));
			dm.Add(qp.Parse("-xx -w1"));
			
			DisjunctionMaxQuery dm2 = new DisjunctionMaxQuery(0.5f);
			dm2.Add(qp.Parse("w1"));
			dm2.Add(qp.Parse("w2"));
			dm2.Add(qp.Parse("w3"));
			dm.Add(dm2);
			
			q.Add(dm, Occur.SHOULD);
			
			BooleanQuery b = new BooleanQuery();
			b.SetMinimumNumberShouldMatch(2);
			b.Add(Snear("w1", "w2", 1, true), Occur.SHOULD);
			b.Add(Snear("w2", "w3", 1, true), Occur.SHOULD);
			b.Add(Snear("w1", "w3", 3, true), Occur.SHOULD);
			
			q.Add(b, Occur.SHOULD);
			
			Qtest(q, new int[]{0, 1, 2});
		}
开发者ID:vikasraz,项目名称:indexsearchutils,代码行数:41,代码来源:TestComplexExplanations.cs


示例9: WeightAnonymousInnerClassHelper

 public WeightAnonymousInnerClassHelper(FilteredQuery outerInstance, Lucene.Net.Search.Weight weight)
 {
     this.OuterInstance = outerInstance;
     this.Weight = weight;
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:5,代码来源:FilteredQuery.cs


示例10: DoSearch

        private static TopDocs DoSearch(IndexSearcher searcher, ScoreDoc after, Query q, Filter filter, int n, Sort sort, bool doDocScores, bool doMaxScore, Collector fc)
        {

            if (filter != null)
            {
                q = new FilteredQuery(q, filter);
            }

            int limit = searcher.IndexReader.MaxDoc;
            if (limit == 0)
            {
                limit = 1;
            }
            n = Math.Min(n, limit);

            if (after != null && after.Doc >= limit)
            {
                throw new System.ArgumentException("after.doc exceeds the number of documents in the reader: after.doc=" + after.Doc + " limit=" + limit);
            }


            if (sort != null)
            {
                if (after != null && !(after is FieldDoc))
                {
                    // TODO: if we fix type safety of TopFieldDocs we can
                    // remove this
                    throw new System.ArgumentException("after must be a FieldDoc; got " + after);
                }
                const bool fillFields = true;
                var hitsCollector = TopFieldCollector.Create(sort, n, (FieldDoc)after, fillFields, doDocScores, doMaxScore, false);
                searcher.Search(q, MultiCollector.Wrap(hitsCollector, fc));
                return hitsCollector.TopDocs();
            }
            else
            {
                // TODO: can we pass the right boolean for
                // in-order instead of hardwired to false...?  we'd
                // need access to the protected IS.search methods
                // taking Weight... could use reflection...
                var hitsCollector = TopScoreDocCollector.Create(n, after, false);
                searcher.Search(q, MultiCollector.Wrap(hitsCollector, fc));
                return hitsCollector.TopDocs();
            }
        }
开发者ID:ChristopherHaws,项目名称:lucenenet,代码行数:45,代码来源:FacetsCollector.cs


示例11: AssertSubsetOf

        /// <summary>
        /// Asserts that the documents returned by <code>q1</code>
        /// are a subset of those returned by <code>q2</code>.
        ///
        /// Both queries will be filtered by <code>filter</code>
        /// </summary>
        protected internal virtual void AssertSubsetOf(Query q1, Query q2, Filter filter)
        {
            // TRUNK ONLY: test both filter code paths
            if (filter != null && Random().NextBoolean())
            {
                q1 = new FilteredQuery(q1, filter, TestUtil.RandomFilterStrategy(Random()));
                q2 = new FilteredQuery(q2, filter, TestUtil.RandomFilterStrategy(Random()));
                filter = null;
            }

            // not efficient, but simple!
            TopDocs td1 = S1.Search(q1, filter, Reader.MaxDoc);
            TopDocs td2 = S2.Search(q2, filter, Reader.MaxDoc);
            Assert.IsTrue(td1.TotalHits <= td2.TotalHits);

            // fill the superset into a bitset
            var bitset = new BitArray(td2.ScoreDocs.Length);
            for (int i = 0; i < td2.ScoreDocs.Length; i++)
            {
                bitset.SafeSet(td2.ScoreDocs[i].Doc, true);
            }

            // check in the subset, that every bit was set by the super
            for (int i = 0; i < td1.ScoreDocs.Length; i++)
            {
                Assert.IsTrue(bitset.SafeGet(td1.ScoreDocs[i].Doc));
            }
        }
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:34,代码来源:SearchEquivalenceTestBase.cs


示例12: MakeQuery

		public override Query MakeQuery(SpatialArgs args)
		{
			// For starters, just limit the bbox
			var shape = args.GetShape();
			if (!(shape is Rectangle || shape is Circle))
				throw new InvalidShapeException("Only Rectangles and Circles are currently supported, found ["
					+ shape.GetType().Name + "]");//TODO

			Rectangle bbox = shape.GetBoundingBox();
			if (bbox.GetCrossesDateLine())
			{
				throw new InvalidOperationException("Crossing dateline not yet supported");
			}

			ValueSource valueSource = null;

			Query spatial = null;
			SpatialOperation op = args.Operation;

			if (SpatialOperation.Is(op,
				SpatialOperation.BBoxWithin,
				SpatialOperation.BBoxIntersects))
			{
				spatial = MakeWithin(bbox);
			}
			else if (SpatialOperation.Is(op,
			  SpatialOperation.Intersects,
			  SpatialOperation.IsWithin))
			{
				spatial = MakeWithin(bbox);
				var circle = args.GetShape() as Circle;
				if (circle != null)
				{
					// Make the ValueSource
					valueSource = MakeValueSource(args);

					var vsf = new ValueSourceFilter(
						new QueryWrapperFilter(spatial), valueSource, 0, circle.GetRadius());

					spatial = new FilteredQuery(new MatchAllDocsQuery(), vsf);
				}
			}
			else if (op == SpatialOperation.IsDisjointTo)
			{
				spatial = MakeDisjoint(bbox);
			}

			if (spatial == null)
			{
				throw new UnsupportedSpatialOperation(args.Operation);
			}

			if (valueSource != null)
			{
				valueSource = new CachingDoubleValueSource(valueSource);
			}
			else
			{
				valueSource = MakeValueSource(args);
			}
			Query spatialRankingQuery = new FunctionQuery(valueSource);
			var bq = new BooleanQuery();
			bq.Add(spatial, Occur.MUST);
			bq.Add(spatialRankingQuery, Occur.MUST);
			return bq;

		}
开发者ID:synhershko,项目名称:lucene.net,代码行数:67,代码来源:TwoDoublesStrategy.cs


示例13: VisitQuery

 private static void VisitQuery(FilteredQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     writer.WriteLine("Filter: {0}", (object)query.Filter);
     writer.WriteLine("Filtered query:");
     ++writer.Indent;
     AzureQueryLogger.Visit(query.Query, writer);
     --writer.Indent;
 }
开发者ID:jscott1277,项目名称:SitecoreAzureSearchProvider,代码行数:8,代码来源:AzureQueryLogger.cs


示例14: CanMixTermsWithAndWithoutFieldLabels

        public void CanMixTermsWithAndWithoutFieldLabels()
        {
            // arrange
            var owners = CreateOwnersResult(new Dictionary<string, HashSet<string>>
                {
                    {  "dot", new HashSet<string> { "microsoft" } }
                });

            var queryText = "dot owner:Microsoft";
            var expected = new FilteredQuery(
                new BooleanQuery
                {
                    new BooleanClause(new BooleanQuery { Clauses = { new BooleanClause(new TermQuery(new Term("Id", "dot")), Occur.SHOULD) }, Boost = 8 }, Occur.SHOULD),
                    new BooleanClause(new BooleanQuery { new BooleanClause(new TermQuery(new Term("ShingledId", "dot")), Occur.SHOULD) }, Occur.SHOULD),
                    new BooleanClause(new BooleanQuery { new BooleanClause(new TermQuery(new Term("TokenizedId", "dot")), Occur.SHOULD) }, Occur.SHOULD),
                    new BooleanClause(new BooleanQuery { new BooleanClause(new TermQuery(new Term("Version", "dot")), Occur.SHOULD) }, Occur.SHOULD),
                    new BooleanClause(new BooleanQuery { new BooleanClause(new TermQuery(new Term("Title", "dot")), Occur.SHOULD) }, Occur.SHOULD),
                    new BooleanClause(new BooleanQuery { new BooleanClause(new TermQuery(new Term("Description", "dot")), Occur.SHOULD) }, Occur.SHOULD),
                    new BooleanClause(new BooleanQuery { new BooleanClause(new TermQuery(new Term("Summary", "dot")), Occur.SHOULD) }, Occur.SHOULD),
                    new BooleanClause(new BooleanQuery { Clauses = { new BooleanClause(new TermQuery(new Term("Tags", "dot")), Occur.SHOULD) }, Boost = 2 }, Occur.SHOULD),
                    new BooleanClause(new BooleanQuery { new BooleanClause(new TermQuery(new Term("Authors", "dot")), Occur.SHOULD) }, Occur.SHOULD)
                },
                new OwnersFilter(owners, "Microsoft"));

            // act
            var actual = NuGetQuery.MakeQuery(queryText, owners);

            // assert
            Assert.Equal(expected.ToString(), actual.ToString());
        }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:30,代码来源:NuGetQueryTests.cs


示例15: AnonymousClassWeight

 public AnonymousClassWeight(Lucene.Net.Search.Weight weight, Lucene.Net.Search.Similarity similarity, FilteredQuery enclosingInstance)
 {
     InitBlock(weight, similarity, enclosingInstance);
 }
开发者ID:karino2,项目名称:wikipediaconv,代码行数:4,代码来源:FilteredQuery.cs


示例16: CreateQuery

        private Query CreateQuery()
        {
            CreatePendingClause();

            var booleanQuery = new BooleanQuery();
            Query resultQuery = booleanQuery;

            if (_clauses.Count == 0) {
                if (_filters.Count > 0) { // only filters applieds => transform to a boolean query
                    foreach (var clause in _filters) {
                        booleanQuery.Add(clause);
                    }

                    resultQuery = booleanQuery;
                }
                else { // search all documents, without filter or clause
                    resultQuery = new MatchAllDocsQuery(null);
                }
            }
            else {
                foreach (var clause in _clauses)
                    booleanQuery.Add(clause);

                if (_filters.Count > 0) {
                    var filter = new BooleanQuery();
                    foreach (var clause in _filters)
                        filter.Add(clause);
                    var queryFilter = new QueryWrapperFilter(filter);

                    resultQuery = new FilteredQuery(booleanQuery, queryFilter);
                }
            }

            Logger.Debug("New search query: {0}", resultQuery.ToString());
            return resultQuery;
        }
开发者ID:Timbioz,项目名称:SciGitAzure,代码行数:36,代码来源:LuceneSearchBuilder.cs


示例17: TChainedFilters

        private void TChainedFilters(bool useRandomAccess)
        {
            Query query = new FilteredQuery(new FilteredQuery(new MatchAllDocsQuery(), new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("field", "three")))), RandomFilterStrategy(Random(), useRandomAccess)), new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("field", "four")))), RandomFilterStrategy(Random(), useRandomAccess));
            ScoreDoc[] hits = Searcher.Search(query, 10).ScoreDocs;
            Assert.AreEqual(2, hits.Length);
            QueryUtils.Check(Random(), query, Searcher);

            // one more:
            query = new FilteredQuery(query, new CachingWrapperFilter(new QueryWrapperFilter(new TermQuery(new Term("field", "five")))), RandomFilterStrategy(Random(), useRandomAccess));
            hits = Searcher.Search(query, 10).ScoreDocs;
            Assert.AreEqual(1, hits.Length);
            QueryUtils.Check(Random(), query, Searcher);
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:13,代码来源:TestFilteredQuery.cs


示例18: Rewrite

        /// <summary>
        /// Rewrites the query. If the wrapped is an instance of
        /// <seealso cref="MatchAllDocsQuery"/> it returns a <seealso cref="ConstantScoreQuery"/>. Otherwise
        /// it returns a new {@code FilteredQuery} wrapping the rewritten query.
        /// </summary>
        public override Query Rewrite(IndexReader reader)
        {
            Query queryRewritten = Query_Renamed.Rewrite(reader);

            if (queryRewritten != Query_Renamed)
            {
                // rewrite to a new FilteredQuery wrapping the rewritten query
                Query rewritten = new FilteredQuery(queryRewritten, Filter_Renamed, strategy);
                rewritten.Boost = this.Boost;
                return rewritten;
            }
            else
            {
                // nothing to rewrite, we are done!
                return this;
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:22,代码来源:FilteredQuery.cs


示例19: TestLeapFrogStrategy

        public virtual void TestLeapFrogStrategy()
        {
            Directory directory = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            int numDocs = AtLeast(50);
            int totalDocsWithZero = 0;
            for (int i = 0; i < numDocs; i++)
            {
                Document doc = new Document();
                int num = Random().Next(10);
                if (num == 0)
                {
                    totalDocsWithZero++;
                }
                doc.Add(NewTextField("field", "" + num, Field.Store.YES));
                writer.AddDocument(doc);
            }
            IndexReader reader = writer.Reader;
            writer.Dispose();
            bool queryFirst = Random().NextBoolean();
            IndexSearcher searcher = NewSearcher(reader);
            Query query = new FilteredQuery(new TermQuery(new Term("field", "0")), new FilterAnonymousInnerClassHelper4(this, queryFirst), queryFirst ? FilteredQuery.LEAP_FROG_QUERY_FIRST_STRATEGY : Random()
                  .NextBoolean() ? FilteredQuery.RANDOM_ACCESS_FILTER_STRATEGY : FilteredQuery.LEAP_FROG_FILTER_FIRST_STRATEGY); // if filterFirst, we can use random here since bits are null

            TopDocs search = searcher.Search(query, 10);
            Assert.AreEqual(totalDocsWithZero, search.TotalHits);
            IOUtils.Close(reader, writer, directory);
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:28,代码来源:TestFilteredQuery.cs


示例20: TestQueryFirstFilterStrategy

        public virtual void TestQueryFirstFilterStrategy()
        {
            Directory directory = NewDirectory();
            RandomIndexWriter writer = new RandomIndexWriter(Random(), directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(Random())));
            int numDocs = AtLeast(50);
            int totalDocsWithZero = 0;
            for (int i = 0; i < numDocs; i++)
            {
                Document doc = new Document();
                int num = Random().Next(5);
                if (num == 0)
                {
                    totalDocsWithZero++;
                }
                doc.Add(NewTextField("field", "" + num, Field.Store.YES));
                writer.AddDocument(doc);
            }
            IndexReader reader = writer.Reader;
            writer.Dispose();

            IndexSearcher searcher = NewSearcher(reader);
            Query query = new FilteredQuery(new TermQuery(new Term("field", "0")), new FilterAnonymousInnerClassHelper3(this, reader), FilteredQuery.QUERY_FIRST_FILTER_STRATEGY);

            TopDocs search = searcher.Search(query, 10);
            Assert.AreEqual(totalDocsWithZero, search.TotalHits);
            IOUtils.Close(reader, writer, directory);
        }
开发者ID:joyanta,项目名称:lucene.net,代码行数:27,代码来源:TestFilteredQuery.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Search.HitCollector类代码示例发布时间:2022-05-26
下一篇:
C# Search.Filter类代码示例发布时间: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