lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grant Ingersoll <>
Subject Re: How to search in metadata? (filename, document title, cocument creator, ...)
Date Mon, 20 Oct 2008 15:29:44 GMT

On Oct 20, 2008, at 10:32 AM, mil84 wrote:

> I've a problem witch searching. I need to search not only in file  
> contents,
> but also in metadata. But I don't know how to do it. My code:
> Document doc = new Document();
> doc.add(new Field("contents", new FileReader(f)));
> writer.addDocument(doc);
> ...
> QueryParser parser = new QueryParser("contents", new  
> StandardAnalyzer());
> Query q = parser.parse(list.get(i));
> Hits hits =;
> Everything is ok, it searches document's contents. But how to search  
> for
> example in filenames? I I add this:
> doc.add(new Field("filename", f.getCanonicalPath(), Field.Store.YES,
> Field.Index.UN_TOKENIZED));

You'll have to tokenize the filename in order for it to match anything  
other than an exact query.  I believe the Lucene demo shows adding  
other fields.  Lucene doesn't have a concept of "metadata".  It only  
has a concept of Document and Fields.  It's up to you to put in your  
metadata, just as you have suggested here.  Try just making that  
filename Field a tokenized field and see what happens.

If you're looking for tools to get metadata from files, then have a  
look at Tika or Aperture, which can easily be paired with Lucene.   
Aperture, I believe, even comes with a Lucene example.

> it doesn't work. Same problem is searching in metadata...Anyone  
> knows how to
> do it? I browsed whole google 3 hours, but found nothing, not even  
> just one
> working example, simple nothing....Thanx a lot.
> -- 
> View this message in context:
> Sent from the Lucene - Java Users mailing list archive at
> ---------------------------------------------------------------------
> To unsubscribe, e-mail:
> For additional commands, e-mail:

Grant Ingersoll
Lucene Boot Camp Training Nov. 3-4, 2008, ApacheCon US New Orleans.

Lucene Helpful Hints:

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message