AnsweredAssumed Answered

Created object Lucene IndexReader gives no result on search

Question asked by stijndereede on Nov 30, 2007
Since I haven't been able to solve the problem from this post: http://forums.alfresco.com/viewtopic.php?t=9820, I'm trying an alternative.

I still want to do a Similar Documents query, but now I try to create the Lucene IndexReader object myself, with the indexes in all the subdirectories in the directory /alf_data/lucene-indexes/workspace/SpacesStore:


        File[] dirs = new File("D:/alfresco220dev/alf_data/lucene-indexes/workspace/SpacesStore").listFiles();
        ArrayList<IndexReader> readers = new ArrayList<IndexReader>();
        for (int i = 0; i < dirs.length; i++) {
           if (dirs[i].isDirectory()) {
              if (new File(dirs[i] + "/segments.gen").exists()) {
                 readers.add(IndexReader.open(dirs[i]));
              }
           }
        }

        MultiReader reader = new MultiReader(readers.toArray(new IndexReader[0]));
        PrintStream o = System.out;
        o.println("Open index " + indexName + " which has " + reader.numDocs() + " docs");

This gives the correct output, 1921 documents are in the index.

However, I cannot find anything within this index:

        IndexSearcher is = new IndexSearcher(reader);
        Query q = new TermQuery(new Term("PRIMARYPARENT", "\"2db33c9f\""));
        System.out.println("Query: " + q);
        Hits hits = is.search(q);
        int len = hits.length();
        o.println("found: " + len + " documents matching");

The PRIMARYPARENT fieldname I got from the  reader.document(i).getFields() List method.
Also, searching for "TEXT:something" or "cm\:content:something" gives no  results…

When I list the fields of each document with getFields(), I cannot see any field containing the content that is (tokenized and) indexed.


Does anybody have any suggestions on how the construct a similar document search?

Outcomes