lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Erick Erickson" <erickerick...@gmail.com>
Subject Re: Create and populate a field when indexing
Date Mon, 12 Nov 2007 19:22:01 GMT
Sure, that'd work. It would also work to just continue to use
f.getPath() whenever you need it.

FWIW
Erick


On Nov 12, 2007 1:43 PM, KR <Keith.Rhodes.ext@siemens.com> wrote:

>
>
> Erick Erickson wrote:
> >
> > Sure, just define it in the same scope as you want to refer to it.
> > Of course, that tells you nothing <G>...
> >
> > Java variables go out of scope when the last '}' *at the same level*
> > is passed. For intance:
> >
> > {
> >    string s1;
> >    {
> >       string s2;
> >    } // s2 is out of scope after this line.
> >    // s1 is still available
> > }
> > //s1 no longer available.
> >
> > So just define your category string "at the appropriate place" outside
> the
> > if statement and it will be available *after* the if. You may need to
> move
> > it outside the enclosing braces. Or outside the enclosing braces
> > outside the enclosing braces (as many levels as your braces are
> > nested that you want to refer to that variable).
> >
> >
>
>
> Thanks, I understand that better now... (I hope).
>
> It looks like the best way to do this would be to extract the filename
> from
> the path  just after the code snippet below:
>
>
>  public static Document Document(File f)
>       throws IOException, InterruptedException  {
>    // make a new, empty document
>    Document doc = new Document();
>
>    // Add the url as a field named "path".  Use a field that is
>    // indexed (i.e. searchable), but don't tokenize the field into words.
>    doc.add(new Field("path", f.getPath().replace(dirSep, '/'),
> Field.Store.YES,
>        Field.Index.UN_TOKENIZED));
>
>
> This way the filename is available for all the subsequent if {} blocks.
>
> Keith.
> --
> View this message in context:
> http://www.nabble.com/Create-and-populate-a-field-when-indexing-tf4713018.html#a13711541
> Sent from the Lucene - Java Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

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