lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Erik Hatcher <e...@ehatchersolutions.com>
Subject Re: Query -- how to write
Date Sun, 10 Jul 2005 10:08:38 GMT

On Jul 10, 2005, at 12:40 AM, bib_lucene bib wrote:

> Hi All
>
> I am indexing a document like this...
>
> Document doc = new Document();
>   doc.add(Field.Text("contents", new FileReader(f)));
>   doc.add(Field.Text("filename",f.getCanonicalPath()));
>   Iterator it = fields.keySet().iterator();
>   String element = "";
>      while (it.hasNext()) {
>         element =  (String)it.next();
>         doc.add(Field.Text(element,(String)fields.get 
> (element)));  // also tried field.keyword
>      }
>      writer.addDocument(doc);
>      writer.optimize();
>      writer.close();
>
> So the lucene doc has the text of the uploaded doc and also some  
> params like author, date, etc.
>
> When I write my search
>
> String queryStr = request.getParameter("query");
>
> File indexDir = new File("c:/luceneindex");
>
> Directory fsDir = FSDirectory.getDirectory(indexDir,false);
>
> IndexSearcher is = new IndexSearcher(fsDir);
>
> Query query = QueryParser.parse(queryStr,"contents", new  
> StandardAnalyzer());
>
> Hits hits = is.search(query);
>
> Not surprisingly I get a match only if there is a word in the  
> contents of the document.
>
> Question: If my query should be able to search not only document  
> contents but also the other data added such as author how do I do  
> that.

There are two common options here:

     - MultiFieldQueryParser

     - Use an aggregate field for all searchable text

I personally prefer the aggregate field approach as it makes the  
queries much simpler under the covers.

     Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Mime
View raw message