Exemplo n.º 1
0
            /* Create the scorer used to score our associated DisjunctionMaxQuery */
            public override Scorer Scorer(IndexReader reader, bool scoreDocsInOrder, bool topScorer)
            {
                Scorer[] scorers = new Scorer[weights.Count];
                int      idx     = 0;

                for (System.Collections.IEnumerator iter = weights.GetEnumerator(); iter.MoveNext();)
                {
                    Weight w         = (Weight)iter.Current;
                    Scorer subScorer = w.Scorer(reader, true, false);
                    if (subScorer != null && subScorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS)
                    {
                        scorers[idx++] = subScorer;
                    }
                }
                if (idx == 0)
                {
                    return(null);                    // all scorers did not have documents
                }
                DisjunctionMaxScorer result = new DisjunctionMaxScorer(Enclosing_Instance.tieBreakerMultiplier, similarity, scorers, idx);

                return(result);
            }
Exemplo n.º 2
0
            public override Explanation Explain(IndexReader reader, int doc)
            {
                int minShouldMatch         = Enclosing_Instance.GetMinimumNumberShouldMatch();
                ComplexExplanation sumExpl = new ComplexExplanation();

                sumExpl.SetDescription("sum of:");
                int   coord            = 0;
                int   maxCoord         = 0;
                float sum              = 0.0f;
                bool  fail             = false;
                int   shouldMatchCount = 0;

                for (System.Collections.IEnumerator wIter = weights.GetEnumerator(), cIter = Enclosing_Instance.clauses.GetEnumerator(); wIter.MoveNext();)
                {
                    cIter.MoveNext();

                    Weight        w = (Weight)wIter.Current;
                    BooleanClause c = (BooleanClause)cIter.Current;
                    if (w.Scorer(reader, true, true) == null)
                    {
                        continue;
                    }
                    Explanation e = w.Explain(reader, doc);
                    if (!c.IsProhibited())
                    {
                        maxCoord++;
                    }
                    if (e.IsMatch())
                    {
                        if (!c.IsProhibited())
                        {
                            sumExpl.AddDetail(e);
                            sum += e.GetValue();
                            coord++;
                        }
                        else
                        {
                            Explanation r = new Explanation(0.0f, "match on prohibited clause (" + c.GetQuery().ToString() + ")");
                            r.AddDetail(e);
                            sumExpl.AddDetail(r);
                            fail = true;
                        }
                        if (c.GetOccur() == Occur.SHOULD)
                        {
                            shouldMatchCount++;
                        }
                    }
                    else if (c.IsRequired())
                    {
                        Explanation r = new Explanation(0.0f, "no match on required clause (" + c.GetQuery().ToString() + ")");
                        r.AddDetail(e);
                        sumExpl.AddDetail(r);
                        fail = true;
                    }
                }
                if (fail)
                {
                    System.Boolean tempAux = false;
                    sumExpl.SetMatch(tempAux);
                    sumExpl.SetValue(0.0f);
                    sumExpl.SetDescription("Failure to meet condition(s) of required/prohibited clause(s)");
                    return(sumExpl);
                }
                else if (shouldMatchCount < minShouldMatch)
                {
                    System.Boolean tempAux2 = false;
                    sumExpl.SetMatch(tempAux2);
                    sumExpl.SetValue(0.0f);
                    sumExpl.SetDescription("Failure to match minimum number " + "of optional clauses: " + minShouldMatch);
                    return(sumExpl);
                }

                sumExpl.SetMatch(0 < coord?true:false);
                sumExpl.SetValue(sum);

                float coordFactor = similarity.Coord(coord, maxCoord);

                if (coordFactor == 1.0f)
                {
                    // coord is no-op
                    return(sumExpl);
                }
                // eliminate wrapper
                else
                {
                    ComplexExplanation result = new ComplexExplanation(sumExpl.IsMatch(), sum * coordFactor, "product of:");
                    result.AddDetail(sumExpl);
                    result.AddDetail(new Explanation(coordFactor, "coord(" + coord + "/" + maxCoord + ")"));
                    return(result);
                }
            }
