You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by kun xiong <xi...@gmail.com> on 2011/01/20 03:41:30 UTC
Which QueryParser to use
Hi all
We are planning to move our search core from Lucene library to Solr, and
we are new here.
We have a question :which parser we should choose?
Our original query for Lucene is kinda of complicated
Ex: *+((name1:A name2:B)^1000 (category1:C ^100 category:D ^10) ^100)
+(location1:E location2:F location3:G)~2*
Does the *dismax *query parser can handle this case, what's the alternative?
Or we can still use the *lucene *query parser without
setMinimumNumberShouldMatch,
which is not involved in lucene query parser.
Thanks
Kun
Re: Which QueryParser to use
Posted by kun xiong <xi...@gmail.com>.
Okey, thanks very much.
2011/1/21 Ahmet Arslan <io...@yahoo.com>
> > We construct our lucene query after certain analysis(ex :
> > words
> > segmentation, category identification).
>
> By analysis, I referring charfilter(s)+tokenizer+tokenfilter(s)
> combination.
>
> > Do you mean we
> > plugin those analysis
> > logic and query construction part onto solr, and solr takes
> > the very
> > beginning input.
> >
>
> I didn't understand what "very beginning input" is.
>
> Lets say you have pure java program that takes a String as an input, and
> returns org.apache.lucene.search.Query as output. You can embed this into
> solr. e.g. Query constructMyMagicQuery(String)
>
> public QParser createParser(String qstr, SolrParams localParams, SolrParams
> params, SolrQueryRequest req) {
> return new QParser(qstr, localParams, params, req) {
> public Query parse() throws ParseException {
> String query = params.get(CommomParams.Q);
> return constructMyMagicQuery(query);
> }
> }
> }
>
> Your custom program can read/use any key-value pairs from the search URL,
> if required.
>
>
>
>
Re: Which QueryParser to use
Posted by Ahmet Arslan <io...@yahoo.com>.
> We construct our lucene query after certain analysis(ex :
> words
> segmentation, category identification).
By analysis, I referring charfilter(s)+tokenizer+tokenfilter(s) combination.
> Do you mean we
> plugin those analysis
> logic and query construction part onto solr, and solr takes
> the very
> beginning input.
>
I didn't understand what "very beginning input" is.
Lets say you have pure java program that takes a String as an input, and returns org.apache.lucene.search.Query as output. You can embed this into solr. e.g. Query constructMyMagicQuery(String)
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) {
return new QParser(qstr, localParams, params, req) {
public Query parse() throws ParseException {
String query = params.get(CommomParams.Q);
return constructMyMagicQuery(query);
}
}
}
Your custom program can read/use any key-value pairs from the search URL, if required.
Re: Which QueryParser to use
Posted by kun xiong <xi...@gmail.com>.
Thanks a lot for your reply.That was very helpful.
We construct our lucene query after certain analysis(ex : words
segmentation, category identification). Do you mean we plugin those analysis
logic and query construction part onto solr, and solr takes the very
beginning input.
Kun
2011/1/20 Ahmet Arslan <io...@yahoo.com>
> > We construct our query by Lucene API
> > before, as BooleanQuery, TermQuery
> > those kind of things.
>
>
> Okey, it seems that your field are not analyzed and you don't do any
> analysis while construction of your query by Lucene API. Correct?
>
> Then you can use your existing Java code directly inside a solr plugin.
>
> http://wiki.apache.org/solr/SolrPlugins#QParserPlugin
>
> Existing sub-classes QParserPlugin can give you an idea.
>
>
>
>
Re: Which QueryParser to use
Posted by Ahmet Arslan <io...@yahoo.com>.
> We construct our query by Lucene API
> before, as BooleanQuery, TermQuery
> those kind of things.
Okey, it seems that your field are not analyzed and you don't do any analysis while construction of your query by Lucene API. Correct?
Then you can use your existing Java code directly inside a solr plugin.
http://wiki.apache.org/solr/SolrPlugins#QParserPlugin
Existing sub-classes QParserPlugin can give you an idea.
Re: Which QueryParser to use
Posted by kun xiong <xi...@gmail.com>.
We construct our query by Lucene API before, as BooleanQuery, TermQuery
those kind of things.
The string I provided is value from Query.toString() methord. Type are all
String.
2011/1/20 Ahmet Arslan <io...@yahoo.com>
> > Hi all
> > We are planning to move our search core from
> > Lucene library to Solr, and
> > we are new here.
> >
> > We have a question :which parser we should choose?
> >
> > Our original query for Lucene is kinda of complicated
> > Ex: *+((name1:A name2:B)^1000 (category1:C ^100
> > category:D ^10) ^100)
> > +(location1:E location2:F location3:G)~2*
> >
> > Does the *dismax *query parser can handle this case, what's
> > the alternative?
> >
> > Or we can still use the *lucene *query parser without
> > setMinimumNumberShouldMatch,
> > which is not involved in lucene query parser.
>
> As I understand you were constructing your queries programmatically,
> without using Lucene's QueryParser, right? If yes how were you handling
> analysis of query terms? Can you tell the types of these fields
> (location,name)?
>
>
>
>
Re: Which QueryParser to use
Posted by Jonathan Rochkind <ro...@jhu.edu>.
On 1/20/2011 1:42 AM, kun xiong wrote:
> Thar example string means our query is BooleanQuery containing
> BooleanQuerys.
>
> I am wondering how to write a complicated BooleanQuery for dismax, like (A
> or B or C) and (D or E)
>
> Or I have to use Lucene query parser.
You can't do it with dismax. You might be able to do it with edismax,
which is in Solr trunk/4.0 or as a patch to 1.4.
You can also do it, in 1.4, with "nested queries" with dismax queries
nested in a 'lucene' query.
But why would you want to? What do you actually want to do? The dismax
parser is great for taking user-entered queries and just sending them
straight to Solr. Is that why you're interested in it? It's also a
convenient way to search a query over multiple fields with different
boosts in different fields, or with other useful boosts like phrase
boosts and such. Is that why you're interested in it? Or something
else? Depending on what you want from it, the easiest solution may be
different. Or if you don't want _anything_ from it, and are happy with a
straight lucene-style query, then there's no reason to do use it, just
use the straight 'lucene' query parser, no problem.
Re: Which QueryParser to use
Posted by kun xiong <xi...@gmail.com>.
Thar example string means our query is BooleanQuery containing
BooleanQuerys.
I am wondering how to write a complicated BooleanQuery for dismax, like (A
or B or C) and (D or E)
Or I have to use Lucene query parser.
2011/1/20 Lalit Kumar 4 <lk...@sapient.com>
>
> Sent on my BlackBerry® from Vodafone
>
> -----Original Message-----
> From: Ahmet Arslan <io...@yahoo.com>
> Date: Thu, 20 Jan 2011 10:43:46
> To: solr-user@lucene.apache.org<so...@lucene.apache.org>
> Reply-To: "solr-user@lucene.apache.org" <so...@lucene.apache.org>
> Subject: Re: Which QueryParser to use
>
> > Hi all
> > We are planning to move our search core from
> > Lucene library to Solr, and
> > we are new here.
> >
> > We have a question :which parser we should choose?
> >
> > Our original query for Lucene is kinda of complicated
> > Ex: *+((name1:A name2:B)^1000 (category1:C ^100
> > category:D ^10) ^100)
> > +(location1:E location2:F location3:G)~2*
> >
> > Does the *dismax *query parser can handle this case, what's
> > the alternative?
> >
> > Or we can still use the *lucene *query parser without
> > setMinimumNumberShouldMatch,
> > which is not involved in lucene query parser.
>
> As I understand you were constructing your queries programmatically,
> without using Lucene's QueryParser, right? If yes how were you handling
> analysis of query terms? Can you tell the types of these fields
> (location,name)?
>
>
>
>
Re: Which QueryParser to use
Posted by Lalit Kumar 4 <lk...@sapient.com>.
Sent on my BlackBerry® from Vodafone
-----Original Message-----
From: Ahmet Arslan <io...@yahoo.com>
Date: Thu, 20 Jan 2011 10:43:46
To: solr-user@lucene.apache.org<so...@lucene.apache.org>
Reply-To: "solr-user@lucene.apache.org" <so...@lucene.apache.org>
Subject: Re: Which QueryParser to use
> Hi all
> We are planning to move our search core from
> Lucene library to Solr, and
> we are new here.
>
> We have a question :which parser we should choose?
>
> Our original query for Lucene is kinda of complicated
> Ex: *+((name1:A name2:B)^1000 (category1:C ^100
> category:D ^10) ^100)
> +(location1:E location2:F location3:G)~2*
>
> Does the *dismax *query parser can handle this case, what's
> the alternative?
>
> Or we can still use the *lucene *query parser without
> setMinimumNumberShouldMatch,
> which is not involved in lucene query parser.
As I understand you were constructing your queries programmatically, without using Lucene's QueryParser, right? If yes how were you handling analysis of query terms? Can you tell the types of these fields (location,name)?
Re: Which QueryParser to use
Posted by Ahmet Arslan <io...@yahoo.com>.
> Hi all
> We are planning to move our search core from
> Lucene library to Solr, and
> we are new here.
>
> We have a question :which parser we should choose?
>
> Our original query for Lucene is kinda of complicated
> Ex: *+((name1:A name2:B)^1000 (category1:C ^100
> category:D ^10) ^100)
> +(location1:E location2:F location3:G)~2*
>
> Does the *dismax *query parser can handle this case, what's
> the alternative?
>
> Or we can still use the *lucene *query parser without
> setMinimumNumberShouldMatch,
> which is not involved in lucene query parser.
As I understand you were constructing your queries programmatically, without using Lucene's QueryParser, right? If yes how were you handling analysis of query terms? Can you tell the types of these fields (location,name)?