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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]