Hi, let me see if I have got the idea. For example,
if I want to search the database for articles written
by Elizabeth Castro, we do what is shown below in
Lucene:
Query query = QueryParser.parse("creator:\"Elizabeth
Castro\"",
"creator",
new StandardAnalyzer());
indexSearcher.search(query);
Nonetheless, both "creator" and the name of the
creator are variables. We depend on the user to give
us the information and we pass the information to form
a query; probably this way:
public static final Query getQuery(
String value,
String field) throws ParameterException {
try {
return QueryParser.parse(value,field,
getAnalyzer());
}
catch (ParseException e) {
throw new ParameterException(e);
}
} // end getQuery()
Now, if we want to search the database for all
articles by Elizabeth Castro in the Computer Science
category, we do something like below:
Query query = QueryParser.parse("creator:\"Elizabeth
Castro\" AND category:\"Computer Science\"",
"creator" AND "category", // Is this right?
new StandardAnalyzer());
indexSearcher.search(query);
I think I want to put my hand on the idea on how to
pass the information (two pairs of field and its
value) provided by a user to form a query. Should I
do this:
public static final Query getQuery(
String value1,
String field1,
String value2,
String field2) throws ParameterException {
try {
return
QueryParser.parse(value1,field1,value2,field2,
getAnalyzer());
}
catch (ParseException e) {
throw new ParameterException(e);
}
} // end getQuery()
In the above code snippet, we have
return QueryParser.parse(value1,field1,value2,field2,
getAnalyzer());
How does the Luncene know it is AND instead of OR we
want?
--- Morus Walter <[EMAIL PROTECTED]>
wrote:
> Caroline Jen writes:
>
> > I have a sample program that takes care of the
> search
> > based on "one single pair of property and value"
> in
> > the database. For example, visitors of the web
> site
> > can retrieve all articles written by Elizabeth
> Castro.
> > "creator" is the property and "Elizabeth Castro"
> is
> > the value and they constitute one single pair of
> > property and value. The method signature of the
> > search is:
> >
> > findByProperty(this,property,value);
>
> Is it? Which type of lucene object has such a
> method?
> >
> > What is the method signature in Lucene if I want
> to
> > search the database based on "two pairs of
> property
> > and value"? For example, I want to retrieve all
> > articles written by Elizabeth Castro in the
> "computer
> > science" category?
> >
> > Am I on the right track? Does my question make
> sense?
> >
> I don't think so.
>
> The method signature for a search in lucene is (in
> the easiest case)
> hits = search(query)
> where search is a method of a searcher object, and
> query is a query object.
> Basically there are two ways to create a query
> object:
> a) use the query parser
> b) construct it yourself
>
> Option a) allowes to formulate queries with the
> options described in
>
http://jakarta.apache.org/lucene/docs/queryparsersyntax.html.
> For a single field a query might look like 'some
> term' with the
> field defined as the default field.
> To search other fields than the default field, you
> can use <fieldname>:term.
> To combine subqueries you can use logical operators
> like AND, OR...
> So a query might look like
> creator:Castro AND category:computer
>
> If you want to construct the query yourself you have
> to look at the
> API docs and the different types of query
> subclasses.
> E.g. you could combine two TermQuery objects with a
> BooleanQuery object.
>
> HTH
> Morus
>
>
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
>
__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]