Dear all,
I have another trouble in one of my program using Lucene. I tried to compare the same
string and use the same analyzer to index it. You can see my code as following:
-----------------------------------------------------------------------------------------------------------------------------
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Hits;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Searcher;
public class LuceneIndexExample {
private static final String _indexDir ="c://lucene-index-dir";
public static void main(String args[]) throws Exception {
String sss = "All work and no play makes Jack a dull boy";
Analyzer analyzer = new StandardAnalyzer();
boolean flag = true;
IndexWriter writer = new IndexWriter(_indexDir, analyzer, flag);
Document document = new Document();
document.add(Field.Text("champs", sss));
writer.addDocument(document);
writer.close();
Searcher s = new IndexSearcher(_indexDir);
String str = "All work and no play makes Jack a dull boy";
Query q = QueryParser.parse(str, "champs", analyzer);
Hits hits = s.search(q);
try {
for (int i=0; i<=hits.length();i++){
System.out.println("score of "+ i +" = "+hits.score(i));
}
} catch (IndexOutOfBoundsException e){
}
}
}
------------------------------------------------------------------------------------------------------------------
I think i should get "1.0" as the score from the hits collection but got "0.30444607"
instead.
SOMEBODY KNOWS WHY IT'S GONE LIKE THIS? PLEASE HELP!
Thanks before hand.
Uddam
---------------------------------
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger