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 Nestor Oviedo <ov...@gmail.com> on 2009/12/15 20:01:18 UTC

facet.field problem in SolrParams to NamedList

Hi!
I wrote a subclass of DisMaxQParserPlugin to add a little filter for
processing the "q" param and generate a "fq" param.
Ej.: "q=something field:value" becomes "q=something value&fq=field:value"

To do this, in the createParser method, I apply a regular expression
to the qstr param to obtain the fq part, and then I do the following:

NamedList<Object> paramsList = params.toNamedList();
paramsList.add(CommonParams.FQ, generatedFilterQuery);
params = SolrParams.toSolrParams(paramsList);
req.setParams(params);

The problem is when I include two "facet.field" in the request. In the
results (facets section) it prints "[Ljava.lang.String;@c77a748",
which is the result of a toString() over an String[] .

So, getting a little in deep in the code, I saw the method
SolrParams.toNameList() was saving the array correctly, but the method
SolrParams.toSolrParams(NamedList) was doing:
"params.getVal(i).toString()". So, it always loses the array.

Something similar occurs with the methods SolrParams.toMap() and
SolrParams.toMultiMap().

Is this a bug ?

thanks.
Nestor

Re: facet.field problem in SolrParams to NamedList

Posted by Nestor Oviedo <ov...@gmail.com>.
Hi Hoss
I changed my code to use the AppendedSolrParams and it worked perfectly.

I'm opening a bug today with my simple test case.

Tank you very much for your help
Regards
Nestor




On Tue, Dec 15, 2009 at 6:39 PM, Chris Hostetter
<ho...@fucit.org> wrote:
>
> : Ej.: "q=something field:value" becomes "q=something value&fq=field:value"
> :
> : To do this, in the createParser method, I apply a regular expression
> : to the qstr param to obtain the fq part, and then I do the following:
> :
> : NamedList<Object> paramsList = params.toNamedList();
> : paramsList.add(CommonParams.FQ, generatedFilterQuery);
> : params = SolrParams.toSolrParams(paramsList);
> : req.setParams(params);
>        ...
> : SolrParams.toNameList() was saving the array correctly, but the method
> : SolrParams.toSolrParams(NamedList) was doing:
> : "params.getVal(i).toString()". So, it always loses the array.
>
> I'm having trouble thinking through exactly where the problem is being
> introduced here ... ultimately what it comes down to is that the NamedList
> souldn't be containing a String[] ... it should be containing multiple
> string values with the same name ("fq")
>
> It would be good to make sure all of these methods play nicely with one
> another so some round trip conversions worked as expected -- so if you
> could open a bug for this with a simple example test case that would be
> great, ...but...
>
> for your purposes, i would skip the NamedList conversion alltogether,
> and just use AppendedSolrParams...
>
>  MapSolrParams myNewParams = new MapSolrParams();
>  myNewParams.getMap().put("fq", generatedFileterQuery);
>  myNewParams.getMap().put("q", generatedQueryString);
>  req.setParams(new AppendedSolrParams(myNewParams, originalPrams));
>
> -Hoss
>
>

Re: facet.field problem in SolrParams to NamedList

Posted by Chris Hostetter <ho...@fucit.org>.
: Ej.: "q=something field:value" becomes "q=something value&fq=field:value"
: 
: To do this, in the createParser method, I apply a regular expression
: to the qstr param to obtain the fq part, and then I do the following:
: 
: NamedList<Object> paramsList = params.toNamedList();
: paramsList.add(CommonParams.FQ, generatedFilterQuery);
: params = SolrParams.toSolrParams(paramsList);
: req.setParams(params);
	...
: SolrParams.toNameList() was saving the array correctly, but the method
: SolrParams.toSolrParams(NamedList) was doing:
: "params.getVal(i).toString()". So, it always loses the array.

I'm having trouble thinking through exactly where the problem is being 
introduced here ... ultimately what it comes down to is that the NamedList 
souldn't be containing a String[] ... it should be containing multiple 
string values with the same name ("fq")

It would be good to make sure all of these methods play nicely with one 
another so some round trip conversions worked as expected -- so if you 
could open a bug for this with a simple example test case that would be 
great, ...but...

for your purposes, i would skip the NamedList conversion alltogether, 
and just use AppendedSolrParams...

  MapSolrParams myNewParams = new MapSolrParams();
  myNewParams.getMap().put("fq", generatedFileterQuery);
  myNewParams.getMap().put("q", generatedQueryString);
  req.setParams(new AppendedSolrParams(myNewParams, originalPrams));

-Hoss