Hi

Thanks for your reply. It turns out you were correct and I was not loading the correct document. User error!


Cheers


Amin

On 28 Dec 2008, at 19:50, Grant Ingersoll <gsing...@apache.org> wrote:

How do you know that document in question has an id of 1, as in when you do: Document documentFromIndex = indexReader.document(1)

I would fire up Luke (http://www.getopt.org/luke) against your index and see what is inside of it.


On Dec 26, 2008, at 3:19 PM, Amin Mohammed-Coleman wrote:

Hi

I have the following situation:

Document document = new Document();
       String body ="This is a body of document";
Field field = new Field("body", body, Field.Store.YES, Field.Index.ANALYZED);
       document.add(field);

       String id ="1234";
Field idField = new Field("id", id, Field.Store.YES, Field.Index.ANALYZED);
       document.add(idField);
       rtfIndexer.add(document);
       System.out.println(document.getFields());



When I print the fields of the document I get the following:


stored/uncompressed,indexed,tokenized<body:This is a body of document>, stored/uncompressed,indexed,tokenized<id:1234>]


The RtfIndexer looks like this:

   public void add(Document document) {
IndexWriter rtfIndexWriter = IndexWriterFactory.createIndexWriter(rtfDirectory, analyzer);
       try {
           rtfIndexWriter.addDocument(document);
           LOGGER.debug("Added Document:" + document + " to index");
           commitAndOptimise(rtfIndexWriter);
       } catch (CorruptIndexException e) {
           throw new IllegalStateException(e);
       } catch (IOException e) {
           throw new IllegalStateException(e);
       }
   }

private void commitAndOptimise(IndexWriter rtfIndexWriter) throws CorruptIndexException,IOException {
       LOGGER.debug("Committing document and closing index writer");
       rtfIndexWriter.optimize();
       rtfIndexWriter.commit();
       rtfIndexWriter.close();
   }



However I load the Document using the below code:

       Directory directory = ((RtfIndexer)rtfIndexer).getDirectory();
       IndexReader indexReader = IndexReader.open(directory);
       Document documentFromIndex = indexReader.document(1);
       System.out.println(documentFromIndex.getFields());

I get:

[stored/uncompressed,indexed,tokenized<body:This is a body of document>]


It seems as though id field is not being stored in the Index...I can't understand why not as I can have added it to the document,


I would be grateful if anyone could help!


Cheers
Amin

P.S. Merry Christmas!


--------------------------
Grant Ingersoll

Lucene Helpful Hints:
http://wiki.apache.org/lucene-java/BasicsOfPerformance
http://wiki.apache.org/lucene-java/LuceneFAQ











---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org
For additional commands, e-mail: java-user-h...@lucene.apache.org

Reply via email to