com.transaxtions.search.rankingalgorithm
Class RankingQuery

java.lang.Object
  extended by com.transaxtions.search.rankingalgorithm.RankingQuery

public class RankingQuery
extends java.lang.Object

The RankingAlgorithm implementation. Uses Lucene to get documents from the index but scores and ranks using the RankingAlgorithm. RankingAlgorithm can be used in two modes, Document mode (default) and Product mode. The scoring changes with the mode. In Document mode, documents are matched for relevancy while in Product mode, documents are matched for term occurence. Document mode is useful for matching text, html, rich text pdf/word, books, faq, forums discussions, etc. Product mode useful for small text as in Retail Product matches, etc. Product mode also has scan speed to fast/medium/full scan. Full scan is the most accurate but also a little slow. Needs the Lucene indexPath or IndexSearcher or IndexReader at instantiation or at search time. Uses the IndexReader to read the documents from the Index.

 Example:
 		RankingQuery rq = new RankingQuery(); 
 		IndexSearcher is = new IndexSearcher(index);
 		StandardAnalyzer analyzer = new StandardAnalyzer();
		QueryParser parser = new QueryParser(field, analyzer);
		Query query = parser.parse(searchterms);
 		RankingHits rh = rq.search(query, is); //is = Lucene IndexSearcher object
		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) );
		}
  
 

Author:
Nagendra Nagarajayya
See Also:
RankingHits, RankingScore

Field Summary
static int DOCUMENT_MODE
           
static int FULLSEARCH_FAST
           
static int FULLSEARCH_FULL
           
static int FULLSEARCH_MEDIUM
           
static int PRODUCT_MODE
           
 
Constructor Summary
RankingQuery()
           
RankingQuery(org.apache.lucene.index.IndexReader reader)
          Constructor to create a RankingQuery object.
RankingQuery(org.apache.lucene.search.IndexSearcher is)
          Constructor to create a RankingQuery object.
RankingQuery(java.lang.String indexPath)
          Constructor to create a RankingQuery object.
 
Method Summary
 void close()
          Closes the IndexReader objects opened.
 org.apache.lucene.document.Document doc(int docid)
          Similar to IndexSearcher doc(id), returns a Lucene Document object
static void main(java.lang.String[] args)
           
 RankingHits search(org.apache.lucene.search.Query query)
          Similar to Lucene search.
 RankingHits search(org.apache.lucene.search.Query query, org.apache.lucene.index.IndexReader r)
          Similar to Lucene search.
 RankingHits search(org.apache.lucene.search.Query query, org.apache.lucene.search.IndexSearcher is)
          Similar to Lucene search.
 RankingHits search(java.lang.String field, java.lang.String searchTerms)
          Similar to Lucene search.
 void setMode(int type)
          Set mode, Document or Product mode.
 void setScan(boolean fast)
          Used in Product mode.
 void setScan(int full)
          Used in Product mode.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

PRODUCT_MODE

public static final int PRODUCT_MODE
See Also:
Constant Field Values

DOCUMENT_MODE

public static final int DOCUMENT_MODE
See Also:
Constant Field Values

FULLSEARCH_FAST

public static final int FULLSEARCH_FAST
See Also:
Constant Field Values

FULLSEARCH_MEDIUM

public static final int FULLSEARCH_MEDIUM
See Also:
Constant Field Values

FULLSEARCH_FULL

public static final int FULLSEARCH_FULL
See Also:
Constant Field Values
Constructor Detail

RankingQuery

public RankingQuery(org.apache.lucene.index.IndexReader reader)
Constructor to create a RankingQuery object.

Parameters:
reader - Lucene InndexReader object.

RankingQuery

public RankingQuery(org.apache.lucene.search.IndexSearcher is)
Constructor to create a RankingQuery object.

Parameters:
is - Lucene IndexSearcher object.

RankingQuery

public RankingQuery(java.lang.String indexPath)
             throws java.lang.Throwable
