/*
* Here is the correlation ranking using Lucene
* Use score for natural sorting
* Correlation ranking is one of the simplest sorting methods.
* The so-called correlation is actually the score of the document
* The score of the document is different for each search,
* It needs to be determined based on the keywords found.
*
*TF Entry Frequency
*IDF Reverse Document Frequency
Incentive factors for *boost field
*lengthnum length Factor
*/
Result diagram:
Package score;
Import java.io.IOException;
Import Org.apache.lucene.analysis.standard.StandardAnalyzer;
Import org.apache.lucene.document.Document;
Import Org.apache.lucene.document.Field;
Import Org.apache.lucene.document.Field.Index;
Import Org.apache.lucene.index.IndexWriter;
Import Org.apache.lucene.index.Term;
Import org.apache.lucene.search.Hits;
Import Org.apache.lucene.search.IndexSearcher;
Import Org.apache.lucene.search.TermQuery;
public class Native_score {
Public Native_score (String Index_store_path)
{
try{
IndexWriter writer = new IndexWriter (Index_store_path, New StandardAnalyzer (), true);
Writer.setusecompoundfile (FALSE);
Create 3 of documents
Document Doc1 = new document ();
Document DOC2 = new document ();
Document DOC3 = new document ();
Field f1 = new Field ("BookName", "ab BC", Field.Store.YES, index.tokenized);
Field F2 = new Field ("BookName", "AB BC CD", Field.Store.YES, index.tokenized);
Field F3 = new Field ("BookName", "AB", Field.Store.YES, index.tokenized);
Doc1.add (F1);
Doc2.add (F2);
Doc3.add (F3);
Writer.adddocument (Doc1);
Writer.adddocument (DOC2);
Writer.adddocument (DOC3);
Writer.close ();
Indexsearcher searcher = new Indexsearcher (Index_store_path);
Termquery q = new Termquery (New term ("BookName", "BC"));
Hits Hits = Searcher.search (q);
for (int i = 0; i < hits.length (); i++) {
Document doc = Hits.doc (i);
The document to which it is matched
System.out.println (Doc.get ("bookname") + "\t\t");
Score from the document
System.out.println (Hits.score (i));
Here's how this score is going to be understood by explaining the method
System.out.println (Searcher.explain (q, Hits.id (i)). ToString ());
}
}catch (IOException e) {
E.printstacktrace ();
}
}
public static void Main (string[] args) {
TODO auto-generated Method Stub
Native_score NV = new Native_score ("E:\\lucene project \ \ Index file");
}
}
Use score for natural sorting in Lucene