lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Amin Mohammed-Coleman <ami...@gmail.com>
Subject Fwd: Field Not Present In Document
Date Fri, 26 Dec 2008 20:29:45 GMT


Begin forwarded message:

> From: Amin Mohammed-Coleman <aminmc@gmail.com>
> Date: 26 December 2008 20:19:02 GMT
> To: java-user@lucene.apache.org
> Subject: Field Not Present In Document
>
> 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!
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message