LocalParams for multi-select faceting

1,065 views
Skip to first unread message

J

unread,
Mar 9, 2010, 10:06:00 AM3/9/10
to SolrNet
Does anyone have any experience with this? Is there an available
example, using SolrNet?

Thanks!
- J

Mauricio Scheffer

unread,
Mar 9, 2010, 10:30:23 AM3/9/10
to SolrNet
I haven't tried, but something like this should work:

From http://wiki.apache.org/solr/SimpleFacetParameters#LocalParams_for_faceting
:

q=mainquery&fq=status:public&fq={!tag=dt}
doctype:pdf&facet=on&facet.field={!ex=dt}doctype

could be translated to SolrNet as:

solr.Query("mainquery", new QueryOptions {
FilterQueries = new ISolrQuery[] {
Query.Field("status").Is("public"),
new LocalParams {{"tag", "dt"}} + Query.Field("doctype").Is("pdf")
},
Facet = new FacetParameters {
Queries = new ISolrFacetQuery[] {
new SolrFacetFieldQuery(new LocalParams {{"ex", "dt"}} +
"doctype")
}
}
});

Let me know if it doesn't work.

Cheers,
Mauricio

Mauricio Scheffer

unread,
Mar 12, 2010, 12:20:00 AM3/12/10
to SolrNet
This got me thinking into some alternatives:
http://bugsquash.blogspot.com/2010/03/low-level-solrnet.html

On Mar 9, 12:30 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:


> I haven't tried, but something like this should work:
>

> Fromhttp://wiki.apache.org/solr/SimpleFacetParameters#LocalParams_for_fac...

Mauricio Scheffer

unread,
Sep 30, 2010, 9:08:30 AM9/30/10
to sol...@googlegroups.com
Solr itself uses OR, not ||, as the or operator. You can use || in C# with SolrNet queries, for example:

new LocalParams {{"tag", "dt"}} + (Query.Field("doctype").Is("pdf") || Query.Field("doctype").Is("html"))

--
Mauricio

On Thu, Sep 30, 2010 at 8:07 AM, ceesjm <sj_...@yahoo.com> wrote:
Hey Mauricio,

I posted a comment on your bugsquash blog regarding multi-select
faceting (copied below for reference) and you kindly replied that it
should be possible.

<quote>
Enjoyed the article but can you tell me if it is possible to represent
the following multi-facet query string (2 facet values selected from
the doctype facet field) using the SolrNet LocalParams class or does
it require the "internal" component approach?

q=mainquery&fq=status:public&fq={!tag=dt}doctype:(pdf OR
txt)&facet=on&facet.field={!ex=dt}doctype
</quote>

I have been playing around with the local params approach and reckon I
am doing something wrong. Any ideas based on the test code below?

           // Build the query options based on the search parameters
input
           QueryOptions options = new QueryOptions
           {
               FilterQueries =
BuildMultiFacetFilterQueries(parameters),
               Rows = parameters.PageSize,
               Start = start,
               ...


       private static ICollection<ISolrQuery>
BuildMultiFacetFilterQueries(SearchParameters parameters)
       {
           ICollection<ISolrQuery> filters = new List<ISolrQuery>();

           foreach (KeyValuePair<string, IList<string>> facet in
parameters.Facets)
           {
               string exclusionFilter = facet.Value.Count > 1 ?
                   "(" + string.Join(" || ", facet.Value.ToArray()) +
")" :
                   facet.Value.FirstOrDefault();

               filters.Add(
                   new LocalParams { { "tag", facet.Key } } +
                   Query.Field(facet.Key).Is(exclusionFilter));
           }

           return filters;
       }

When multiple facets are selected I get zero results due to the
following resultant query string:

http://localhost:8983/solr/select?f.date.facet.date.other=all&f.date.facet.date.gap=%2b1MONTH&f.date.facet.date.end=2010-09-30T11%3a48%3a18Z&f.date.facet.date.start=2010-01-01T00%3a00%3a00Z&facet.date=date&facet.field=author_exact&facet.field=%7b!ex%3ddoc_type_exact%7ddoc_type_exact&facet=true&spellcheck=true&fq=%7b!tag%3ddoc_type_exact%7ddoc_type_exact%3a%22%5c(text%2fhtml+%5c%7c%7c+application%2fpdf%5c)%22&hl.snippets=2&hl.fl=doc_title%2csummary&hl=true&rows=5&start=0&q=&?

fq decoded:  <str name="fq">{!tag=doc_type_exact}doc_type_exact:"\
(text/html \|| application/pdf\)"</str>

The problem appears to be the escaping of parenthesis and logical OR
and the quotes surrounding the fq value.  If I manually hack the Solr
query string parameters as follows:

http://d8h5p84j:8983/solr/select?f.date.facet.date.other=all&f.date.facet.date.gap=%2b1MONTH&f.date.facet.date.end=2010-09-30T12%3a03%3a58Z&f.date.facet.date.start=2010-01-01T00%3a00%3a00Z&facet.date=date&facet.field=author_exact&facet.field=%7b!ex%3ddoc_type_exact%7ddoc_type_exact&facet=true&spellcheck=true&fq=%7b!tag%3ddoc_type_exact%7ddoc_type_exact%3a(text%2fhtml+%7c%7c+application%2fpdf)&hl.snippets=2&hl.fl=doc_title%2csummary&hl=true&rows=5&start=0&q=&?

<str name="fq">{!tag=doc_type_exact}doc_type_exact:(text/html ||
application/pdf)</str>

this produces the desired result set.

Any help appreciated :)

On Mar 12, 6:20 am, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> This got me thinking into some alternatives:http://bugsquash.blogspot.com/2010/03/low-level-solrnet.html
>
> On Mar 9, 12:30 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
> wrote:
>
>
>
> > I haven't tried, but something like this should work:
>
> > Fromhttp://wiki.apache.org/solr/SimpleFacetParameters#LocalParams_for_fac...
> > :
>
> > q=mainquery&fq=status:public&fq={!tag=dt}
> > doctype:pdf&facet=on&facet.field={!ex=dt}doctype
>
> > could be translated to SolrNet as:
>
> > solr.Query("mainquery", new QueryOptions {
> >   FilterQueries = new ISolrQuery[] {
> >     Query.Field("status").Is("public"),
> >     new LocalParams {{"tag", "dt"}} + Query.Field("doctype").Is("pdf")
> >   },
> >  Facet= new FacetParameters {

> >     Queries = new ISolrFacetQuery[] {
> >       new SolrFacetFieldQuery(new LocalParams {{"ex", "dt"}} +
> > "doctype")
> >     }
> >   }
>
> > });
>
> > Let me know if it doesn't work.
>
> > Cheers,
> > Mauricio
>
> > On Mar 9, 12:06 pm, J <jesse...@gmail.com> wrote:
>
> > > Does anyone have any experience with this? Is there an available
> > > example, using SolrNet?
>
> > > Thanks!
> > > - J- Hide quoted text -
>
> - Show quoted text -

Reply all
Reply to author
Forward
0 new messages