コード例 #1
0
            public override Query Rewrite(IndexReader reader, MultiTermQuery query)
            {
                FilteredTermEnum enumerator = query.GetEnum(reader);
                BooleanQuery     result     = new BooleanQuery(true);
                int count = 0;

                try
                {
                    do
                    {
                        Term t = enumerator.Term;
                        if (t != null)
                        {
                            TermQuery tq = new TermQuery(t);                  // found a match
                            tq.Boost = query.Boost * enumerator.Difference(); // set the boost
                            result.Add(tq, Occur.SHOULD);                     // add to query
                            count++;
                        }
                    }while (enumerator.Next());
                }
                finally
                {
                    enumerator.Close();
                }
                query.IncTotalNumberOfTerms(count);
                return(result);
            }
コード例 #2
0
        private int CountTerms(MultiTermQuery q)
        {
            Terms terms = MultiFields.GetTerms(reader, q.Field);

            if (terms == null)
            {
                return(0);
            }
            TermsEnum termEnum = q.GetTermsEnum(terms);

            Assert.IsNotNull(termEnum);
            int      count = 0;
            BytesRef cur, last = null;

            while ((cur = termEnum.Next()) != null)
            {
                count++;
                if (last != null)
                {
                    Assert.IsTrue(last.CompareTo(cur) < 0);
                }
                last = BytesRef.DeepCopyOf(cur);
            }
            // LUCENE-3314: the results after next() already returned null are undefined,
            // Assert.IsNull(termEnum.Next());
            return(count);
        }
コード例 #3
0
        public override Query Rewrite(IndexReader reader, MultiTermQuery query)
        {
            Query result = new ConstantScoreQuery(new MultiTermQueryFieldCacheWrapperFilter(query));

            result.Boost = query.Boost;
            return(result);
        }
コード例 #4
0
ファイル: MultiTermQuery.cs プロジェクト: pchaozhong/FlexNet
            public override Query Rewrite(IndexReader reader, MultiTermQuery query)
            {
                Query result = new ConstantScoreQuery(new MultiTermQueryWrapperFilter(query));

                result.SetBoost(query.GetBoost());
                return(result);
            }
コード例 #5
0
        public override bool Equals(object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (this.GetType() != obj.GetType())
            {
                return(false);
            }
            MultiTermQuery other = (MultiTermQuery)obj;

            if (Number.SingleToInt32Bits(Boost) != Number.SingleToInt32Bits(other.Boost))
            {
                return(false);
            }
            if (!m_rewriteMethod.Equals(other.m_rewriteMethod))
            {
                return(false);
            }
            return(other.m_field == null ? m_field == null : other.m_field.Equals(m_field, StringComparison.Ordinal));
        }
コード例 #6
0
            public override Query Rewrite(IndexReader reader, MultiTermQuery query)
            {
                // Get the enum and start visiting terms.  If we
                // exhaust the enum before hitting either of the
                // cutoffs, we use ConstantBooleanQueryRewrite; else,
                // ConstantFilterRewrite:
                System.Collections.ArrayList pendingTerms = new System.Collections.ArrayList();
                int docCountCutoff = (int)((docCountPercent / 100.0) * reader.MaxDoc());
                int termCountLimit = System.Math.Min(BooleanQuery.GetMaxClauseCount(), termCountCutoff);
                int docVisitCount  = 0;

                FilteredTermEnum enumerator = query.GetEnum(reader);

                try
                {
                    while (true)
                    {
                        Term t = enumerator.Term();
                        if (t != null)
                        {
                            pendingTerms.Add(t);
                            // Loading the TermInfo from the terms dict here
                            // should not be costly, because 1) the
                            // query/filter will load the TermInfo when it
                            // runs, and 2) the terms dict has a cache:
                            docVisitCount += reader.DocFreq(t);
                        }

                        if (pendingTerms.Count >= termCountLimit || docVisitCount >= docCountCutoff)
                        {
                            // Too many terms -- make a filter.
                            Query result = new ConstantScoreQuery(new MultiTermQueryWrapperFilter(query));
                            result.SetBoost(query.GetBoost());
                            return(result);
                        }
                        else if (!enumerator.Next())
                        {
                            // Enumeration is done, and we hit a small
                            // enough number of terms & docs -- just make a
                            // BooleanQuery, now
                            System.Collections.IEnumerator it = pendingTerms.GetEnumerator();
                            BooleanQuery bq = new BooleanQuery(true);
                            while (it.MoveNext())
                            {
                                TermQuery tq = new TermQuery((Term)it.Current);
                                bq.Add(tq, BooleanClause.Occur.SHOULD);
                            }
                            // Strip scores
                            Query result = new ConstantScoreQuery(new QueryWrapperFilter(bq));
                            result.SetBoost(query.GetBoost());
                            query.IncTotalNumberOfTerms(pendingTerms.Count);
                            return(result);
                        }
                    }
                }
                finally
                {
                    enumerator.Close();
                }
            }