Exemplo n.º 3
0
		public override void  Search(Weight weight, Filter filter, Collector collector)
		{
			
			if (filter == null)
			{
				for (int i = 0; i < subReaders.Length; i++)
				{
					// search each subreader
					collector.SetNextReader(subReaders[i], docStarts[i]);
					Scorer scorer = weight.Scorer(subReaders[i], !collector.AcceptsDocsOutOfOrder(), true);
					if (scorer != null)
					{
						scorer.Score(collector);
					}
				}
			}
			else
			{
				for (int i = 0; i < subReaders.Length; i++)
				{
					// search each subreader
					collector.SetNextReader(subReaders[i], docStarts[i]);
					SearchWithFilter(subReaders[i], weight, filter, collector);
				}
			}
		}
Exemplo n.º 4
0
		private void  SearchWithFilter(IndexReader reader, Weight weight, Filter filter, Collector collector)
		{
			
			System.Diagnostics.Debug.Assert(filter != null);
			
			Scorer scorer = weight.Scorer(reader, true, false);
			if (scorer == null)
			{
				return ;
			}
			
			int docID = scorer.DocID();
			System.Diagnostics.Debug.Assert(docID == - 1 || docID == DocIdSetIterator.NO_MORE_DOCS);
			
			// CHECKME: use ConjunctionScorer here?
			DocIdSet filterDocIdSet = filter.GetDocIdSet(reader);
			if (filterDocIdSet == null)
			{
				// this means the filter does not accept any documents.
				return ;
			}
			
			DocIdSetIterator filterIter = filterDocIdSet.Iterator();
			if (filterIter == null)
			{
				// this means the filter does not accept any documents.
				return ;
			}
			int filterDoc = filterIter.NextDoc();
			int scorerDoc = scorer.Advance(filterDoc);
			
			collector.SetScorer(scorer);
			while (true)
			{
				if (scorerDoc == filterDoc)
				{
					// Check if scorer has exhausted, only before collecting.
					if (scorerDoc == DocIdSetIterator.NO_MORE_DOCS)
					{
						break;
					}
					collector.Collect(scorerDoc);
					filterDoc = filterIter.NextDoc();
					scorerDoc = scorer.Advance(filterDoc);
				}
				else if (scorerDoc > filterDoc)
				{
					filterDoc = filterIter.Advance(scorerDoc);
				}
				else
				{
					scorerDoc = scorer.Advance(filterDoc);
				}
			}
		}
Exemplo n.º 5
0
		/// <summary> Just like {@link #Search(Weight, Filter, int, Sort)}, but you choose
		/// whether or not the fields in the returned {@link FieldDoc} instances
		/// should be set by specifying fillFields.<br/>
		/// 
		/// <p/>
		/// NOTE: this does not compute scores by default. If you need scores, create
		/// a {@link TopFieldCollector} instance by calling
		/// {@link TopFieldCollector#create} and then pass that to
		/// {@link #Search(Weight, Filter, Collector)}.
		/// <p/>
		/// </summary>
		public virtual TopFieldDocs Search(Weight weight, Filter filter, int nDocs, Sort sort, bool fillFields)
		{
            nDocs = System.Math.Min(nDocs, reader.MaxDoc());

			SortField[] fields = sort.fields;
			bool legacy = false;
			for (int i = 0; i < fields.Length; i++)
			{
				SortField field = fields[i];
				System.String fieldname = field.GetField();
				int type = field.GetType();
				// Resolve AUTO into its true type
				if (type == SortField.AUTO)
				{
					int autotype = SortField.DetectFieldType(reader, fieldname);
					if (autotype == SortField.STRING)
					{
						fields[i] = new SortField(fieldname, field.GetLocale(), field.GetReverse());
					}
					else
					{
						fields[i] = new SortField(fieldname, autotype, field.GetReverse());
					}
				}
				
				if (field.GetUseLegacySearch())
				{
					legacy = true;
				}
			}
			
			if (legacy)
			{
				// Search the single top-level reader
				TopDocCollector collector = new TopFieldDocCollector(reader, sort, nDocs);
				HitCollectorWrapper hcw = new HitCollectorWrapper(collector);
				hcw.SetNextReader(reader, 0);
				if (filter == null)
				{
					Scorer scorer = weight.Scorer(reader, true, true);
					if (scorer != null)
					{
						scorer.Score(hcw);
					}
				}
				else
				{
					SearchWithFilter(reader, weight, filter, hcw);
				}
				return (TopFieldDocs) collector.TopDocs();
			}
			
			TopFieldCollector collector2 = TopFieldCollector.create(sort, nDocs, fillFields, fieldSortDoTrackScores, fieldSortDoMaxScore, !weight.ScoresDocsOutOfOrder());
			Search(weight, filter, collector2);
			return (TopFieldDocs) collector2.TopDocs();
		}