lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ian Lea <ian....@gmail.com>
Subject Re: cannot retrieve the values of a field is not stored in the index
Date Fri, 05 Jun 2009 11:14:41 GMT
You can't get at the field values from the document hits.
Field.Store.NO means it isn't stored and what isn't there can't be
retrieved.

But you should be able to get at the indexed paths via a TermEnum.
Something like this

  	IndexReader reader = IndexReader.open(...);
	String field = "path".intern();
	Term st = new Term("path", "");
	TermEnum te = reader.terms(st);
	while (true) {
	    Term t = te.term();
	    if (t == null || t.field() != field) {
		break;
	    }
	    System.out.println(t.text());
	    if (!te.next()) {
		break;
	    }
	}
    }


--
Ian.


On Fri, Jun 5, 2009 at 1:18 AM, Alex Steward<alex_lucene@yahoo.com> wrote:
>
>
> Hi,
>
>   Is there a way I can retrieve the value of a field that is not stored in the Index?
>
>
> private static void indexFile(IndexWriter writer, File f)
>     throws IOException {
>
>     if (f.isHidden() || !f.exists() || !f.canRead()) {
>       return;
>     }
>
>     System.out.println("Indexing " + f.getCanonicalPath());
>
>     Document doc = new Document();
>
>     // add contents of file
>     FileReader fr = new FileReader(f);
>
>     doc.add(new Field("contents", fr));
>
>     //adding second field which contains the path of the file
>     doc.add(new Field("path", f.getCanonicalPath(),
>                 Field.Store.NO,
>                 Field.Index.NOT_ANALYZED));
> }
>
> Is there a way I can access the value of the field "path" from the document hits?
>
> Thanks,
> a
>
>
>
>

---------------------------------------------------------------------
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