Esempio n. 1
0
			public TermWeight(TermQuery enclosingInstance, Searcher searcher)
			{
				InitBlock(enclosingInstance);
				this.similarity = Enclosing_Instance.GetSimilarity(searcher);
				idfExp = similarity.IdfExplain(Enclosing_Instance.term, searcher);
				idf = idfExp.Idf;
			}
Esempio n. 2
0
 public static Query CreateQuery(string name, string type, object value) {
     Query query;
     switch (type) {
         case "byte":
             query = NumericRangeQuery.NewIntRange(name, Convert.ToInt32(value), Convert.ToInt32(value), true, true);
             break;
         case "int16":
             query = NumericRangeQuery.NewIntRange(name, Convert.ToInt32(value), Convert.ToInt32(value), true, true);
             break;
         case "int":
             var intValue = (int)value;
             query = NumericRangeQuery.NewIntRange(name, intValue, intValue, true, true);
             break;
         case "int32":
             var int32Value = (int)value;
             query = NumericRangeQuery.NewIntRange(name, int32Value, int32Value, true, true);
             break;
         case "int64":
             var int64Value = (long)value;
             query = NumericRangeQuery.NewLongRange(name, int64Value, int64Value, true, true);
             break;
         case "long":
             var longValue = (long)value;
             query = NumericRangeQuery.NewLongRange(name, longValue, longValue, true, true);
             break;
         case "double":
             var doubleValue = (double)value;
             query = NumericRangeQuery.NewDoubleRange(name, doubleValue, doubleValue, true, true);
             break;
         case "float":
             var floatValue = (float)value;
             query = NumericRangeQuery.NewFloatRange(name, floatValue, floatValue, true, true);
             break;
         case "datetime":
             var datetimeValue = ((DateTime)value).Ticks;
             query = NumericRangeQuery.NewLongRange(name, datetimeValue, datetimeValue, true, true);
             break;
         case "string":
             query = new TermQuery(new Term((string)value));
             break;
         case "byte[]":
             query = new TermQuery(new Term(Common.BytesToHexString((byte[])value)));
             break;
         case "rowversion":
             query = new TermQuery(new Term(Common.BytesToHexString((byte[])value)));
             break;
         default:
             query = new TermQuery(new Term(name, Convert.ToString(value)));
             break;
     }
     return query;
 }
Esempio n. 3
0
        public override int NextBatchId(string processName) {
            if (!TflBatchRecordsExist(processName)) {
                return 1;
            }
            using (var searcher = LuceneSearcherFactory.Create(this, TflBatchEntity(processName))) {

                var query = new TermQuery(new Term("process", processName));
                var sort = new Sort(new SortField("id", SortField.INT, true));
                var hits = searcher.Search(query, null, 1, sort);

                if (hits.TotalHits <= 0)
                    return 1;

                var doc = searcher.Doc(0);
                return Convert.ToInt32(doc.GetField("id").StringValue) + 1;
            }
        }
Esempio n. 4
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:
				ICollection<Term> pendingTerms = new List<Term>();
				int docCountCutoff = (int) ((docCountPercent / 100.0) * reader.MaxDoc);
				int termCountLimit = System.Math.Min(BooleanQuery.MaxClauseCount, 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<MultiTermQuery>(query));
							result.Boost = query.Boost;
							return result;
						}
						else if (!enumerator.Next())
						{
							// Enumeration is done, and we hit a small
							// enough number of terms & docs -- just make a
							// BooleanQuery, now
							BooleanQuery bq = new BooleanQuery(true);
							foreach(Term term in pendingTerms)
							{
								TermQuery tq = new TermQuery(term);
								bq.Add(tq, Occur.SHOULD);
							}
							// Strip scores
							Query result = new ConstantScoreQuery(new QueryWrapperFilter(bq));
							result.Boost = query.Boost;
							query.IncTotalNumberOfTerms(pendingTerms.Count);
							return result;
						}
					}
				}
				finally
				{
					enumerator.Close();
				}
			}
Esempio n. 5
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;
			}
Esempio n. 6
0
        public override Query Rewrite(IndexReader reader)
        {
            if (!termLongEnough)
            {
                // can only match if it's exact
                return(new TermQuery(Term));
            }

            int maxSize = BooleanQuery.MaxClauseCount;

            // TODO: Java uses a PriorityQueue.  Using Linq, we can emulate it,
            //       however it's considerable slower than the java counterpart.
            //       this should be a temporary thing, fixed before release
            SortedList <ScoreTerm, ScoreTerm> stQueue = new SortedList <ScoreTerm, ScoreTerm>();
            FilteredTermEnum enumerator = GetEnum(reader);

            try
            {
                ScoreTerm st = new ScoreTerm();
                do
                {
                    Term t = enumerator.Term;
                    if (t == null)
                    {
                        break;
                    }
                    float score = enumerator.Difference();
                    //ignore uncompetetive hits
                    if (stQueue.Count >= maxSize && score <= stQueue.Keys.First().score)
                    {
                        continue;
                    }
                    // add new entry in PQ
                    st.term  = t;
                    st.score = score;
                    stQueue.Add(st, st);
                    // possibly drop entries from queue
                    if (stQueue.Count > maxSize)
                    {
                        st = stQueue.Keys.First();
                        stQueue.Remove(st);
                    }
                    else
                    {
                        st = new ScoreTerm();
                    }
                }while (enumerator.Next());
            }
            finally
            {
                enumerator.Close();
            }

            BooleanQuery query = new BooleanQuery(true);

            foreach (ScoreTerm st in stQueue.Keys)
            {
                TermQuery tq = new TermQuery(st.term);       // found a match
                tq.Boost = Boost * st.score;                 // set the boost
                query.Add(tq, Occur.SHOULD);                 // add to query
            }

            return(query);
        }
Esempio n. 7
0
 private void  InitBlock(TermQuery enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
Esempio n. 8
0
		public override Weight CreateWeight(Searcher searcher)
		{
			if (terms.Count == 1)
			{
				// optimize one-term case
				Term term = terms[0];
				Query termQuery = new TermQuery(term);
				termQuery.Boost = Boost;
				return termQuery.CreateWeight(searcher);
			}
			return new PhraseWeight(this, searcher);
		}
Esempio n. 9
0
			private void  InitBlock(TermQuery enclosingInstance)
			{
				this.enclosingInstance = enclosingInstance;
			}