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 Swati Singhal <sw...@yahoo.com> on 2005/01/12 10:13:40 UTC
Searching a document for a keyword
Hi,
I'm new to Lucene and also this forum.
I have a txt file, which contains the path to jpg
files. These jpg files are organized into folders.
My search is limited to searching only this txt file.
So when i search based on a folder name, a match is
found in the txt file, but i want it to return me the
entire line as a search result and not the document
name. (which is the txt file)
How can I do that using Lucene?
I have already built the index by giving the txt file
as an input to build the index.
If this is not possible, please tell me a way to parse
jpg files to form an index file.
Thanks,
Swati
=====
__________________________________
Do you Yahoo!?
Yahoo! Mail - Helps protect you from nasty viruses.
http://promotions.yahoo.com/new_mail
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: Searching a document for a keyword
Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Jan 12, 2005, at 4:13 AM, Swati Singhal wrote:
> I have a txt file, which contains the path to jpg
> files. These jpg files are organized into folders.
> My search is limited to searching only this txt file.
>
> So when i search based on a folder name, a match is
> found in the txt file, but i want it to return me the
> entire line as a search result and not the document
> name. (which is the txt file)
>
> How can I do that using Lucene?
> I have already built the index by giving the txt file
> as an input to build the index.
>
> If this is not possible, please tell me a way to parse
> jpg files to form an index file.
First let me re-phrase what I think you want. You want to be able to
search on a folder name and retrieve back JPG filenames that are in
that folder. Correct?
You're using the text file as simply a way to get text into Lucene?
Does this text file have any other relevance here?
If you have a folder of JPG images and all you're after is their
filenames and the results granularity to be a JPG image file name,
write a simple file system crawler that recurses your directory tree,
and indexes a single document for each JPG, with a field for
"filename". What type of field should the "filename" field be? That
depends on how you want to search. You could make it a
Field.Keyword(), which would require exact (TermQuery) or PrefixQuery's
to work.
The Indexer example from Lucene in Action makes a great starting place
for this crawler - you'd have to adapt it to recognize .jpg extensions
and adjust it to only index the filename, not the contents (though the
contents may contain text and be worth indexing also).
Erik
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org
Re: Searching a document for a keyword
Posted by Miles Barr <mi...@runtime-collective.com>.
On Wed, 2005-01-12 at 01:13 -0800, Swati Singhal wrote:
> I have a txt file, which contains the path to jpg
> files. These jpg files are organized into folders.
> My search is limited to searching only this txt file.
>
> So when i search based on a folder name, a match is
> found in the txt file, but i want it to return me the
> entire line as a search result and not the document
> name. (which is the txt file)
>
> How can I do that using Lucene?
> I have already built the index by giving the txt file
> as an input to build the index.
>
> If this is not possible, please tell me a way to parse
> jpg files to form an index file.
Lucene might be overkill in this situation if you don't need it's more
advanced text searching facilities, i.e. you're only searching for exact
matches for folder names and never need to tokenize the search term.
If you still want to use Lucene the approach I would take would be to
have one Document in Lucene per folder name in the text file. Within
this document you store the list of JPG files, it might not even be
necessary to store them in separate fields from the sounds of your
requirements.
Start up parsing the text file and each time you find a new folder name
create a new Document. Assuming the entries in the file are of the form:
/folder-name/filename.jpg
It should be fairly straightforward to do using regular expressions.
If the text document is an unnecessary step I would follow the solution
described in Erik's reply.
--
Miles Barr <mi...@runtime-collective.com>
Runtime Collective Ltd.
---------------------------------------------------------------------
To unsubscribe, e-mail: lucene-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: lucene-user-help@jakarta.apache.org