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 Abin Mathew <ab...@toostep.com> on 2010/01/29 06:30:08 UTC

Newbie Question on Custom Query Generation

Hi I want to generate my own customized query from the input string entered
by the user. It should look something like this

*Search field : Microsoft*
*
Generated Query*  :
description:microsoft +((tags:microsoft^1.5 title:microsoft^3.0
role:microsoft requi
rement:microsoft company:microsoft city:microsoft)^5.0) tags:microsoft^2.0
title:microsoft^3.5 functionalArea:microsoft

*The lucene code we used is like this*
BooleanQuery must = new BooleanQuery();

addToBooleanQuery(must, "tags", inputData, synonymAnalyzer, 1.5f);
addToBooleanQuery(must, "title", inputData, synonymAnalyzer);
addToBooleanQuery(must, "role", inputData, synonymAnalyzer);
addToBooleanQuery(query, "description", inputData, synonymAnalyzer);
addToBooleanQuery(must, "requirement", inputData, synonymAnalyzer);
addToBooleanQuery(must, "company", inputData, standardAnalyzer);
addToBooleanQuery(must, "city", inputData, standardAnalyzer);
must.setBoost(5.0f);
query.add(must, Occur.MUST);
addToBooleanQuery(query, "tags", includeAll, synonymAnalyzer, 2.0f);
addToBooleanQuery(query, "title", includeAll, synonymAnalyzer, 3.5f);
addToBooleanQuery(query, "functionalArea", inputData, synonymAnalyzer,);
*
In Simple english*
addToBooleanQuery will add the particular field to the query after analysing
using the analyser mentioned and setting a boost as specified
So there "MUST" be a keyword match with any of the fields
tags,title,role,description,requirement,company,city and it "SHOULD" occur
in the fields tags,title and functionalArea.

Hope you have got an idea of my requirement. I am not asking anyone to do it
for me. Please let me know where can i start and give me some useful tips to
move ahead with this. I believe that it has to do with modifying the XML
configuration file and setting the parameters in Dismax handler. But I am
still not sure. Please help

Thanks & Regards
Abin Mathew

Re: Newbie Question on Custom Query Generation

Posted by Erik Hatcher <er...@gmail.com>.
dismax won't quite give you the same query result.  What you can do  
pretty easily, though, is create a QParser and QParserPlugin pair,  
register it solrconfig.xml and then use &defType=<name registered>.   
Pretty straightforward.  Have a look at Solr's various QParserPlugin  
implementations for details.

	Erik

On Jan 29, 2010, at 12:30 AM, Abin Mathew wrote:

> Hi I want to generate my own customized query from the input string  
> entered
> by the user. It should look something like this
>
> *Search field : Microsoft*
> *
> Generated Query*  :
> description:microsoft +((tags:microsoft^1.5 title:microsoft^3.0
> role:microsoft requi
> rement:microsoft company:microsoft city:microsoft)^5.0)  
> tags:microsoft^2.0
> title:microsoft^3.5 functionalArea:microsoft
>
> *The lucene code we used is like this*
> BooleanQuery must = new BooleanQuery();
>
> addToBooleanQuery(must, "tags", inputData, synonymAnalyzer, 1.5f);
> addToBooleanQuery(must, "title", inputData, synonymAnalyzer);
> addToBooleanQuery(must, "role", inputData, synonymAnalyzer);
> addToBooleanQuery(query, "description", inputData, synonymAnalyzer);
> addToBooleanQuery(must, "requirement", inputData, synonymAnalyzer);
> addToBooleanQuery(must, "company", inputData, standardAnalyzer);
> addToBooleanQuery(must, "city", inputData, standardAnalyzer);
> must.setBoost(5.0f);
> query.add(must, Occur.MUST);
> addToBooleanQuery(query, "tags", includeAll, synonymAnalyzer, 2.0f);
> addToBooleanQuery(query, "title", includeAll, synonymAnalyzer, 3.5f);
> addToBooleanQuery(query, "functionalArea", inputData,  
> synonymAnalyzer,);
> *
> In Simple english*
> addToBooleanQuery will add the particular field to the query after  
> analysing
> using the analyser mentioned and setting a boost as specified
> So there "MUST" be a keyword match with any of the fields
> tags,title,role,description,requirement,company,city and it "SHOULD"  
> occur
> in the fields tags,title and functionalArea.
>
> Hope you have got an idea of my requirement. I am not asking anyone  
> to do it
> for me. Please let me know where can i start and give me some useful  
> tips to
> move ahead with this. I believe that it has to do with modifying the  
> XML
> configuration file and setting the parameters in Dismax handler. But  
> I am
> still not sure. Please help
>
> Thanks & Regards
> Abin Mathew


Re: Newbie Question on Custom Query Generation

Posted by Abin Mathew <ab...@toostep.com>.
Hi, I realized the power of Dismax Query Handler recently and now I
dont need to generate my own query since Dismax is giving better
results.Thanks a lot

