lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grant Ingersoll <gsing...@apache.org>
Subject Re: Field Not Present In Document
Date Sun, 28 Dec 2008 19:50:07 GMT
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-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message