Esempio n. 1
0
            public virtual Explanation Explain(Monodoc.Lucene.Net.Index.IndexReader reader, int doc)
            {
                Explanation sumExpl = new Explanation();

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

                for (int i = 0; i < weights.Count; i++)
                {
                    BooleanClause c = (BooleanClause)Enclosing_Instance.clauses[i];
                    Weight        w = (Weight)weights[i];
                    Explanation   e = w.Explain(reader, doc);
                    if (!c.prohibited)
                    {
                        maxCoord++;
                    }
                    if (e.GetValue() > 0)
                    {
                        if (!c.prohibited)
                        {
                            sumExpl.AddDetail(e);
                            sum += e.GetValue();
                            coord++;
                        }
                        else
                        {
                            return(new Explanation(0.0f, "match prohibited"));
                        }
                    }
                    else if (c.required)
                    {
                        return(new Explanation(0.0f, "match required"));
                    }
                }
                sumExpl.SetValue(sum);

                if (coord == 1)
                {
                    // only one clause matched
                    sumExpl = sumExpl.GetDetails()[0];                     // eliminate wrapper
                }
                float coordFactor = Enclosing_Instance.GetSimilarity(searcher).Coord(coord, maxCoord);

                if (coordFactor == 1.0f)
                {
                    // coord is no-op
                    return(sumExpl);
                }
                // eliminate wrapper
                else
                {
                    Explanation result = new Explanation();
                    result.SetDescription("product of:");
                    result.AddDetail(sumExpl);
                    result.AddDetail(new Explanation(coordFactor, "coord(" + coord + "/" + maxCoord + ")"));
                    result.SetValue(sum * coordFactor);
                    return(result);
                }
            }
Esempio n. 2
0
		/// <summary>Adds a clause to a boolean query.</summary>
		/// <seealso cref="#GetMaxClauseCount()">
		/// </seealso>
		public virtual void  Add(BooleanClause clause)
		{
			if (clauses.Count >= maxClauseCount)
				throw new TooManyClauses();
			
			clauses.Add(clause);
		}
Esempio n. 3
0
            public virtual Scorer Scorer(Monodoc.Lucene.Net.Index.IndexReader reader)
            {
                // First see if the (faster) ConjunctionScorer will work.  This can be
                // used when all clauses are required.  Also, at this point a
                // BooleanScorer cannot be embedded in a ConjunctionScorer, as the hits
                // from a BooleanScorer are not always sorted by document number (sigh)
                // and hence BooleanScorer cannot implement skipTo() correctly, which is
                // required by ConjunctionScorer.
                bool allRequired = true;
                bool noneBoolean = true;

                for (int i = 0; i < weights.Count; i++)
                {
                    BooleanClause c = (BooleanClause)Enclosing_Instance.clauses[i];
                    if (!c.required)
                    {
                        allRequired = false;
                    }
                    if (c.query is BooleanQuery)
                    {
                        noneBoolean = false;
                    }
                }

                if (allRequired && noneBoolean)
                {
                    // ConjunctionScorer is okay
                    ConjunctionScorer result = new ConjunctionScorer(Enclosing_Instance.GetSimilarity(searcher));
                    for (int i = 0; i < weights.Count; i++)
                    {
                        Weight w         = (Weight)weights[i];
                        Scorer subScorer = w.Scorer(reader);
                        if (subScorer == null)
                        {
                            return(null);
                        }
                        result.Add(subScorer);
                    }
                    return(result);
                }

                // Use good-old BooleanScorer instead.
                BooleanScorer result2 = new BooleanScorer(Enclosing_Instance.GetSimilarity(searcher));

                for (int i = 0; i < weights.Count; i++)
                {
                    BooleanClause c         = (BooleanClause)Enclosing_Instance.clauses[i];
                    Weight        w         = (Weight)weights[i];
                    Scorer        subScorer = w.Scorer(reader);
                    if (subScorer != null)
                    {
                        result2.Add(subScorer, c.required, c.prohibited);
                    }
                    else if (c.required)
                    {
                        return(null);
                    }
                }

                return(result2);
            }