org.tgels.search.rankingalgorithm
Class RankingHits

java.lang.Object
  extended by org.tgels.search.rankingalgorithm.RankingHits
All Implemented Interfaces:
java.io.Serializable

public class RankingHits
extends java.lang.Object
implements java.io.Serializable

Returns the matching hits. Made to be comptabile with the Lucene Hits syntax.

Author:
Nagendra Nagarajayya
See Also:
RankingQuery, RankingScore, Serialized Form

Field Summary
 java.util.ArrayList<RankingScore> hits
           
 
Constructor Summary
RankingHits()
           
 
Method Summary
 org.apache.lucene.document.Document doc(int i)
          Return a Lucene Document.
 int docid(int i)
          Return a Lucene document id.
 org.apache.lucene.document.Document getDoc(int i)
          Return a Lucene document.
 float getHighestScore()
          Returns the highest score
 java.util.ArrayList<RankingScore> getHits()
          Returns an ArrayList of RankingScore objects.
 int getNumHits()
          Returns the number of hits.
 RankingScore getRankingScore(int i)
          Returns a RankingScore for the the document in the list
 int getTotalHits()
          Returns the total number of hits.
 int length()
          Returns the number of hits.
 float relevant(int i)
          Returns the percentage relevancy of a document.
 float score(int i)
          Similar to the Lucene score, except the return value is a double.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

hits

public java.util.ArrayList<RankingScore> hits
Constructor Detail

RankingHits

public RankingHits()
Method Detail

getDoc

public org.apache.lucene.document.Document getDoc(int i)
                                           throws java.lang.Throwable
Return a Lucene document.
Note: if RankingQuery(indexPath) constructor was used, a call to RankigQuery.close() will close the IndexReader object being used and an Exception will be thrown.

Parameters:
i - index value into the list of hits
Returns:
Document
Throws:
java.lang.Throwable

doc

public org.apache.lucene.document.Document doc(int i)
                                        throws java.lang.Throwable
Return a Lucene Document.
 Example: 
 		RankingHits rh = rq.search(query, is);
		System.out.println("num hits=" + rh.getNumHits() + "--no docs=" + is.maxDoc()); 
		for (int i=0; i<rh.getNumHits() && i<10; i++) {
			System.out.println("i=" + i + "--" + rh.score(i) + "--docid=" + rh.docid(i) + "--doc=" + rh.doc(i).get(title) );
		}

Parameters:
i - index value into the list
Returns:
Document
Throws:
java.lang.Throwable

getHits

public java.util.ArrayList<RankingScore> getHits()
Returns an ArrayList of RankingScore objects. RankingScore holds the scoring for a document.

Returns:
ArrayList of RankingScore objects
See Also:
RankingScore

docid

public int docid(int i)
Return a Lucene document id.
 Example: 
 		RankingHits rh = rq.search(query, is);
		System.out.println("num hits=" + rh.getNumHits() + "--no docs=" + is.maxDoc()); 
		for (int i=0; i<rh.getNumHits() && i<10; i++) {
			System.out.println("i=" + i + "--" + rh.score(i) + "--docid=" + rh.docid(i) + "--doc=" + rh.doc(i).get(title) );
		}

 

Parameters:
i - index value into the list of hits
Returns:
Document id
See Also:
getHits()

length

public int length()
Returns the number of hits. Named to be compatible with Lucene Hits() syntax. To be used to iterate through the matching hits to get the score, document id or the document itself.
 Example: 
 		RankingHits rh = rq.search(query, is);
		System.out.println("num hits=" + rh.getNumHits() + "--no docs=" + is.maxDoc()); 
		for (int i=0; i<rh.getNumHits() && i<10; i++) {
			System.out.println("i=" + i + "--" + rh.score(i) + "--docid=" + rh.docid(i) + "--doc=" + rh.doc(i).get(title) );
		}

 

Returns:
number of hits matching the search terms

getNumHits

public int getNumHits()
Returns the number of hits. Iterate through the matching hits to get the score, document id or the document itself.
 Example: 
 		RankingHits rh = rq.search(query, is);
		System.out.println("num hits=" + rh.getNumHits() + "--no docs=" + is.maxDoc()); 
		for (int i=0; i<rh.getNumHits() && i<10; i++) {
			System.out.println("i=" + i + "--" + rh.score(i) + "--docid=" + rh.docid(i) + "--doc=" + rh.doc(i).get(title) );
		}

Returns:
number of hits matching the search terms

getTotalHits

public int getTotalHits()
Returns the total number of hits. This might be different than getNumHits if only top n docs were requested
 Example: 
 		RankingHits rh = rq.search(query, null, is, 10);
		System.out.println("num hits=" + rh.getTotalHits() + "--no docs=" + is.maxDoc()); 
		for (int i=0; i<rh.getNumHits() && i<10; i++) {
			System.out.println("i=" + i + "--" + rh.score(i) + "--docid=" + rh.docid(i) + "--doc=" + rh.doc(i).get(title) );
		}

Returns:
number of hits matching the search terms

getHighestScore

public float getHighestScore()
Returns the highest score
 Example: 
 		RankingHits rh = rq.search(query, is);
		System.out.println("num hits=" + rh.getTotalHits() + "--no docs=" + is.maxDoc()); 
		for (int i=0; i<rh.getNumHits() && i<10; i++) {
			System.out.println("i=" + i + "--" + rh.score(i) + "--docid=" + rh.docid(i) + "--doc=" + rh.doc(i).get(title) );
		}

Returns:
number of hits matching the search terms

getRankingScore

public RankingScore getRankingScore(int i)
Returns a RankingScore for the the document in the list

Parameters:
i - index value into the list of hits
Returns:
A RankingScore object.
See Also:
getHits(), RankingScore

relevant

public float relevant(int i)
Returns the percentage relevancy of a document.

Parameters:
i - index value into the list of hits
Returns:
a relevant percentage
See Also:
getHits()

score

public float score(int i)
Similar to the Lucene score, except the return value is a double.
 Example: 
 		RankingHits rh = rq.search(query, is);
		System.out.println("num hits=" + rh.getNumHits() + "--no docs=" + is.maxDoc()); 
		for (int i=0; i<rh.getNumHits() && i<10; i++) {
			System.out.println("i=" + i + "--" + rh.score(i) + "--docid=" + rh.docid(i) + "--doc=" + rh.doc(i).get(title) );
		}

Parameters:
i - index value into the list of hits @getHits
Returns:
a double value showing the scoring for the document at the index value