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 Demian Katz <de...@villanova.edu> on 2011/09/20 15:39:14 UTC

Questions about LocalParams syntax

I'm using the LocalParams syntax combined with the _query_ pseudo-field to build an advanced search screen (built on Solr 1.4.1's Dismax handler), but I'm running into some syntax questions that don't seem to be addressed by the wiki page here:

http://wiki.apache.org/solr/LocalParams


1.)    How should I deal with repeating parameters?  If I use multiple boost queries, it seems that only the last one listed is used...  for example:

((_query_:"{!dismax qf=\"title^500 author^300 allfields\" bq=\"format:Book^50\" bq=\"format:Journal^150\"}test"))

                boosts Journals, but not Books.  If I reverse the order of the two bq parameters, then Books get boosted instead of Journals.  I can work around this by creating one bq with the clauses OR'ed together, but I would rather be able to apply multiple bq's like I can elsewhere.


2.)    What is the proper way to escape quotes?  Since there are multiple nested layers of double quotes, things get ugly and it's easy to end up with syntax errors.  I found that this syntax doesn't cause an error:


((_query_:"{!dismax qf=\"title^500 author^300 allfields\" bq=\"format:\\\"Book\\\"^50\" bq=\"format:\\\"Journal\\\"^150\"}test"))

                ...but it also doesn't work correctly - the boost queries are completely ignored in this example.  Perhaps this is more a problem related to  _query_ than to LocalParams syntax...  but either way, a solution would be great!

thanks,
Demian

Re: Questions about LocalParams syntax

Posted by Chris Hostetter <ho...@fucit.org>.
: 1.)  How should I deal with repeating parameters?  If I use multiple 
: boost queries, it seems that only the last one listed is used...  for 
: example:
: 
: ((_query_:"{!dismax qf=\"title^500 author^300 allfields\" bq=\"format:Book^50\" bq=\"format:Journal^150\"}test"))

Hmmm... that's either a bug or a silly limitation in the local params 
parsing -- I've file a Jira for it but i have no idea what the fix is (or 
if it was intentional for some odd reason)

https://issues.apache.org/jira/browse/SOLR-2798

...if you are interested in dig into the code to see what the cause might 
be and helping to work on a patch that would be awesome.

: 2.)  What is the proper way to escape quotes?  Since there are multiple 
: nested layers of double quotes, things get ugly and it's easy to end up 
: with syntax errors.  I found that this syntax doesn't cause an error:
	...
: ((_query_:"{!dismax qf=\"title^500 author^300 allfields\"  bq=\"format:\\\"Book\\\"^50\" bq=\"format:\\\"Journal\\\"^150\"}test"))

backslash escaping should work, but you need to keep in mind that both the 
LocalParam syntax and most query parsers treat '"' and '\' as significant 
characters, so you may have to escape them more times then you think

For instance, even w/o local params, if you wanted a bq that contained a 
literal '"', you'd need to escape it for the lucene query parser...

bq=foo_s:inner\"quote OR foo_s:other

if you then wanted to use that bq as a quoted local param, you'd need to 
escape both the '\' and the original '"' again ...

q={!dismax bq="foo_s:inner\\\"quote OR foo_s:other"}foo

...and if you then wanted to use that entire {!dismax ... } string inside 
of a quoted expression using the "_query_" hook of the Lucene QParser 
(which is what it looks like you are doig) you would need to escape *all* 
of those '\' and '"' characters once more....

q=bob OR _query_:"{!dismax bq=\"foo_s:inner\\\\\\\"quote OR foo_s:other\"}foo"

...and it should work (it does for me)

But the other thing you can do to make your life a *lot* simpler is to 
leverage the parameter derefrencing and put each logical query string into 
it's own parameter...

    q=bob OR _query_:"{!dismax bq=$myBq}foo"
  & myBq=foo_s:inner\"quote OR foo_s:other

...or really make youre life easy...

    qq=foo
  & q=bob OR _query_:"{!dismax bq=$myBq v=$qq}"
  & myBq=foo_s:inner\"quote OR foo_s:other






-Hoss

RE: Questions about LocalParams syntax

Posted by Demian Katz <de...@villanova.edu>.
Space-separation works for the qf field, but not for bq.  If I try a bq of "format:Book^50 format:Journal^150", I get a strange result -- I would expect in the case of a failed bq that either a) I would get a syntax error of some sort or b) I would get normal search results with no boosting applied.  Instead, I get a successful search result containing 0 entries.  Very odd!  Anyway, the solution that definitely works is joining the clauses with OR...  but I'd still love to be able to specify multiple bq's separately if there's any way it can be done.

As for the quote issue, the problem I'm trying to solve is that my code is driven by configuration files, and users may specify any legal Solr bq values that they choose.  You're right that in some cases, I can simplify the situation by alternating quotes or changing the syntax...  but I don't want to force users into using a subset of legal Solr syntax; it would be much better to able to handle all legal cases in a straightforward fashion.  Admittedly, my example is artificial -- format:Book^50 works just as well as format:"Book"^50...  but suppose they wanted to boost a phrase like format:"Conference Proceeding"^25 -- this is a common case.  It seems like there should be some syntax that allows this to work in the context I am using it.  If not, perhaps we need to file a bug report.

In any case, thanks for taking the time to make some suggestions!  It surprises me that this very powerful feature of Solr is so little-documented.

- Demian