コード例 #7
0
        public override Query Rewrite(IndexReader reader, MultiTermQuery query)
        {
            var result = GetTopLevelQuery();
            ParallelArraysTermCollector col = new ParallelArraysTermCollector(this);

            CollectTerms(reader, query, col);

            int size = col.terms.Count;

            if (size > 0)
            {
                int[]         sort       = col.terms.Sort(col.termsEnum.Comparer);
                float[]       boost      = col.array.boost;
                TermContext[] termStates = col.array.termState;
                for (int i = 0; i < size; i++)
                {
                    int  pos  = sort[i];
                    Term term = new Term(query.Field, col.terms.Get(pos, new BytesRef()));
                    if (Debugging.AssertsEnabled)
                    {
                        Debugging.Assert(reader.DocFreq(term) == termStates[pos].DocFreq);
                    }
                    AddClause(result, term, termStates[pos].DocFreq, query.Boost * boost[pos], termStates[pos]);
                }
            }
            return(result);
        }
コード例 #8
0
        //@Override
        public override bool Equals(System.Object obj)
        {
            if (this == obj)
            {
                return(true);
            }
            if (obj == null)
            {
                return(false);
            }
            if (GetType() != obj.GetType())
            {
                return(false);
            }
            MultiTermQuery other = (MultiTermQuery)obj;

            if (System.Convert.ToInt32(Boost) != System.Convert.ToInt32(other.Boost))
            {
                return(false);
            }
            if (!internalRewriteMethod.Equals(other.internalRewriteMethod))
            {
                return(false);
            }
            return(true);
        }
コード例 #9
0
            public override Query Rewrite(IndexReader reader, MultiTermQuery query, IState state)
            {
                // strip the scores off
                Query result = new ConstantScoreQuery(new QueryWrapperFilter(base.Rewrite(reader, query, state)));

                result.Boost = query.Boost;
                return(result);
            }
コード例 #10
0
            public override Query Rewrite(IndexReader reader, MultiTermQuery query)
            {
                // strip the scores off
                Query result = new ConstantScoreQuery(new QueryWrapperFilter(base.Rewrite(reader, query)));

                result.SetBoost(query.GetBoost());
                return(result);
            }
コード例 #11
0
            public override Query Rewrite(IndexReader reader, MultiTermQuery query)
            {
                BooleanQuery bq = (BooleanQuery)SCORING_BOOLEAN_QUERY_REWRITE.Rewrite(reader, query);
                // strip the scores off
                Query result = new ConstantScoreQuery(bq);

                result.Boost = query.Boost;
                return(result);
            }
