Lucene.Net.Search.IndexSearcher.Explain C# (CSharp) Method

Explain() public method

public Explain ( Weight weight, int doc ) : Explanation
weight Weight
doc int
return Explanation
		public override Explanation Explain(Weight weight, int doc)
		{
			int n = ReaderUtil.SubIndex(doc, docStarts);
			int deBasedDoc = doc - docStarts[n];
			
			return weight.Explain(subReaders[n], deBasedDoc);
		}
		

Usage Example

コード例 #1
0
        public virtual void TestBasic()
        {
            // create a sort field and sort by it (reverse order)
            Query       query = new TermQuery(new Term("body", "contents"));
            IndexReader r     = searcher.IndexReader;

            // Just first pass query
            TopDocs hits = searcher.Search(query, 10);

            Assert.AreEqual(3, hits.TotalHits);
            Assert.AreEqual("3", r.Document(hits.ScoreDocs[0].Doc).Get("id"));
            Assert.AreEqual("1", r.Document(hits.ScoreDocs[1].Doc).Get("id"));
            Assert.AreEqual("2", r.Document(hits.ScoreDocs[2].Doc).Get("id"));

            // Now, rescore:
            Sort     sort     = new Sort(new SortField("popularity", SortFieldType.INT32, true));
            Rescorer rescorer = new SortRescorer(sort);

            hits = rescorer.Rescore(searcher, hits, 10);
            Assert.AreEqual(3, hits.TotalHits);
            Assert.AreEqual("2", r.Document(hits.ScoreDocs[0].Doc).Get("id"));
            Assert.AreEqual("1", r.Document(hits.ScoreDocs[1].Doc).Get("id"));
            Assert.AreEqual("3", r.Document(hits.ScoreDocs[2].Doc).Get("id"));

            string expl = rescorer.Explain(searcher, searcher.Explain(query, hits.ScoreDocs[0].Doc), hits.ScoreDocs[0].Doc).ToString();

            // Confirm the explanation breaks out the individual
            // sort fields:
            Assert.IsTrue(expl.Contains("= sort field <int: \"popularity\">! value=20"));

            // Confirm the explanation includes first pass details:
            Assert.IsTrue(expl.Contains("= first pass score"));
            Assert.IsTrue(expl.Contains("body:contents in"));
        }
All Usage Examples Of Lucene.Net.Search.IndexSearcher::Explain