/// <summary> Populates the results array with the ScoreDoc instaces. This can be /// overridden in case a different ScoreDoc type should be returned. /// </summary> protected internal virtual void PopulateResults(ScoreDoc[] results, int howMany) { for (int i = howMany - 1; i >= 0; i--) { results[i] = (ScoreDoc)pq.Pop(); } }
/// <summary>The top-scoring hits. </summary> public virtual TopDocs TopDocs() { ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()]; for (int i = hq.Size() - 1; i >= 0; i--) { // put docs in array scoreDocs[i] = (ScoreDoc)hq.Pop(); } float maxScore = (totalHits == 0) ? System.Single.NegativeInfinity : scoreDocs[0].score; return(new TopDocs(totalHits, scoreDocs, maxScore)); }
/// <summary> Convenience routine to make it easy to return the most interesting words in a document. /// More advanced users will call <see cref="RetrieveTerms(System.IO.StreamReader)"/> directly. /// </summary> /// <param name="r">the source document /// </param> /// <returns> the most interesting words in the document /// /// </returns> /// <seealso cref="RetrieveTerms(System.IO.StreamReader)"> /// </seealso> /// <seealso cref="SetMaxQueryTerms"> /// </seealso> public System.String[] RetrieveInterestingTerms(System.IO.StreamReader r) { System.Collections.ArrayList al = new System.Collections.ArrayList(maxQueryTerms); PriorityQueue pq = RetrieveTerms(r); System.Object cur; int lim = maxQueryTerms; // have to be careful, retrieveTerms returns all words but that's probably not useful to our caller... // we just want to return the top words while (((cur = pq.Pop()) != null) && lim-- > 0) { System.Object[] ar = (System.Object[])cur; al.Add(ar[0]); // the 1st entry is the interesting word } System.String[] res = new System.String[al.Count]; // return (System.String[]) SupportClass.ICollectionSupport.ToArray(al, res); return((System.String[])al.ToArray(typeof(System.String))); }
/// <summary> Create the More like query from a PriorityQueue</summary> private Query CreateQuery(PriorityQueue q) { BooleanQuery query = new BooleanQuery(); System.Object cur; int qterms = 0; float bestScore = 0; while (((cur = q.Pop()) != null)) { System.Object[] ar = (System.Object[])cur; TermQuery tq = new TermQuery(new Term((System.String)ar[1], (System.String)ar[0])); if (boost) { if (qterms == 0) { bestScore = (float)((System.Single)ar[2]); } float myScore = (float)((System.Single)ar[2]); tq.SetBoost(myScore / bestScore); } try { query.Add(tq, BooleanClause.Occur.SHOULD); } catch (BooleanQuery.TooManyClauses) { break; } qterms++; if (maxQueryTerms > 0 && qterms >= maxQueryTerms) { break; } } return(query); }
/// <summary> Create the More like query from a PriorityQueue</summary> private Query CreateQuery(PriorityQueue q) { BooleanQuery query = new BooleanQuery(); System.Object cur; int qterms = 0; float bestScore = 0; while (((cur = q.Pop()) != null)) { System.Object[] ar = (System.Object[]) cur; TermQuery tq = new TermQuery(new Term((System.String) ar[1], (System.String) ar[0])); if (boost) { if (qterms == 0) { bestScore = (float) ((System.Single) ar[2]); } float myScore = (float) ((System.Single) ar[2]); tq.SetBoost(myScore / bestScore); } try { query.Add(tq, BooleanClause.Occur.SHOULD); } catch (BooleanQuery.TooManyClauses ignore) { break; } qterms++; if (maxQueryTerms > 0 && qterms >= maxQueryTerms) { break; } } return query; }