コード例 #12
0
        internal void CollectTerms(IndexReader reader, MultiTermQuery query, TermCollector collector)
        {
            IndexReaderContext   topReaderContext = reader.Context;
            IComparer <BytesRef> lastTermComp     = null;

            foreach (AtomicReaderContext context in topReaderContext.Leaves)
            {
                Fields fields = context.AtomicReader.Fields;
                if (fields == null)
                {
                    // reader has no fields
                    continue;
                }

                Terms terms = fields.GetTerms(query.m_field);
                if (terms == null)
                {
                    // field does not exist
                    continue;
                }

                TermsEnum termsEnum = GetTermsEnum(query, terms, collector.Attributes);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(termsEnum != null);
                }

                if (termsEnum == TermsEnum.EMPTY)
                {
                    continue;
                }

                // Check comparer compatibility:
                IComparer <BytesRef> newTermComp = termsEnum.Comparer;
                if (lastTermComp != null && newTermComp != null && newTermComp != lastTermComp)
                {
                    throw new Exception("term comparer should not change between segments: " + lastTermComp + " != " + newTermComp);
                }
                lastTermComp = newTermComp;
                collector.SetReaderContext(topReaderContext, context);
                collector.SetNextEnum(termsEnum);
                BytesRef bytes;
                while ((bytes = termsEnum.Next()) != null)
                {
                    if (!collector.Collect(bytes))
                    {
                        return; // interrupt whole term collection, so also don't iterate other subReaders
                    }
                }
            }
        }
コード例 #13
0
        private void CheckNoMaxClauseLimitation(MultiTermQuery.RewriteMethod method)
        {
            int savedMaxClauseCount = BooleanQuery.MaxClauseCount;

            BooleanQuery.MaxClauseCount = 3;

            MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);

            mtq.MultiTermRewriteMethod = (method);
            try
            {
                MultiSearcherDupls.Rewrite(mtq);
            }
            finally
            {
                BooleanQuery.MaxClauseCount = savedMaxClauseCount;
            }
        }
コード例 #14
0
            public virtual void Generate(MultiTermQuery query, IndexReader reader, TermEnum enumerator)
            {
                int[]    docs     = new int[32];
                int[]    freqs    = new int[32];
                TermDocs termDocs = reader.TermDocs();

                try
                {
                    int termCount = 0;
                    do
                    {
                        Term term = enumerator.Term();
                        if (term == null)
                        {
                            break;
                        }
                        termCount++;
                        termDocs.Seek(term);
                        while (true)
                        {
                            int count = termDocs.Read(docs, freqs);
                            if (count != 0)
                            {
                                for (int i = 0; i < count; i++)
                                {
                                    HandleDoc(docs[i]);
                                }
                            }
                            else
                            {
                                break;
                            }
                        }
                    }while (enumerator.Next());

                    query.IncTotalNumberOfTerms(termCount);                     // {{Aroush-2.9}} is the use of 'temp' as is right?
                }
                finally
                {
                    termDocs.Close();
                }
            }
コード例 #15
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (!(o is MultiTermQuery))
            {
                return(false);
            }

            MultiTermQuery multiTermQuery = (MultiTermQuery)o;

            if (!term.Equals(multiTermQuery.term))
            {
                return(false);
            }

            return(GetBoost() == multiTermQuery.GetBoost());
        }
コード例 #16
0
ファイル: TopTermsRewrite.cs プロジェクト: segovia/lucenenet
        public override Query Rewrite(IndexReader reader, MultiTermQuery query)
        {
            int maxSize = Math.Min(size, MaxSize);

            JCG.PriorityQueue <ScoreTerm> stQueue = new JCG.PriorityQueue <ScoreTerm>();
            CollectTerms(reader, query, new TermCollectorAnonymousInnerClassHelper(this, maxSize, stQueue));

            var q = GetTopLevelQuery();

            ScoreTerm[] scoreTerms = stQueue.ToArray(/*new ScoreTerm[stQueue.size()]*/);
            ArrayUtil.TimSort(scoreTerms, scoreTermSortByTermComp);

            foreach (ScoreTerm st in scoreTerms)
            {
                Term term = new Term(query.m_field, st.Bytes);
                Debug.Assert(reader.DocFreq(term) == st.TermState.DocFreq, "reader DF is " + reader.DocFreq(term) + " vs " + st.TermState.DocFreq + " term=" + term);
                AddClause(q, term, st.TermState.DocFreq, query.Boost * st.Boost, st.TermState); // add to query
            }
            return(q);
        }
