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 Conal Tuohy <ct...@unimelb.edu.au> on 2010/03/25 07:45:46 UTC

How to compose a query from multiple HTTP URL parameters?

I would like to be able to specify a query over multiple fields using 
just an HTML form with different parameters for the different fields.

Is it possible to configure Solr to accept a URL of this form:

select?Species=Pseudonaja+textilis&Hospital=Griffith+Base+Hospital

... instead of:

q=Species:'Pseudonaja+textilis'+Hospital:'Griffith+Base+Hospital'

I have read some information about parameter indirection or parameter 
dereferencing, but I haven't been able to get it to work.



Re: How to compose a query from multiple HTTP URL parameters?

Posted by Abdelhamid ABID <ae...@gmail.com>.
Hi,
You may implement this alternative by using "URL rewrite" mechanism either
by coding your own filter or by pulling back your servlet
engine behind the Apache httpd in order to benefit from mod_rewrite.


On 3/25/10, Conal Tuohy <ct...@unimelb.edu.au> wrote:
>
> I would like to be able to specify a query over multiple fields using just
> an HTML form with different parameters for the different fields.
>
> Is it possible to configure Solr to accept a URL of this form:
>
> select?Species=Pseudonaja+textilis&Hospital=Griffith+Base+Hospital
>
> ... instead of:
>
> q=Species:'Pseudonaja+textilis'+Hospital:'Griffith+Base+Hospital'
>
> I have read some information about parameter indirection or parameter
> dereferencing, but I haven't been able to get it to work.
>
>
>


-- 
Abdelhamid ABID
Software Engineer- J2EE / WEB / ESB MULE

Re: How to compose a query from multiple HTTP URL parameters?

Posted by Conal Tuohy <ct...@unimelb.edu.au>.
Chris Hostetter wrote:
> : select?Species=Pseudonaja+textilis&Hospital=Griffith+Base+Hospital
> : 
> : ... instead of:
> : 
> : q=Species:'Pseudonaja+textilis'+Hospital:'Griffith+Base+Hospital'
>
> Try this, i *think* it will work for you...
>
> q=%2B_query_:"{!field+f=Species+v=$Species}"+%2B_query_="{!field+f=Hospital+v=$Hospital}"+Species=Pseudonaja+textilis&Hospital=Griffith+Base+Hospital
>
> More details...
>
> http://www.lucidimagination.com/blog/2009/03/31/nested-queries-in-solr/
>   

Thanks, that was very helpful! I removed the %2B from your URI, and 
successfully used the following URI (broken into separate lines for 
readability):

   q=
      _query_:%22{!field+f=Species+v=$Species}%22+
      _query_=%22{!field+f=Hospital+v=$Hospital}%22
   &Species=Pseudonaja+textilis
   &Hospital=Griffith+Base+Hospital

Having done that, I removed the q parameter from my URL, URL-decoded it, 
and specified it instead in my solrconfig.xml (in 
/config/requestHandler/lst[@name='defaults']/str[@name='q']), e.g.

    <str name="q">_query_:"{!field f=Species v=$Species}" 
_query_="{!field f=Hospital v=$Hospital}"</str>

That way the query URLs can contain just the "Species" and "Hospital" 
field names as URL parameters.

This is great! Now I can have a simple HTML form as the front end of a 
"fielded search", with different HTML input elements for the different 
Solr fields, but I don't need any custom back end to parse the URL!

Cheers

Con

Re: How to compose a query from multiple HTTP URL parameters?

Posted by Chris Hostetter <ho...@fucit.org>.
: select?Species=Pseudonaja+textilis&Hospital=Griffith+Base+Hospital
: 
: ... instead of:
: 
: q=Species:'Pseudonaja+textilis'+Hospital:'Griffith+Base+Hospital'

Try this, i *think* it will work for you...

q=%2B_query_:"{!field+f=Species+v=$Species}"+%2B_query_="{!field+f=Hospital+v=$Hospital}"+Species=Pseudonaja+textilis&Hospital=Griffith+Base+Hospital

More details...

http://www.lucidimagination.com/blog/2009/03/31/nested-queries-in-solr/



-Hoss