> -----Original Message-----
> From: Jonathan Rochkind [mailto:rochkind@jhu.edu]
> Sent: Tuesday, September 20, 2011 10:32 AM
> To: solr-user@lucene.apache.org
> Cc: Demian Katz
> Subject: Re: Questions about LocalParams syntax
> 
> I don't have the complete answer. But I _think_ if you do one 'bq'
> param
> with multiple space-seperated directives, it will work.
> 
> And escaping is a pain.  But can be made somewhat less of a pain if you
> realize that single quotes can sometimes be used instead of
> double-quotes. What I do:
> 
> _query_:"{!dismax qf='title something else'}"
> 
> So by switching between single and double quotes, you can avoid need to
> escape. Sometimes you still do need to escape when a single or double
> quote is actually in a value (say in a 'q'), and I do use backslash
> there. If you had more levels of nesting though... I have no idea what
> you'd do.
> 
> I'm not even sure why you have the internal quotes here:
> 
> bq=\"format:\\\"Book\\\"^50\"
> 
> 
> Shouldn't that just be bq='format:Book^50', what's the extra double
> quotes around <<Book>>?  If you don't need them, then with switching
> between single and double, this can become somewhat less crazy and
> error
> prone:
> 
> _query_:"{!dismax bq='format:Book^50'}"
> 
> I think. Maybe. If you really do need the double quotes in there, then
> I
> think switching between single and double you can use a single
> backslash
> there.
> 
> 
> On 9/20/2011 9:39 AM, Demian Katz wrote:
> > I'm using the LocalParams syntax combined with the _query_ pseudo-
> field to build an advanced search screen (built on Solr 1.4.1's Dismax
> handler), but I'm running into some syntax questions that don't seem to
> be addressed by the wiki page here:
> >
> > http://wiki.apache.org/solr/LocalParams
> >
> >
> > 1.)    How should I deal with repeating parameters?  If I use
> multiple boost queries, it seems that only the last one listed is
> used...  for example:
> >
> > ((_query_:"{!dismax qf=\"title^500 author^300 allfields\"
> bq=\"format:Book^50\" bq=\"format:Journal^150\"}test"))
> >
> >                  boosts Journals, but not Books.  If I reverse the
> order of the two bq parameters, then Books get boosted instead of
> Journals.  I can work around this by creating one bq with the clauses
> OR'ed together, but I would rather be able to apply multiple bq's like
> I can elsewhere.
> >
> >
> > 2.)    What is the proper way to escape quotes?  Since there are
> multiple nested layers of double quotes, things get ugly and it's easy
> to end up with syntax errors.  I found that this syntax doesn't cause
> an error:
> >
> >
> > ((_query_:"{!dismax qf=\"title^500 author^300 allfields\"
> bq=\"format:\\\"Book\\\"^50\" bq=\"format:\\\"Journal\\\"^150\"}test"))
> >
> >                  ...but it also doesn't work correctly - the boost
> queries are completely ignored in this example.  Perhaps this is more a
> problem related to  _query_ than to LocalParams syntax...  but either
> way, a solution would be great!
> >
> > thanks,
> > Demian
> >

Re: Questions about LocalParams syntax

Posted by Jonathan Rochkind <ro...@jhu.edu>.
I don't have the complete answer. But I _think_ if you do one 'bq' param 
with multiple space-seperated directives, it will work.

And escaping is a pain.  But can be made somewhat less of a pain if you 
realize that single quotes can sometimes be used instead of 
double-quotes. What I do:

_query_:"{!dismax qf='title something else'}"

So by switching between single and double quotes, you can avoid need to 
escape. Sometimes you still do need to escape when a single or double 
quote is actually in a value (say in a 'q'), and I do use backslash 
there. If you had more levels of nesting though... I have no idea what 
you'd do.

I'm not even sure why you have the internal quotes here:

bq=\"format:\\\"Book\\\"^50\"


Shouldn't that just be bq='format:Book^50', what's the extra double 
quotes around <<Book>>?  If you don't need them, then with switching 
between single and double, this can become somewhat less crazy and error 
prone:

_query_:"{!dismax bq='format:Book^50'}"

I think. Maybe. If you really do need the double quotes in there, then I 
think switching between single and double you can use a single backslash 
there.


On 9/20/2011 9:39 AM, Demian Katz wrote:
> I'm using the LocalParams syntax combined with the _query_ pseudo-field to build an advanced search screen (built on Solr 1.4.1's Dismax handler), but I'm running into some syntax questions that don't seem to be addressed by the wiki page here:
>
> http://wiki.apache.org/solr/LocalParams
>
>
> 1.)    How should I deal with repeating parameters?  If I use multiple boost queries, it seems that only the last one listed is used...  for example:
>
> ((_query_:"{!dismax qf=\"title^500 author^300 allfields\" bq=\"format:Book^50\" bq=\"format:Journal^150\"}test"))
>
>                  boosts Journals, but not Books.  If I reverse the order of the two bq parameters, then Books get boosted instead of Journals.  I can work around this by creating one bq with the clauses OR'ed together, but I would rather be able to apply multiple bq's like I can elsewhere.
>
>
> 2.)    What is the proper way to escape quotes?  Since there are multiple nested layers of double quotes, things get ugly and it's easy to end up with syntax errors.  I found that this syntax doesn't cause an error:
>
>
> ((_query_:"{!dismax qf=\"title^500 author^300 allfields\" bq=\"format:\\\"Book\\\"^50\" bq=\"format:\\\"Journal\\\"^150\"}test"))
>
>                  ...but it also doesn't work correctly - the boost queries are completely ignored in this example.  Perhaps this is more a problem related to  _query_ than to LocalParams syntax...  but either way, a solution would be great!
>
> thanks,
> Demian
>