コード例 #17
0
        public override Query Rewrite(IndexReader reader, MultiTermQuery query)
        {
            // Get the enum and start visiting terms.  If we
            // exhaust the enum before hitting either of the
            // cutoffs, we use ConstantBooleanQueryRewrite; else,
            // ConstantFilterRewrite:
            int docCountCutoff = (int)((docCountPercent / 100.0) * reader.MaxDoc);
            int termCountLimit = Math.Min(BooleanQuery.MaxClauseCount, termCountCutoff);

            CutOffTermCollector col = new CutOffTermCollector(docCountCutoff, termCountLimit);

            CollectTerms(reader, query, col);
            int size = col.pendingTerms.Count;

            if (col.hasCutOff)
            {
                return(MultiTermQuery.CONSTANT_SCORE_FILTER_REWRITE.Rewrite(reader, query));
            }
            else
            {
                BooleanQuery bq = GetTopLevelQuery();
                if (size > 0)
                {
                    BytesRefHash pendingTerms = col.pendingTerms;
                    int[]        sort         = pendingTerms.Sort(col.termsEnum.Comparer);
                    for (int i = 0; i < size; i++)
                    {
                        int pos = sort[i];
                        // docFreq is not used for constant score here, we pass 1
                        // to explicitely set a fake value, so it's not calculated
                        AddClause(bq, new Term(query.m_field, pendingTerms.Get(pos, new BytesRef())), 1, 1.0f, col.array.termState[pos]);
                    }
                }
                // Strip scores
                Query result = new ConstantScoreQuery(bq);
                result.Boost = query.Boost;
                return(result);
            }
        }
コード例 #18
0
        private void CheckDuplicateTerms(MultiTermQuery.RewriteMethod method)
        {
            MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);

            mtq.MultiTermRewriteMethod = (method);
            Query q1 = Searcher.Rewrite(mtq);
            Query q2 = MultiSearcher.Rewrite(mtq);
            Query q3 = MultiSearcherDupls.Rewrite(mtq);

            if (VERBOSE)
            {
                Console.WriteLine();
                Console.WriteLine("single segment: " + q1);
                Console.WriteLine("multi segment: " + q2);
                Console.WriteLine("multi segment with duplicates: " + q3);
            }
            Assert.IsTrue(q1.Equals(q2), "The multi-segment case must produce same rewritten query");
            Assert.IsTrue(q1.Equals(q3), "The multi-segment case with duplicates must produce same rewritten query");
            CheckBooleanQueryOrder(q1);
            CheckBooleanQueryOrder(q2);
            CheckBooleanQueryOrder(q3);
        }
コード例 #19
0
        public override Query Rewrite(IndexReader reader, MultiTermQuery query)
        {
            int maxSize = Math.Min(size, MaxSize);

            JCG.PriorityQueue <ScoreTerm> stQueue = new JCG.PriorityQueue <ScoreTerm>();
            CollectTerms(reader, query, new TermCollectorAnonymousClass(maxSize, stQueue));

            var q = GetTopLevelQuery();

            ScoreTerm[] scoreTerms = stQueue.ToArray(/*new ScoreTerm[stQueue.Count]*/);

            ArrayUtil.TimSort(scoreTerms, scoreTermSortByTermComp);

            foreach (ScoreTerm st in scoreTerms)
            {
                Term term = new Term(query.m_field, st.Bytes);
                if (Debugging.AssertsEnabled)
                {
                    Debugging.Assert(reader.DocFreq(term) == st.TermState.DocFreq, "reader DF is {0} vs {1} term={2}", reader.DocFreq(term), st.TermState.DocFreq, term);
                }
                AddClause(q, term, st.TermState.DocFreq, query.Boost * st.Boost, st.TermState); // add to query
            }
            return(q);
        }