2010/1/29 Wangsheng Mei <ha...@gmail.com>:
> What's the point of generating your own query?
> Are you sure that solr query syntax cannot satisfy your need?
>
> 2010/1/29 Abin Mathew <ab...@toostep.com>
>
>> Hi I want to generate my own customized query from the input string entered
>> by the user. It should look something like this
>>
>> *Search field : Microsoft*
>> *
>> Generated Query*  :
>> description:microsoft +((tags:microsoft^1.5 title:microsoft^3.0
>> role:microsoft requi
>> rement:microsoft company:microsoft city:microsoft)^5.0) tags:microsoft^2.0
>> title:microsoft^3.5 functionalArea:microsoft
>>
>> *The lucene code we used is like this*
>> BooleanQuery must = new BooleanQuery();
>>
>> addToBooleanQuery(must, "tags", inputData, synonymAnalyzer, 1.5f);
>> addToBooleanQuery(must, "title", inputData, synonymAnalyzer);
>> addToBooleanQuery(must, "role", inputData, synonymAnalyzer);
>> addToBooleanQuery(query, "description", inputData, synonymAnalyzer);
>> addToBooleanQuery(must, "requirement", inputData, synonymAnalyzer);
>> addToBooleanQuery(must, "company", inputData, standardAnalyzer);
>> addToBooleanQuery(must, "city", inputData, standardAnalyzer);
>> must.setBoost(5.0f);
>> query.add(must, Occur.MUST);
>> addToBooleanQuery(query, "tags", includeAll, synonymAnalyzer, 2.0f);
>> addToBooleanQuery(query, "title", includeAll, synonymAnalyzer, 3.5f);
>> addToBooleanQuery(query, "functionalArea", inputData, synonymAnalyzer,);
>> *
>> In Simple english*
>> addToBooleanQuery will add the particular field to the query after
>> analysing
>> using the analyser mentioned and setting a boost as specified
>> So there "MUST" be a keyword match with any of the fields
>> tags,title,role,description,requirement,company,city and it "SHOULD" occur
>> in the fields tags,title and functionalArea.
>>
>> Hope you have got an idea of my requirement. I am not asking anyone to do
>> it
>> for me. Please let me know where can i start and give me some useful tips
>> to
>> move ahead with this. I believe that it has to do with modifying the XML
>> configuration file and setting the parameters in Dismax handler. But I am
>> still not sure. Please help
>>
>> Thanks & Regards
>> Abin Mathew
>>
>
>
>
> --
> 梅旺生
>

Re: Newbie Question on Custom Query Generation

Posted by Wangsheng Mei <ha...@gmail.com>.
What's the point of generating your own query?
Are you sure that solr query syntax cannot satisfy your need?

2010/1/29 Abin Mathew <ab...@toostep.com>

> Hi I want to generate my own customized query from the input string entered
> by the user. It should look something like this
>
> *Search field : Microsoft*
> *
> Generated Query*  :
> description:microsoft +((tags:microsoft^1.5 title:microsoft^3.0
> role:microsoft requi
> rement:microsoft company:microsoft city:microsoft)^5.0) tags:microsoft^2.0
> title:microsoft^3.5 functionalArea:microsoft
>
> *The lucene code we used is like this*
> BooleanQuery must = new BooleanQuery();
>
> addToBooleanQuery(must, "tags", inputData, synonymAnalyzer, 1.5f);
> addToBooleanQuery(must, "title", inputData, synonymAnalyzer);
> addToBooleanQuery(must, "role", inputData, synonymAnalyzer);
> addToBooleanQuery(query, "description", inputData, synonymAnalyzer);
> addToBooleanQuery(must, "requirement", inputData, synonymAnalyzer);
> addToBooleanQuery(must, "company", inputData, standardAnalyzer);
> addToBooleanQuery(must, "city", inputData, standardAnalyzer);
> must.setBoost(5.0f);
> query.add(must, Occur.MUST);
> addToBooleanQuery(query, "tags", includeAll, synonymAnalyzer, 2.0f);
> addToBooleanQuery(query, "title", includeAll, synonymAnalyzer, 3.5f);
> addToBooleanQuery(query, "functionalArea", inputData, synonymAnalyzer,);
> *
> In Simple english*
> addToBooleanQuery will add the particular field to the query after
> analysing
> using the analyser mentioned and setting a boost as specified
> So there "MUST" be a keyword match with any of the fields
> tags,title,role,description,requirement,company,city and it "SHOULD" occur
> in the fields tags,title and functionalArea.
>
> Hope you have got an idea of my requirement. I am not asking anyone to do
> it
> for me. Please let me know where can i start and give me some useful tips
> to
> move ahead with this. I believe that it has to do with modifying the XML
> configuration file and setting the parameters in Dismax handler. But I am
> still not sure. Please help
>
> Thanks & Regards
> Abin Mathew
>



-- 
梅旺生