|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.transaxtions.search.rankingalgorithm.RankingQuery
public class RankingQuery
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) );
}
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 |
|---|
public static final int PRODUCT_MODE
public static final int DOCUMENT_MODE
public static final int FULLSEARCH_FAST
public static final int FULLSEARCH_MEDIUM
public static final int FULLSEARCH_FULL
| Constructor Detail |
|---|
public RankingQuery(org.apache.lucene.index.IndexReader reader)
reader - Lucene InndexReader object.public RankingQuery(org.apache.lucene.search.IndexSearcher is)
is - Lucene IndexSearcher object.
public RankingQuery(java.lang.String indexPath)
throws java.lang.Throwable
indexPath - to a Lucene index.
java.lang.Throwablepublic RankingQuery()
| Method Detail |
|---|
public void setScan(boolean fast)
fast - true for FAST.public void setScan(int full)
full - Valid values are RankingQuery.FAST, RankingQuery.MEDIUM, RankingQuery.FULLpublic void setMode(int type)
type - Valid values are RankingQuery.DOCUMENT_MODE or RankingQuery.PRODUCT_MODE
public void close()
throws java.lang.Throwable
java.lang.ThrowableRankingQuery(String)
public org.apache.lucene.document.Document doc(int docid)
throws java.lang.Throwable
docid - Lucene document id
java.lang.Throwable
public RankingHits search(org.apache.lucene.search.Query query)
throws java.lang.Throwable
query - A Lucene query object
java.lang.ThrowableRankingHits
public RankingHits search(java.lang.String field,
java.lang.String searchTerms)
throws java.lang.Throwable
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) );
}
field - to searchsearchTerms - search terms
java.lang.ThrowableRankingHits
public RankingHits search(org.apache.lucene.search.Query query,
org.apache.lucene.search.IndexSearcher is)
throws java.lang.Throwable
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) );
}
query - Lucene query objectis - Lucene IndexSearcher object
java.lang.ThrowableRankingHits
public RankingHits search(org.apache.lucene.search.Query query,
org.apache.lucene.index.IndexReader r)
throws java.lang.Throwable
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) );
}
query - Lucene query objectr - Lucene IndexSearcher object
java.lang.ThrowableRankingHits
public static void main(java.lang.String[] args)
throws java.lang.Throwable
java.lang.Throwable
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||