コード例 #20
0
        private void CheckMaxClauseLimitation(MultiTermQuery.RewriteMethod method, [CallerMemberName] string memberName = "")
        {
            int savedMaxClauseCount = BooleanQuery.MaxClauseCount;

            BooleanQuery.MaxClauseCount = 3;

            MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);

            mtq.MultiTermRewriteMethod = (method);
            try
            {
                MultiSearcherDupls.Rewrite(mtq);
                Assert.Fail("Should throw BooleanQuery.TooManyClauses");
            }
            catch (BooleanQuery.TooManyClausesException e)
            {
                //  Maybe remove this assert in later versions, when internal API changes:
                Assert.AreEqual("CheckMaxClauseCount", new StackTrace(e, false).GetFrames()[0].GetMethod().Name); //, "Should throw BooleanQuery.TooManyClauses with a stacktrace containing checkMaxClauseCount()");
            }
            finally
            {
                BooleanQuery.MaxClauseCount = savedMaxClauseCount;
            }
        }
コード例 #21
0
 private void CheckBoosts(MultiTermQuery.RewriteMethod method)
 {
     MultiTermQuery mtq = new MultiTermQueryAnonymousInnerClassHelper(this);
     mtq.SetRewriteMethod(method);
     Query q1 = Searcher.Rewrite(mtq);
     Query q2 = MultiSearcher.Rewrite(mtq);
     Query q3 = MultiSearcherDupls.Rewrite(mtq);
     if (VERBOSE)
     {
         Console.WriteLine();
         Console.WriteLine("single segment: " + q1);
         Console.WriteLine("multi segment: " + q2);
         Console.WriteLine("multi segment with duplicates: " + q3);
     }
     Assert.IsTrue(q1.Equals(q2), "The multi-segment case must produce same rewritten query");
     Assert.IsTrue(q1.Equals(q3), "The multi-segment case with duplicates must produce same rewritten query");
     CheckBooleanQueryBoosts((BooleanQuery)q1);
     CheckBooleanQueryBoosts((BooleanQuery)q2);
     CheckBooleanQueryBoosts((BooleanQuery)q3);
 }
コード例 #22
0
 private void CheckDuplicateTerms(MultiTermQuery.RewriteMethod method)
 {
     MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);
     mtq.SetRewriteMethod(method);
     Query q1 = Searcher.Rewrite(mtq);
     Query q2 = MultiSearcher.Rewrite(mtq);
     Query q3 = MultiSearcherDupls.Rewrite(mtq);
     if (VERBOSE)
     {
         Console.WriteLine();
         Console.WriteLine("single segment: " + q1);
         Console.WriteLine("multi segment: " + q2);
         Console.WriteLine("multi segment with duplicates: " + q3);
     }
     Assert.IsTrue(q1.Equals(q2), "The multi-segment case must produce same rewritten query");
     Assert.IsTrue(q1.Equals(q3), "The multi-segment case with duplicates must produce same rewritten query");
     CheckBooleanQueryOrder(q1);
     CheckBooleanQueryOrder(q2);
     CheckBooleanQueryOrder(q3);
 }
コード例 #23
0
ファイル: QueryTranslator.cs プロジェクト: daszat/zetbox
 private MultiTermQuery VisitNumericRangeQuery(MultiTermQuery n)
 {
     if (n is NumericRangeQuery<double>)
     {
         var q = (NumericRangeQuery<double>)n;
         return NumericRangeQuery.NewDoubleRange(VisitField(q.Field), q.Min, q.Max, q.IncludesMin, q.IncludesMax);
     }
     else if (n is NumericRangeQuery<float>)
     {
         var q = (NumericRangeQuery<float>)n;
         return NumericRangeQuery.NewFloatRange(VisitField(q.Field), q.Min, q.Max, q.IncludesMin, q.IncludesMax);
     }
     else if (n is NumericRangeQuery<int>)
     {
         var q = (NumericRangeQuery<int>)n;
         return NumericRangeQuery.NewIntRange(VisitField(q.Field), q.Min, q.Max, q.IncludesMin, q.IncludesMax);
     }
     else if (n is NumericRangeQuery<long>)
     {
         var q = (NumericRangeQuery<long>)n;
         return NumericRangeQuery.NewLongRange(VisitField(q.Field), q.Min, q.Max, q.IncludesMin, q.IncludesMax);
     }
     else
     {
         throw new NotSupportedException(string.Format("Numeric range of type '{0}' is not supported", n.GetType().FullName));
     }
 }
