This project is read-only.

QueryBuilder's AddSearchParameter method is strange

Jan 27, 2009 at 9:05 PM
It's near the end of the day here, so this may be my caffeine-addled brain overlooking something obvious, but the QueryBuilder's AddSearchParameter() function looks like this:

public void AddSearchParameter(string parameter, string value, bool overwrite)
{
if (overwrite)
this._searchkeyvalues.Remove(parameter);
this._searchkeyvalues[parameter] = value;
}
Doesn't this end up overwriting the value no matter what you pass in for the overwrite parameter?

The reason I ask is it would be nice if I could make successive calls to append to an existing search parameter, such as the "fq" parameter.

Something like

foo.AddSearchParameter("fq", "-productActiveStatus:Active");
foo.AddSearchParameter("fq", "sizeInStock:M");

which would end up spitting out something like "&fq=-productActiveStatus:Active sizeInStock:M" to Solr.

Apologies if I'm missing something obvious.
Jan 27, 2009 at 9:31 PM
Well I just found the QueryParameters part of the Query class, which is more like what I want.

That method above still looks strange to me, though.
Coordinator
Jan 28, 2009 at 5:17 PM
I can see why that would be strange.  There is some safety in this method in that it prevents duplication of query values, to the effect of:

foo.AddSearchParameter("fq", "-productActiveStatus:Active");
foo.AddSearchParameter("fq", "sizeInStock:M");
foo.AddSearchParameter("fq", "-productActiveStatus:Active");

to avoid producing a query value such as ""&fq=-productActiveStatus:Active -productActiveStatus:Active sizeInStock:M"

There was also some sense around this approach when the library was originally designed (Solr 1.1), but the reasoning escapes me.  (note to self: deeper code comments...)

However, the search values could be much more logical in terms of collecting values.  The primary function in this scenario is handling appended values vs. overwritten values.

Thanks for the comments.