You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Alex Steward <al...@yahoo.com> on 2009/06/05 02:18:15 UTC

cannot retrieve the values of a field is not stored in the index


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



      

Re: cannot retrieve the values of a field is not stored in the index

Posted by Erick Erickson <er...@gmail.com>.
Enumerating terms will be inefficient compared to getting the stored field.I'd
try soring the fields first until and unless you can demonstrate a problem.
BTW, if you're not going to *search* on the field, there's no reason to
index
it at all.

Why do think you don't want to store the paths? How big is your index?
Are you running into any performance issues?

Best
Erick

On Fri, Jun 5, 2009 at 7:14 AM, Ian Lea <ia...@gmail.com> wrote:

> 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<al...@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
>
>

Re: cannot retrieve the values of a field is not stored in the index

Posted by Ian Lea <ia...@gmail.com>.
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<al...@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