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!

Reply via email to