public virtual void TestInvalidArguments() { int numResults = 5; TopDocsCollector <ScoreDoc> tdc = DoSearch(numResults); // start < 0 Assert.AreEqual(0, tdc.GetTopDocs(-1).ScoreDocs.Length); // start > pq.Size() Assert.AreEqual(0, tdc.GetTopDocs(numResults + 1).ScoreDocs.Length); // start == pq.Size() Assert.AreEqual(0, tdc.GetTopDocs(numResults).ScoreDocs.Length); // howMany < 0 Assert.AreEqual(0, tdc.GetTopDocs(0, -1).ScoreDocs.Length); // howMany == 0 Assert.AreEqual(0, tdc.GetTopDocs(0, 0).ScoreDocs.Length); }
public virtual void TestSortWithoutScoreTracking() { // Two Sort criteria to instantiate the multi/single comparers. Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC), new Sort() }; for (int i = 0; i < sort.Length; i++) { Query q = new MatchAllDocsQuery(); TopDocsCollector <Entry> tdc = TopFieldCollector.Create(sort[i], 10, true, false, false, true); @is.Search(q, tdc); TopDocs td = tdc.GetTopDocs(); ScoreDoc[] sd = td.ScoreDocs; for (int j = 0; j < sd.Length; j++) { Assert.IsTrue(float.IsNaN(sd[j].Score)); } Assert.IsTrue(float.IsNaN(td.MaxScore)); } }
public virtual void TestOutOfOrderCollection() { Directory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, null, MaxFieldLength.UNLIMITED); for (int i = 0; i < 10; i++) { writer.AddDocument(new Document()); } writer.Commit(); writer.Close(); bool[] inOrder = new bool[] { false, true }; System.String[] actualTSDCClass = new System.String[] { "OutOfOrderTopScoreDocCollector", "InOrderTopScoreDocCollector" }; BooleanQuery bq = new BooleanQuery(); // Add a Query with SHOULD, since bw.scorer() returns BooleanScorer2 // which delegates to BS if there are no mandatory clauses. bq.Add(new MatchAllDocsQuery(), Occur.SHOULD); // Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return // the clause instead of BQ. bq.MinimumNumberShouldMatch = 1; IndexSearcher searcher = new IndexSearcher(dir, true); for (int i = 0; i < inOrder.Length; i++) { TopDocsCollector <ScoreDoc> tdc = TopScoreDocCollector.Create(3, inOrder[i]); Assert.AreEqual("Lucene.Net.Search.TopScoreDocCollector+" + actualTSDCClass[i], tdc.GetType().FullName); searcher.Search(new MatchAllDocsQuery(), tdc); ScoreDoc[] sd = tdc.TopDocs().ScoreDocs; Assert.AreEqual(3, sd.Length); for (int j = 0; j < sd.Length; j++) { Assert.AreEqual(j, sd[j].Doc, "expected doc Id " + j + " found " + sd[j].Doc); } } }
public virtual void TestSortWithoutFillFields() { // There was previously a bug in TopFieldCollector when fillFields was set // to false - the same doc and score was set in ScoreDoc[] array. this test // asserts that if fillFields is false, the documents are set properly. It // does not use Searcher's default search methods (with Sort) since all set // fillFields to true. Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC), new Sort() }; for (int i = 0; i < sort.Length; i++) { Query q = new MatchAllDocsQuery(); TopDocsCollector <Entry> tdc = TopFieldCollector.Create(sort[i], 10, false, false, false, true); @is.Search(q, tdc); ScoreDoc[] sd = tdc.TopDocs().ScoreDocs; for (int j = 1; j < sd.Length; j++) { Assert.IsTrue(sd[j].Doc != sd[j - 1].Doc); } } }
public virtual void TestGetAllResults() { TopDocsCollector <ScoreDoc> tdc = DoSearch(15); Assert.AreEqual(15, tdc.GetTopDocs().ScoreDocs.Length); }
public virtual void TestFirstResultsPage() { TopDocsCollector <ScoreDoc> tdc = DoSearch(15); Assert.AreEqual(10, tdc.GetTopDocs(0, 10).ScoreDocs.Length); }
internal MyCollector() { Collector = TopScoreDocCollector.Create(10, true); }
public virtual void TestGetAllResults() { TopDocsCollector tdc = doSearch(15); Assert.AreEqual(15, tdc.TopDocs().scoreDocs.Length); }
internal MyCollector() { Collector = TopScoreDocCollector.Create(10, true); }
private IEnumerable<ContentSearchResult> EnumSearchResults(int start, Searcher searcher, TopDocsCollector collector, int limit) { TopDocs results = collector.TopDocs(); float max = results.GetMaxScore(); ScoreDoc[] found = results.scoreDocs; limit = Math.Min(limit, found.Length); for (int i = start; i < limit; i++) { ScoreDoc doc = found[i]; Document docInfo = searcher.Doc(doc.doc); ContentSearchResult.Builder builder = new ContentSearchResult.Builder(); builder.SetRanking((uint) Math.Max(0, Math.Min(100, (int) (doc.score/max*100f)))); builder.SetUri(docInfo.GetField("uri").StringValue()); builder.SetTitle(docInfo.GetField("title").StringValue()); builder.SetBlurb(docInfo.GetField("blurb").StringValue()); builder.SetModified(DateTime.ParseExact(docInfo.GetField("modified").StringValue(), "yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture, DateTimeStyles.None)); ContentRecord record; if (TryGetValue(builder.Uri, out record)) { builder.SetRecord(record); } yield return builder.Build(); } }