Solr query with mandatory values

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Solr query with mandatory values

G.Long
Hi :)

I remember that in a Lucene query, there is something like mandatory
values. I just have to add a "+" symbol in front of the mandatory
parameter, like: +myField:my value

I was wondering if there was something similar in Solr queries? Or is
this behaviour activated by default?

Gary
Reply | Threaded
Open this post in threaded view
|

RE: Solr query with mandatory values

Matt Kuiper
Yes.  

See http://wiki.apache.org/solr/SolrQuerySyntax  - The standard Solr Query Parser syntax is a superset of the Lucene Query Parser syntax.
Which links to http://lucene.apache.org/core/3_6_0/queryparsersyntax.html 

Note - Based on the info on these pages I believe the "+" symbol is to be placed just before the mandatory value, not before the field name in the query.

Matt Kuiper
Intelligent Software Solutions

-----Original Message-----
From: G.Long [mailto:[hidden email]]
Sent: Wednesday, May 09, 2012 10:45 AM
To: [hidden email]
Subject: Solr query with mandatory values

Hi :)

I remember that in a Lucene query, there is something like mandatory values. I just have to add a "+" symbol in front of the mandatory parameter, like: +myField:my value

I was wondering if there was something similar in Solr queries? Or is this behaviour activated by default?

Gary


Reply | Threaded
Open this post in threaded view
|

Re: Solr query with mandatory values

Li Li
+ before term is correct. in lucene term includes field and value.

Query  ::= ( Clause )*

Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )

<#_TERM_CHAR: ( <_TERM_START_CHAR> | <_ESCAPED_CHAR> | "-" | "+" ) >

<#_ESCAPED_CHAR: "\\" ~[] >


in lucene query syntax, you can't express a term value including space.
you can use quotation mark but lucene will take it as a phrase query.
so you need escape space like title:hello\\ world
which will take "hello world" as a field value. and the analyzer then
will tokenize it. so you should use analyzer which can deal with
space. e.g. you can use keyword analyzer

as far as I know

On Thu, May 10, 2012 at 3:35 AM, Matt Kuiper <[hidden email]> wrote:

> Yes.
>
> See http://wiki.apache.org/solr/SolrQuerySyntax  - The standard Solr Query Parser syntax is a superset of the Lucene Query Parser syntax.
> Which links to http://lucene.apache.org/core/3_6_0/queryparsersyntax.html
>
> Note - Based on the info on these pages I believe the "+" symbol is to be placed just before the mandatory value, not before the field name in the query.
>
> Matt Kuiper
> Intelligent Software Solutions
>
> -----Original Message-----
> From: G.Long [mailto:[hidden email]]
> Sent: Wednesday, May 09, 2012 10:45 AM
> To: [hidden email]
> Subject: Solr query with mandatory values
>
> Hi :)
>
> I remember that in a Lucene query, there is something like mandatory values. I just have to add a "+" symbol in front of the mandatory parameter, like: +myField:my value
>
> I was wondering if there was something similar in Solr queries? Or is this behaviour activated by default?
>
> Gary
>
>
Reply | Threaded
Open this post in threaded view
|

Re: Solr query with mandatory values

Li Li
some sample codes:

                QueryParser parser=new QueryParser(Version.LUCENE_36, "title", new
KeywordAnalyzer());
               
                String q="+title:hello\\ world";
               
                Query query=parser.parse(q);
               
                System.out.println(query);

On Thu, May 10, 2012 at 8:20 AM, Li Li <[hidden email]> wrote:

> + before term is correct. in lucene term includes field and value.
>
> Query  ::= ( Clause )*
>
> Clause ::= ["+", "-"] [<TERM> ":"] ( <TERM> | "(" Query ")" )
>
> <#_TERM_CHAR: ( <_TERM_START_CHAR> | <_ESCAPED_CHAR> | "-" | "+" ) >
>
> <#_ESCAPED_CHAR: "\\" ~[] >
>
>
> in lucene query syntax, you can't express a term value including space.
> you can use quotation mark but lucene will take it as a phrase query.
> so you need escape space like title:hello\\ world
> which will take "hello world" as a field value. and the analyzer then
> will tokenize it. so you should use analyzer which can deal with
> space. e.g. you can use keyword analyzer
>
> as far as I know
>
> On Thu, May 10, 2012 at 3:35 AM, Matt Kuiper <[hidden email]> wrote:
>> Yes.
>>
>> See http://wiki.apache.org/solr/SolrQuerySyntax  - The standard Solr Query Parser syntax is a superset of the Lucene Query Parser syntax.
>> Which links to http://lucene.apache.org/core/3_6_0/queryparsersyntax.html
>>
>> Note - Based on the info on these pages I believe the "+" symbol is to be placed just before the mandatory value, not before the field name in the query.
>>
>> Matt Kuiper
>> Intelligent Software Solutions
>>
>> -----Original Message-----
>> From: G.Long [mailto:[hidden email]]
>> Sent: Wednesday, May 09, 2012 10:45 AM
>> To: [hidden email]
>> Subject: Solr query with mandatory values
>>
>> Hi :)
>>
>> I remember that in a Lucene query, there is something like mandatory values. I just have to add a "+" symbol in front of the mandatory parameter, like: +myField:my value
>>
>> I was wondering if there was something similar in Solr queries? Or is this behaviour activated by default?
>>
>> Gary
>>
>>