Hoss - the main caveat with this approach is that a user could select
a different field from any of the designated text boxes. Putting
"subject:foo" in the name text box for example.
I think this is one of my biggest issues with QueryParser these days,
it exposes too much power. It's like giving a SQL text box to your
database application (read-only, of course). There are generally
fields not made for user querying.
Caveat asides, the technique you describe is a good one and worth
considering when dealing with these types of situations.
Erik
On Dec 19, 2005, at 2:14 PM, Chris Hostetter wrote:
: > I have moved from my approach:
: > Query query = QueryParser.parse("big lucene expression", "afield",
: > LuceneHelper.getAnalyzer());
: >
: > to building the query based on BooleanQuery, PhareQuery, TermQuery
: > etc...But before the analyzer was doing a bunch of work in my
incoming
: > words, and I dont see an easy way to do the same sort of stuff
to the
: > incoming words used in PhareQuery, TermQuery etc.
In addition to Erik's suggestion, something that i find frequently
makes
sense is to use the QueryParser in each case where you are dealing
with a
discrete "input string" -- and then combine them into a BooleanQuery
(along with any other progromatically generated TermQueries you
might want
for other reasons)
For example, it looks like your applciation is targeted at
searching email
right? let's assume your application allows the user to specify the
following inputs
* a text box for search words
* a text box for people's names/email
* pulldowns for picking date ranges
...and you want to look in the subject, body, and attachment fields
for
the input words (with differnet boosts) and in all of the header
fields
for the name/email input. you can builda Date object out of the
pulldown
yourself, and then do something like this with the two strings...
QueryParser subP = new QueryParser("subject",SomeAnalyzer)
QueryParser bodyP = new QueryParser("body",SomeAnalyzer)
QueryParser attachP = new QueryParser("attachemnts",SomeAnalyzer)
QueryParser headP = new QueryParser
("headers",AnalyzerThatKnowsAboutEmailAddress)
Query s = subP.parse(words);
s.setBoost(2.0)
Query b = bodyP.parse(words);
Query a = attachP.parse(words);
a.setBoost(0.5)
Query h = headP.parse(person);
h.setBoost(1.5)
BooleanQuery bq = new BooleanQuery();
bq.add(s,false,false);
bq.add(b,false,false);
bq.add(a,false,false);
bq.add(h,false,false);
...and then execute your search using a filter built from the date
range
pulldowns.
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]