Constructor to create a RankingQuery object. An Lucene IndexReader object is created to read the index in the indexPath.

Parameters:
indexPath - to a Lucene index.
Throws:
java.lang.Throwable

RankingQuery

public RankingQuery()
Method Detail

setScan

public void setScan(boolean fast)
Used in Product mode. Set scan speed, FAST/FULL.

Parameters:
fast - true for FAST.

setScan

public void setScan(int full)
Used in Product mode. Set scan speed, FAST/MEDIUM/FULL. Default is FAST.

Parameters:
full - Valid values are RankingQuery.FAST, RankingQuery.MEDIUM, RankingQuery.FULL

setMode

public void setMode(int type)
Set mode, Document or Product mode. Default is Document mode.

Parameters:
type - Valid values are RankingQuery.DOCUMENT_MODE or RankingQuery.PRODUCT_MODE

close

public void close()
           throws java.lang.Throwable
Closes the IndexReader objects opened. Note: IndexReader object is closed only if the constructor RankingQuery(indexpath) is used. If the IndexSearcher or IndexReader is passed explicitly as in RankingQuery(IndexSearcher is) or RankingQuery(IndexReader ir) it is not closed.

Throws:
java.lang.Throwable
See Also:
RankingQuery(String)

doc

public org.apache.lucene.document.Document doc(int docid)
                                        throws java.lang.Throwable
Similar to IndexSearcher doc(id), returns a Lucene Document object

Parameters:
docid - Lucene document id
Returns:
Document object
Throws:
java.lang.Throwable

search

public RankingHits search(org.apache.lucene.search.Query query)
                   throws java.lang.Throwable
Similar to Lucene search. RankingQuery needs to have been instantiated with Lucene IndexReader or IndexSearcher objects. Uses the IndexReader object to access the Lucene index.

Parameters:
query - A Lucene query object
Returns:
A list of hits matching the search terms
Throws:
java.lang.Throwable
See Also:
RankingHits

search

public RankingHits search(java.lang.String field,
                          java.lang.String searchTerms)
                   throws java.lang.Throwable
Similar to Lucene search. RankingQuery needs to have been instantiated with a path to a Lucene index. *
 Example:
 		RankingQuery rq = new RankingQuery("/lucene/index/perl"); 
 		RankingHits rh = rq.search("search terms", "text"); 
		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:
field - to search
searchTerms - search terms
Returns:
RankingHits object, a list of documents matching the search terms
Throws:
java.lang.Throwable
See Also:
RankingHits

search

public RankingHits search(org.apache.lucene.search.Query query,
                          org.apache.lucene.search.IndexSearcher is)
                   throws java.lang.Throwable
Similar to Lucene search. Uses the Lucene Query object to get at the terms of the search. Uses the IndexSearcher to access to the IndexReader object to access the Lucene index.
 Example:
 		RankingQuery rq = new RankingQuery(); 
 		RankingHits rh = rq.search(query, is); //is = Lucene IndexSearcher object
		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:
query - Lucene query object
is - Lucene IndexSearcher object
Returns:
RankingHits object, a list of documents matching the search terms
Throws:
java.lang.Throwable
See Also:
RankingHits

search

public RankingHits search(org.apache.lucene.search.Query query,
                          org.apache.lucene.index.IndexReader r)
                   throws java.lang.Throwable
Similar to Lucene search. Uses the Lucene Query object to get at the terms of the search. Uses the IndexReader to access the Lucene index.
 Example:
 		RankingQuery rq = new RankingQuery(); 
 		RankingHits rh = rq.search(query, is); //is = Lucene IndexSearcher object
		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:
query - Lucene query object
r - Lucene IndexSearcher object
Returns:
RankingHits object, a list of documents matching the search terms
Throws:
java.lang.Throwable
See Also:
RankingHits

main

public static void main(java.lang.String[] args)
                 throws java.lang.Throwable
Throws:
java.lang.Throwable