lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kamal Najib <kamal.na...@mytum.de>
Subject get the cosine similarity between two docs
Date Mon, 04 May 2009 11:34:34 GMT
Hi all, 
I try to get the cosine similarity between two docs:
I have tried first to create a document for a String like this:
Document doc1=new Document();
doc1.add(new Field("term","nodular lesions over years responding kamal najib nodular lesions
over years responding",Field.Store.YES,Field.Index.TOKENIZED));
Document doc2=new Document();
doc2.add(new Field("term","we describe 5 cases( kamal najib , 61 years old )",Field.Store.YES,Field.Index.TOKENIZED));
than add the both docs to an indexWriter:
writer.addDocument(doc1);
writer.addDocument(doc2);

then create a query from the doc2 :
IndexReader ir=IndexReader.open(directory);
MoreLikeThis mlt=new MoreLikeThis(ir);
Query query=mlt.like(1);
and then search the query:
IndexSearcher searcher=new IndexSearcher(directory);
ScoreDoc[] scoreDocs=searcher.search(query,5);

then the lenght of the scoreDocs array was 0.Mean that the two docs are not similar?when are
two docs similar in this apraotch?how can i check the correctness  of the similarity result?do
i do somthing wrong?
thanks.
Kamal
-- 


Mime
View raw message