コード例 #24
0
 private static void VisitQuery(MultiTermQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     writer.WriteLine("TotalNumberOfTerms: {0}", (object)query.TotalNumberOfTerms);
     if (query is FuzzyQuery)
         AzureQueryLogger.MultiTermQuery((FuzzyQuery)query, writer);
     else if (query is PrefixQuery)
         AzureQueryLogger.MultiTermQuery((PrefixQuery)query, writer);
     else if (query is TermRangeQuery)
         AzureQueryLogger.MultiTermQuery((TermRangeQuery)query, writer);
     else if (query is WildcardQuery)
     {
         AzureQueryLogger.MultiTermQuery((WildcardQuery)query, writer);
     }
     else
     {
         if (!(query is RegexQuery))
             return;
         AzureQueryLogger.MultiTermQuery((RegexQuery)query, writer);
     }
 }
コード例 #25
0
			public override Query Rewrite(IndexReader reader, MultiTermQuery query)
			{
				Query result = new ConstantScoreQuery(new MultiTermQueryWrapperFilter(query));
				result.SetBoost(query.GetBoost());
				return result;
			}
コード例 #26
0
 public override Query Rewrite(IndexReader reader, MultiTermQuery query)
 {
     Query result = new ConstantScoreQuery(new MultiTermQueryDocTermOrdsWrapperFilter(query));
     result.Boost = query.Boost;
     return result;
 }
コード例 #27
0
 private int CountTerms(MultiTermQuery q)
 {
     Terms terms = MultiFields.GetTerms(Reader, q.Field);
     if (terms == null)
     {
         return 0;
     }
     TermsEnum termEnum = q.GetTermsEnum(terms);
     Assert.IsNotNull(termEnum);
     int count = 0;
     BytesRef cur, last = null;
     while ((cur = termEnum.Next()) != null)
     {
         count++;
         if (last != null)
         {
             Assert.IsTrue(last.CompareTo(cur) < 0);
         }
         last = BytesRef.DeepCopyOf(cur);
     }
     // LUCENE-3314: the results after next() already returned null are undefined,
     // Assert.IsNull(termEnum.Next());
     return count;
 }
コード例 #28
0
 /// <summary>
 /// Wrap a <see cref="MultiTermQuery"/> as a <see cref="Filter"/>.
 /// </summary>
 protected internal MultiTermQueryDocTermOrdsWrapperFilter(MultiTermQuery query)
 {
     this.m_query = query;
 }
コード例 #29
0
		public static Query Csrq(System.String f, System.String l, System.String h, bool il, bool ih, MultiTermQuery.RewriteMethod method)
		{
			TermRangeQuery query = new TermRangeQuery(f, l, h, il, ih);
			query.SetRewriteMethod(method);
			return query;
		}
コード例 #30
0
        private void CheckMaxClauseLimitation(MultiTermQuery.RewriteMethod method)
        {
            int savedMaxClauseCount = BooleanQuery.MaxClauseCount;
            BooleanQuery.MaxClauseCount = 3;

            MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);
            mtq.SetRewriteMethod(method);
            try
            {
                MultiSearcherDupls.Rewrite(mtq);
                Assert.Fail("Should throw BooleanQuery.TooManyClauses");
            }
            catch (BooleanQuery.TooManyClauses e)
            {
                //  Maybe remove this assert in later versions, when internal API changes:
                Assert.AreEqual("CheckMaxClauseCount", new StackTrace(e).GetFrames()[0].GetMethod().Name, "Should throw BooleanQuery.TooManyClauses with a stacktrace containing checkMaxClauseCount()");
            }
            finally
            {
                BooleanQuery.MaxClauseCount = savedMaxClauseCount;
            }
        }
コード例 #31
0
 public abstract Query Rewrite(IndexReader reader, MultiTermQuery query);
コード例 #32
0
		/// <summary> Wrap a {@link MultiTermQuery} as a Filter.</summary>
		protected internal MultiTermQueryWrapperFilter(MultiTermQuery query)
		{
			this.query = query;
		}
コード例 #33
0
 public abstract Query Rewrite(IndexReader reader, MultiTermQuery query, IState state);
コード例 #34
0
 public override Query Rewrite(IndexReader reader, MultiTermQuery query)
 {
     Query result = new ConstantScoreQuery(new MultiTermQueryDocTermOrdsWrapperFilter(query));
     result.Boost = query.Boost;
     return result;
 }
コード例 #35
0
        private void CheckNoMaxClauseLimitation(MultiTermQuery.RewriteMethod method)
        {
            int savedMaxClauseCount = BooleanQuery.MaxClauseCount;
            BooleanQuery.MaxClauseCount = 3;

            MultiTermQuery mtq = TermRangeQuery.NewStringRange("data", "2", "7", true, true);
            mtq.SetRewriteMethod(method);
            try
            {
                MultiSearcherDupls.Rewrite(mtq);
            }
            finally
            {
                BooleanQuery.MaxClauseCount = savedMaxClauseCount;
            }
        }
コード例 #36
0
 /// <summary>
 /// Wrap a <see cref="MultiTermQuery"/> as a Filter.
 /// </summary>
 protected internal MultiTermQueryFieldCacheWrapperFilter(MultiTermQuery query)
 {
     this.m_query = query;
 }
コード例 #37
0
 /// <summary> Wrap a {@link MultiTermQuery} as a Filter.</summary>
 protected internal MultiTermQueryWrapperFilter(MultiTermQuery query)
 {
     this.query = query;
 }
コード例 #38
0
			public override Query Rewrite(IndexReader reader, MultiTermQuery query)
			{
				
				FilteredTermEnum enumerator = query.GetEnum(reader);
				BooleanQuery result = new BooleanQuery(true);
				int count = 0;
				try
				{
					do 
					{
						Term t = enumerator.Term();
						if (t != null)
						{
							TermQuery tq = new TermQuery(t); // found a match
							tq.SetBoost(query.GetBoost() * enumerator.Difference()); // set the boost
							result.Add(tq, BooleanClause.Occur.SHOULD); // add to query
							count++;
						}
					}
					while (enumerator.Next());
				}
				finally
				{
					enumerator.Close();
				}
				query.IncTotalNumberOfTerms(count);
				return result;
			}
コード例 #39
0
 /// <summary>
 /// Wrap a <seealso cref="MultiTermQuery"/> as a Filter.
 /// </summary>
 protected internal MultiTermQueryFieldCacheWrapperFilter(MultiTermQuery query)
 {
     this.Query = query;
 }
コード例 #40
0
			public override Query Rewrite(IndexReader reader, MultiTermQuery query)
			{
				// strip the scores off
				Query result = new ConstantScoreQuery(new QueryWrapperFilter(base.Rewrite(reader, query)));
				result.SetBoost(query.GetBoost());
				return result;
			}
