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 Sabeer Hussain <sh...@del.aithent.com> on 2013/02/04 09:57:50 UTC
Re: Getting Lucense Query from Solr query (Or converting Solr Query
to Lucense's query)
Hi,
Thanks for the reply. In my application, I am using some servlets to receive
the request from user since I need to authenticate the user and adding
conditions like userid=xxxx before sending the request to Solr Server using
one of the two approaches
1) Using SolrServer
SolrServer server = new CommonsHttpSolrServer(.....);
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(....);
QueryResponse response = server.query(params);
2) Using URLConnection
ModifiableSolrParams params = new ModifiableSolrParams();
params.set(....);
String paramString = params.toString();
URL url = new URL("http://localhost:8080/solr/select?"+paramString);
URLConnection connection = null;
try
{
connection = url.openConnection();
}
catch(Exception e)
{
e.printStackTrace();
}
..... reading the response
All I am doing is using SolrJ APIs. So, please tell me how I can get
SolrQueryRequest object or anything like that to get the instance of
QParserPlugin. Is it possible to create SolrQueryRequest from
HttpServletRequest? I would like to use SolrJ to create Lucense Query from
Solr query (but I do not know whether it is possible or not)
Regards
Sabeer
--
View this message in context: http://lucene.472066.n3.nabble.com/Getting-Lucense-Query-from-Solr-query-Or-converting-Solr-Query-to-Lucense-s-query-tp4031187p4038300.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Getting Lucense Query from Solr query (Or converting Solr Query
to Lucense's query)
Posted by Sabeer Hussain <sh...@del.aithent.com>.
It is working but I come across another problem. I am expecting same
parsedquery in the following two approaches but I am not getting it as same
Approach 1:
BooleanQuery myQuery = new BooleanQuery();
myQuery.add(new TermQuery(new Term("PATIENT_GENDER", "Male")),
BooleanClause.Occur.SHOULD);
myQuery.add(new TermQuery(new Term("STUDY_DIVISION","\"Cancer Center\"")),
BooleanClause.Occur.SHOULD);
System.out.println("parsedquery >>"+myQuery.toString());
output is
parsedquery >>PATIENT_GENDER:Male STUDY_DIVISION:"Cancer Center"
Approach 2:
String defaultField ="text";
String queryString = "PATIENT_GENDER:Male OR STUDY_DIVISION:\"Cancer
Center\"";
QueryParser qp = new QueryParser(Version.LUCENE_40, defaultField, new
StandardAnalyzer(Version.LUCENE_40));
System.out.println("querystring >>"+queryString);
Query q = qp.parse(queryString);
System.out.println("parsedquery >>"+q.toString());
output is
querystring >>PATIENT_GENDER:Male OR STUDY_DIVISION:"Cancer Center"
parsedquery >>PATIENT_GENDER:male STUDY_DIVISION:"cancer center"
In the Approach 2, the values are converted into lower case and due to that
I am not getting same results even though my querystring are same.
If I have some fq parameters (filter query), how I can parse the query for
lucene? Is there any place from where I can get more information about
these kind of programming? any book available?
-- Sabeer
--
View this message in context: http://lucene.472066.n3.nabble.com/Getting-Lucense-Query-from-Solr-query-Or-converting-Solr-Query-to-Lucense-s-query-tp4031187p4038753.html
Sent from the Solr - User mailing list archive at Nabble.com.
Re: Getting Lucense Query from Solr query (Or converting Solr Query
to Lucense's query)
Posted by Roman Chyla <ro...@gmail.com>.
You could use LocalSolrQueryRequest to create the request, but it is not
necessary, if all what you need is to get the lucene query parser, just do:
import org.apache.lucene.queryparser.classic.QueryParser
qp = new QueryParser(Version.LUCENE_40, defaultField, new SimpleAnalyzer());
Query q = qp.parse(queryString)
hth
roman
On Mon, Feb 4, 2013 at 3:57 AM, Sabeer Hussain <sh...@del.aithent.com>wrote:
> Hi,
> Thanks for the reply. In my application, I am using some servlets to
> receive
> the request from user since I need to authenticate the user and adding
> conditions like userid=xxxx before sending the request to Solr Server using
> one of the two approaches
>
> 1) Using SolrServer
> SolrServer server = new CommonsHttpSolrServer(.....);
> ModifiableSolrParams params = new ModifiableSolrParams();
> params.set(....);
> QueryResponse response = server.query(params);
>
> 2) Using URLConnection
> ModifiableSolrParams params = new ModifiableSolrParams();
> params.set(....);
> String paramString = params.toString();
>
> URL url = new URL("http://localhost:8080/solr/select?"+paramString);
> URLConnection connection = null;
> try
> {
> connection = url.openConnection();
> }
> catch(Exception e)
> {
> e.printStackTrace();
> }
>
> ..... reading the response
>
> All I am doing is using SolrJ APIs. So, please tell me how I can get
> SolrQueryRequest object or anything like that to get the instance of
> QParserPlugin. Is it possible to create SolrQueryRequest from
> HttpServletRequest? I would like to use SolrJ to create Lucense Query from
> Solr query (but I do not know whether it is possible or not)
>
>
> Regards
> Sabeer
>
>
>
> --
> View this message in context:
> http://lucene.472066.n3.nabble.com/Getting-Lucense-Query-from-Solr-query-Or-converting-Solr-Query-to-Lucense-s-query-tp4031187p4038300.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>