/// <summary> Computes a score factor for a phrase. /// /// <p/> /// The default implementation sums the idf factor for /// each term in the phrase. /// /// </summary> /// <param name="terms">the terms in the phrase /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> an IDFExplain object that includes both an idf /// score factor for the phrase and an explanation /// for each term. /// </returns> /// <throws> IOException </throws> public virtual IDFExplanation idfExplain(IList <Lucene.Net.Index.Term> terms, Searcher searcher) { if (SupportedMethods.overridesCollectionIDF) { float idf = Idf(terms, searcher); return(new IDFExplanation { GetIdf = () => idf, Explain = () => "Inexplicable" }); } int max = searcher.MaxDoc(); float idf2 = 0.0f; System.Text.StringBuilder exp = new System.Text.StringBuilder(); foreach (Term term in terms) { int df = searcher.DocFreq(term); idf2 += Idf(df, max); exp.Append(" "); exp.Append(term.Text()); exp.Append("="); exp.Append(df); } float fIdf = idf2; return(new IDFExplanation { GetIdf = () => fIdf, Explain = () => exp.ToString() }); }
// count # deletions, return -1 if unknown. private int CountDeletions(Searcher s) { int cnt = -1; if (s is IndexSearcher) { cnt = s.MaxDoc() - ((IndexSearcher)s).GetIndexReader().NumDocs(); } return(cnt); }
/// <summary> Computes a score factor for a simple term and returns an explanation /// for that score factor. /// /// <p/> /// The default implementation uses: /// /// <pre> /// idf(searcher.docFreq(term), searcher.maxDoc()); /// </pre> /// /// Note that {@link Searcher#MaxDoc()} is used instead of /// {@link Lucene.Net.Index.IndexReader#NumDocs()} because it is /// proportional to {@link Searcher#DocFreq(Term)} , i.e., when one is /// inaccurate, so is the other, and in the same direction. /// /// </summary> /// <param name="term">the term in question /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> an IDFExplain object that includes both an idf score factor /// and an explanation for the term. /// </returns> /// <throws> IOException </throws> public virtual IDFExplanation IdfExplain(Term term, Searcher searcher) { if (SupportedMethods.overridesTermIDF) { float idf = Idf(term, searcher); return(new AnonymousClassIDFExplanation(idf, this)); } int df = searcher.DocFreq(term); int max = searcher.MaxDoc(); float idf2 = Idf(df, max); return(new AnonymousClassIDFExplanation1(df, max, idf2, this)); }
/// <summary> Computes a score factor for a simple term and returns an explanation /// for that score factor. /// /// <p/> /// The default implementation uses: /// /// <pre> /// idf(searcher.docFreq(term), searcher.maxDoc()); /// </pre> /// /// Info: <see cref="Searcher.MaxDoc()"/> is used instead of /// <see cref="Lucene.Net.Index.IndexReader.NumDocs()"/> because it is /// proportional to <see cref="Searcher.DocFreq(Term)"/> , i.e., when one is /// inaccurate, so is the other, and in the same direction. /// /// </summary> /// <param name="term">the term in question /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> an IDFExplain object that includes both an idf score factor /// and an explanation for the term. /// </returns> /// <throws> IOException </throws> public virtual IDFExplanation IdfExplain(Term term, Searcher searcher) { if (SupportedMethods.overridesTermIDF) { float idf = Idf(term, searcher); return(new IDFExplanation { GetIdf = () => idf, Explain = () => "Inexplicable" }); } int df = searcher.DocFreq(term); int max = searcher.MaxDoc(); float idf2 = Idf(df, max); return(new IDFExplanation { GetIdf = () => idf2, Explain = () => "idf(docFreq=" + df + ", maxDocs=" + max + ")" }); }
public static float EXPLAIN_SCORE_TOLERANCE_DELTA = 0.00025f; // {{See: LUCENENET-288}} Intentional diversion from Java Lucene per above comment /// <summary> Tests that all documents up to maxDoc which are *not* in the /// expected result set, have an explanation which indicates no match /// (ie: Explanation value of 0.0f) /// </summary> public static void CheckNoMatchExplanations(Query q, System.String defaultFieldName, Searcher searcher, int[] results) { System.String d = q.ToString(defaultFieldName); System.Collections.Hashtable ignore = new System.Collections.Hashtable(); for (int i = 0; i < results.Length; i++) { SupportClass.CollectionsHelper.AddIfNotContains(ignore, (System.Int32) results[i]); } int maxDoc = searcher.MaxDoc(); for (int doc = 0; doc < maxDoc; doc++) { if (ignore.Contains((System.Int32) doc)) continue; Explanation exp = searcher.Explain(q, doc); Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null"); Assert.AreEqual(0.0f, exp.GetValue(), 0.0f, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString()); } }
public static float EXPLAIN_SCORE_TOLERANCE_DELTA = 0.00025f; // {{See: LUCENENET-288}} Intentional diversion from Java Lucene per above comment /// <summary> Tests that all documents up to maxDoc which are *not* in the /// expected result set, have an explanation which indicates no match /// (ie: Explanation value of 0.0f) /// </summary> public static void CheckNoMatchExplanations(Query q, System.String defaultFieldName, Searcher searcher, int[] results) { System.String d = q.ToString(defaultFieldName); System.Collections.Hashtable ignore = new System.Collections.Hashtable(); for (int i = 0; i < results.Length; i++) { SupportClass.CollectionsHelper.AddIfNotContains(ignore, (System.Int32)results[i]); } int maxDoc = searcher.MaxDoc(); for (int doc = 0; doc < maxDoc; doc++) { if (ignore.Contains((System.Int32)doc)) { continue; } Explanation exp = searcher.Explain(q, doc); Assert.IsNotNull(exp, "Explanation of [[" + d + "]] for #" + doc + " is null"); Assert.AreEqual(0.0f, exp.GetValue(), 0.0f, "Explanation of [[" + d + "]] for #" + doc + " doesn't indicate non-match: " + exp.ToString()); } }
/// <summary> Computes a score factor for a phrase. /// /// <p/> /// The default implementation sums the idf factor for /// each term in the phrase. /// /// </summary> /// <param name="terms">the terms in the phrase /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> an IDFExplain object that includes both an idf /// score factor for the phrase and an explanation /// for each term. /// </returns> /// <throws> IOException </throws> public virtual IDFExplanation idfExplain(System.Collections.ICollection terms, Searcher searcher) { if (SupportedMethods.overridesCollectionIDF) { float idf = Idf(terms, searcher); return(new AnonymousClassIDFExplanation2(idf, this)); } int max = searcher.MaxDoc(); float idf2 = 0.0f; System.Text.StringBuilder exp = new System.Text.StringBuilder(); foreach (Term term in terms) { int df = searcher.DocFreq(term); idf2 += Idf(df, max); exp.Append(" "); exp.Append(term.Text()); exp.Append("="); exp.Append(df); } float fIdf = idf2; return(new AnonymousClassIDFExplanation3(fIdf, exp, this)); }
/// <summary> Computes a score factor for a phrase. /// /// <p/> /// The default implementation sums the idf factor for /// each term in the phrase. /// /// </summary> /// <param name="terms">the terms in the phrase /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> an IDFExplain object that includes both an idf /// score factor for the phrase and an explanation /// for each term. /// </returns> /// <throws> IOException </throws> public virtual IDFExplanation idfExplain(System.Collections.ICollection terms, Searcher searcher) { if (SupportedMethods.overridesCollectionIDF) { float idf = Idf(terms, searcher); return new AnonymousClassIDFExplanation2(idf, this); } int max = searcher.MaxDoc(); float idf2 = 0.0f; System.Text.StringBuilder exp = new System.Text.StringBuilder(); foreach (Term term in terms) { int df = searcher.DocFreq(term); idf2 += Idf(df, max); exp.Append(" "); exp.Append(term.Text()); exp.Append("="); exp.Append(df); } float fIdf = idf2; return new AnonymousClassIDFExplanation3(fIdf, exp, this); }
/// <summary> Computes a score factor for a simple term and returns an explanation /// for that score factor. /// /// <p/> /// The default implementation uses: /// /// <pre> /// idf(searcher.docFreq(term), searcher.maxDoc()); /// </pre> /// /// Note that {@link Searcher#MaxDoc()} is used instead of /// {@link Lucene.Net.Index.IndexReader#NumDocs()} because it is /// proportional to {@link Searcher#DocFreq(Term)} , i.e., when one is /// inaccurate, so is the other, and in the same direction. /// /// </summary> /// <param name="term">the term in question /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> an IDFExplain object that includes both an idf score factor /// and an explanation for the term. /// </returns> /// <throws> IOException </throws> public virtual IDFExplanation IdfExplain(Term term, Searcher searcher) { if (SupportedMethods.overridesTermIDF) { float idf = Idf(term, searcher); return new AnonymousClassIDFExplanation(idf, this); } int df = searcher.DocFreq(term); int max = searcher.MaxDoc(); float idf2 = Idf(df, max); return new AnonymousClassIDFExplanation1(df, max, idf2, this); }
public virtual float Idf(Term term, Searcher searcher) { return Idf(searcher.DocFreq(term), searcher.MaxDoc()); }
/// <summary> Computes a score factor for a phrase. /// /// <p/> /// The default implementation sums the idf factor for /// each term in the phrase. /// /// </summary> /// <param name="terms">the terms in the phrase /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> an IDFExplain object that includes both an idf /// score factor for the phrase and an explanation /// for each term. /// </returns> /// <throws> IOException </throws> public virtual IDFExplanation idfExplain(IList<Lucene.Net.Index.Term> terms, Searcher searcher) { if (SupportedMethods.overridesCollectionIDF) { float idf = Idf(terms, searcher); return new IDFExplanation { GetIdf = () => idf, Explain = () => "Inexplicable" }; } int max = searcher.MaxDoc(); float idf2 = 0.0f; System.Text.StringBuilder exp = new System.Text.StringBuilder(); foreach (Term term in terms) { int df = searcher.DocFreq(term); idf2 += Idf(df, max); exp.Append(" "); exp.Append(term.Text()); exp.Append("="); exp.Append(df); } float fIdf = idf2; return new IDFExplanation { GetIdf = () => fIdf, Explain = () => exp.ToString() }; }
/// <summary> Computes a score factor for a simple term and returns an explanation /// for that score factor. /// /// <p/> /// The default implementation uses: /// /// <pre> /// idf(searcher.docFreq(term), searcher.maxDoc()); /// </pre> /// /// Info: <see cref="Searcher.MaxDoc()"/> is used instead of /// <see cref="Lucene.Net.Index.IndexReader.NumDocs()"/> because it is /// proportional to <see cref="Searcher.DocFreq(Term)"/> , i.e., when one is /// inaccurate, so is the other, and in the same direction. /// /// </summary> /// <param name="term">the term in question /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> an IDFExplain object that includes both an idf score factor /// and an explanation for the term. /// </returns> /// <throws> IOException </throws> public virtual IDFExplanation IdfExplain(Term term, Searcher searcher) { if (SupportedMethods.overridesTermIDF) { float idf = Idf(term, searcher); return new IDFExplanation { GetIdf = () => idf, Explain = () => "Inexplicable" }; } int df = searcher.DocFreq(term); int max = searcher.MaxDoc(); float idf2 = Idf(df, max); return new IDFExplanation { GetIdf = () => idf2, Explain = () => "idf(docFreq=" + df + ", maxDocs=" + max + ")" }; }
/// <summary>Computes a score factor for a simple term. /// /// <p>The default implementation is:<pre> /// return idf(searcher.docFreq(term), searcher.maxDoc()); /// </pre> /// /// Note that {@link Searcher#MaxDoc()} is used instead of /// {@link IndexReader#NumDocs()} because it is proportional to /// {@link Searcher#DocFreq(Term)} , i.e., when one is inaccurate, /// so is the other, and in the same direction. /// /// </summary> /// <param name="term">the term in question /// </param> /// <param name="searcher">the document collection being searched /// </param> /// <returns> a score factor for the term /// </returns> public virtual float Idf(Term term, Searcher searcher) { return(Ldf(searcher.DocFreq(term), searcher.MaxDoc())); }
// count # deletions, return -1 if unknown. private int CountDeletions(Searcher s) { int cnt = - 1; if (s is IndexSearcher) { cnt = s.MaxDoc() - ((IndexSearcher) s).GetIndexReader().NumDocs(); } return cnt; }