lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Keller" <>
Subject Lucene-MoreLikethis
Date Tue, 15 Jan 2013 20:22:03 GMT

I have a question about "MoreLikeThis" in Lucene, Java. I built up an index and want to find
similar documents. But I always get no results for my query, is always empty.
Can anyone find my mistake? Here is an example. (I use Lucene 4.0) 

public class HelloLucene { 
  public static void main(String[] args) throws IOException, ParseException { 
   StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_40); 
   Directory index = new RAMDirectory(); 
   IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_40, analyzer); 
    IndexWriter w = new IndexWriter(index, config); 
    addDoc(w, "Lucene in Action", "193398817"); 
    addDoc(w, "Lucene for Dummies", "55320055Z"); 
    addDoc(w, "Managing Gigabytes", "55063554A"); 
    addDoc(w, "The Art of Computer Science", "9900333X"); 
    // search 
    IndexReader reader =; 
    IndexSearcher searcher = new IndexSearcher(reader); 
    MoreLikeThis mlt = new MoreLikeThis(reader); 
    Query query =; 
    System.out.println(, 5).totalHits); 
  private static void addDoc(IndexWriter w, String title, String isbn) throws IOException
    Document doc = new Document(); 
    doc.add(new TextField("title", title, Field.Store.YES)); 
    // use a string field for isbn because we don't want it tokenized 
    doc.add(new StringField("isbn", isbn, Field.Store.YES)); 

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message