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 mil84 <mi...@centrum.sk> on 2008/10/20 16:32:13 UTC
How to search in metadata? (filename, document title, cocument
creator, ...)
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 = is.search(createQuery(searchText));
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));
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: http://www.nabble.com/How-to-search-in-metadata--%28filename%2C-document-title%2C-cocument-creator%2C-...%29-tp20069124p20069124.html
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
Re: How to search in metadata? (filename, document title, cocument creator, ...)
Posted by Grant Ingersoll <gs...@apache.org>.
On Oct 20, 2008, at 5:07 PM, mil84 wrote:
>
> thx :) There was also another problem with filename (because I
> indexed full
> path, not only name). But I fixed it, and now it finally works.
>
> Last question - how to get number of hits in every document (not
> only global
> number of hits)? Best would be a simple example, if possible...
You'll have to use SpanQuery and it's derivatives for that. See the
javadocs and/or search the archives of the mailing list. I don't have
any examples handy, but I believe I did a talk on Span Queries a few
years back at ApacheCon.
>
> --
> View this message in context: http://www.nabble.com/How-to-search-in-metadata--%28filename%2C-document-title%2C-cocument-creator%2C-...%29-tp20069124p20078814.html
> 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
>
--------------------------
Grant Ingersoll
Lucene Boot Camp Training Nov. 3-4, 2008, ApacheCon US New Orleans.
http://www.lucenebootcamp.com
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
RE: How to search in metadata? (filename, document title, cocument
creator, ...)
Posted by mil84 <mi...@centrum.sk>.
thx :) There was also another problem with filename (because I indexed full
path, not only name). But I fixed it, and now it finally works.
Last question - how to get number of hits in every document (not only global
number of hits)? Best would be a simple example, if possible...
--
View this message in context: http://www.nabble.com/How-to-search-in-metadata--%28filename%2C-document-title%2C-cocument-creator%2C-...%29-tp20069124p20078814.html
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
RE: How to search in metadata? (filename, document title, cocument creator, ...)
Posted by Steven A Rowe <sa...@syr.edu>.
On 10/20/2008 at 12:41 PM, mil84 wrote:
> doc.add(new Field("Title", "hohoho", Field.Store.YES, Field.Index.TOKENIZED));
[...]
> 3) Searching in title - it DON'T WORK (I try to find hohoho, and nothing).
[...]
> QueryParser parser = new QueryParser("title", new StandardAnalyzer());
Field names are case-sensitive: "Title" != "title".
Steve
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: How to search in metadata? (filename, document title, cocument
creator, ...)
Posted by mil84 <mi...@centrum.sk>.
Ok, better example. For example I want to search pdf file.
1) Indexing:
Document doc = LucenePDFDocument.getDocument(f);
doc.add(new Field("contents", new FileReader(f)));
doc.add(new Field("filename", "Example.pdf", Field.Store.YES,
Field.Index.TOKENIZED));
doc.add(new Field("Creator", "John Smith", Field.Store.YES,
Field.Index.TOKENIZED));
doc.add(new Field("Title", "hohoho", Field.Store.YES,
Field.Index.TOKENIZED));
2) Searching in contents - it WORKS OK
QueryParser parser = new QueryParser("contents", new StandardAnalyzer());
Query q = parser.parse(searchText);
Hits hits = is.search(q);
3) Searching in title - it DON'T WORK (I try to find hohoho, and nothing).
Same with searching in creator, etc...
QueryParser parser = new QueryParser("title", new StandardAnalyzer());
Query q = parser.parse(searchText);
Hits hits = is.search(q);
I simple can't understand, where I made mistake? It's simple code...
--
View this message in context: http://www.nabble.com/How-to-search-in-metadata--%28filename%2C-document-title%2C-cocument-creator%2C-...%29-tp20069124p20073802.html
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
Re: How to search in metadata? (filename, document title, cocument creator, ...)
Posted by Erick Erickson <er...@gmail.com>.
If Grant's suggestions don't help you, some examples of your search
code would be helpful to further pinpoint things...
Best
Erick
On Mon, Oct 20, 2008 at 11:29 AM, Grant Ingersoll <gs...@apache.org>wrote:
>
> 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 = is.search(createQuery(searchText));
>>
>> 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:
>> http://www.nabble.com/How-to-search-in-metadata--%28filename%2C-document-title%2C-cocument-creator%2C-...%29-tp20069124p20069124.html
>> 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
>>
>>
> --------------------------
> Grant Ingersoll
> Lucene Boot Camp Training Nov. 3-4, 2008, ApacheCon US New Orleans.
> http://www.lucenebootcamp.com
>
>
> 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
>
>
Re: How to search in metadata? (filename, document title, cocument creator, ...)
Posted by Grant Ingersoll <gs...@apache.org>.
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 = is.search(createQuery(searchText));
>
> 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: http://www.nabble.com/How-to-search-in-metadata--%28filename%2C-document-title%2C-cocument-creator%2C-...%29-tp20069124p20069124.html
> 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
>
--------------------------
Grant Ingersoll
Lucene Boot Camp Training Nov. 3-4, 2008, ApacheCon US New Orleans.
http://www.lucenebootcamp.com
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