コード例 #41
0
			public override Query Rewrite(IndexReader reader, MultiTermQuery query)
			{
				// Get the enum and start visiting terms.  If we
				// exhaust the enum before hitting either of the
				// cutoffs, we use ConstantBooleanQueryRewrite; else,
				// ConstantFilterRewrite:
				System.Collections.ArrayList pendingTerms = new System.Collections.ArrayList();
				int docCountCutoff = (int) ((docCountPercent / 100.0) * reader.MaxDoc());
				int termCountLimit = System.Math.Min(BooleanQuery.GetMaxClauseCount(), termCountCutoff);
				int docVisitCount = 0;
				
				FilteredTermEnum enumerator = query.GetEnum(reader);
				try
				{
					while (true)
					{
						Term t = enumerator.Term();
						if (t != null)
						{
							pendingTerms.Add(t);
							// Loading the TermInfo from the terms dict here
							// should not be costly, because 1) the
							// query/filter will load the TermInfo when it
							// runs, and 2) the terms dict has a cache:
							docVisitCount += reader.DocFreq(t);
						}
						
						if (pendingTerms.Count >= termCountLimit || docVisitCount >= docCountCutoff)
						{
							// Too many terms -- make a filter.
							Query result = new ConstantScoreQuery(new MultiTermQueryWrapperFilter(query));
							result.SetBoost(query.GetBoost());
							return result;
						}
						else if (!enumerator.Next())
						{
							// Enumeration is done, and we hit a small
							// enough number of terms & docs -- just make a
							// BooleanQuery, now
							System.Collections.IEnumerator it = pendingTerms.GetEnumerator();
							BooleanQuery bq = new BooleanQuery(true);
							while (it.MoveNext())
							{
								TermQuery tq = new TermQuery((Term) it.Current);
								bq.Add(tq, BooleanClause.Occur.SHOULD);
							}
							// Strip scores
							Query result = new ConstantScoreQuery(new QueryWrapperFilter(bq));
							result.SetBoost(query.GetBoost());
							query.IncTotalNumberOfTerms(pendingTerms.Count);
							return result;
						}
					}
				}
				finally
				{
					enumerator.Close();
				}
			}
コード例 #42
0
			public abstract Query Rewrite(IndexReader reader, MultiTermQuery query);
コード例 #43
0
            public virtual void Generate(MultiTermQuery query, IndexReader reader, TermEnum enumerator)
			{
				int[] docs = new int[32];
				int[] freqs = new int[32];
				TermDocs termDocs = reader.TermDocs();
				try
				{
					int termCount = 0;
					do 
					{
						Term term = enumerator.Term();
						if (term == null)
							break;
						termCount++;
						termDocs.Seek(term);
						while (true)
						{
							int count = termDocs.Read(docs, freqs);
							if (count != 0)
							{
								for (int i = 0; i < count; i++)
								{
									HandleDoc(docs[i]);
								}
							}
							else
							{
								break;
							}
						}
					}
					while (enumerator.Next());
					
					query.IncTotalNumberOfTerms(termCount); // {{Aroush-2.9}} is the use of 'temp' as is right?
				}
				finally
				{
					termDocs.Close();
				}
			}
コード例 #44
0
 /// <summary>
 /// Wrap a <seealso cref="MultiTermQuery"/> as a Filter.
 /// </summary>
 protected internal MultiTermQueryDocTermOrdsWrapperFilter(MultiTermQuery query)
 {
     this.Query = query;
 }
コード例 #45
0
 /// <summary>
 /// Returns the <see cref="MultiTermQuery"/>s <see cref="TermsEnum"/> </summary>
 /// <seealso cref="MultiTermQuery.GetTermsEnum(Terms, AttributeSource)"/>
 protected virtual TermsEnum GetTermsEnum(MultiTermQuery query, Terms terms, AttributeSource atts)
 {
     return(query.GetTermsEnum(terms, atts)); // allow RewriteMethod subclasses to pull a TermsEnum from the MTQ
 }
コード例 #46
0
 public static Query Csrq(string f, string l, string h, bool il, bool ih, MultiTermQuery.RewriteMethod method)
 {
     TermRangeQuery query = TermRangeQuery.NewStringRange(f, l, h, il, ih);
     query.SetRewriteMethod(method);
     if (VERBOSE)
     {
         Console.WriteLine("TEST: query=" + query + " method=" + method);
     }
     return query;
 }