Multiple facets

73 views
Skip to first unread message

MungoDungo

unread,
Nov 18, 2011, 6:46:14 AM11/18/11
to PHP Solr Client
Hi Guys.

Following an example from the FAQ I have realised that one cannot do
multiple facet ranges using this lib .

For example how is one supposed to achieve...

http://localhost:8080/solr/select?q=*:*
&facet=on&facet.field=salary
&facet.query=salary:[* TO 100]
&facet.query=salary:[100 TO 200];&facet.query=[salary:200 TO 300]
&facet.query=salary:[300 TO 400];&facet.query=[salary:400 TO 500]
&facet.query=salary:[500 TO *]
using the library ?

Donovan Jimenez

unread,
Nov 18, 2011, 2:27:10 PM11/18/11
to php-sol...@googlegroups.com
You use arrays for sending the same parameter multiple times. order is maintained so that you can do associations between multiple multivalue parameters like you may need with multiple facet queries that you want to behave slightly differently. It's demonstrated in the example usage (facet.field is an array):

http://code.google.com/p/solr-php-client/wiki/FAQ#How_Can_I_Use_Additional_Parameters_(like_fq,_facet,_etc)

Let me know if you have any problems with this.

Good Luck,
Donovan
> --
> You received this message because you are subscribed to the Google Groups "PHP Solr Client" group.
> To post to this group, send email to php-sol...@googlegroups.com.
> To unsubscribe from this group, send email to php-solr-clie...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/php-solr-client?hl=en.
>
>

Tarrant Marshall

unread,
Nov 1, 2012, 7:53:44 PM11/1/12
to php-sol...@googlegroups.com
I think this is still an issue a year on. It may not be for facet.field, but any facet.range.* must come immediately after the facet.field it is related to

Donovan Jimenez

unread,
Nov 2, 2012, 12:12:28 PM11/2/12
to php-sol...@googlegroups.com
The same advice still applies, a year on. order only matters for fields of the same name. the association between one parameter name and another is by index (which is why order for parameters of the same name do matter).

I'll construct an  example around a salary field, since that's the thread you've taken up (0 - 1000 with gap of 100).

    /select?q=*:*&facet=true&facet.range=salary&facet.range.start=0&facet.range.end=1000&facet.range.gap=100

Simple, right... now, i'm going to jumble up the order of parameters, would you expect this not to work?

    /select?q=*:*&facet.range.end=1000&facet.range.gap=100&facet.range=salary_id&facet.range.start=0&facet=true

It does work, because order for differently named parameters DOESN'T MATTER.

Now, lets pose a case where some ordering does matter, specifically, if we have more than one facet range going on, for this, i'll suppose the same field (though doesn' tmatter if its not) but with different range parameters (100 - 500 with a gap of 10):

    /select?q=*:*&facet=true&facet.range=salary&facet.range.start=0&facet.range.end=1000&facet.range.gap=100&facet.range=salary&facet.range.start=100&facet.range.end=500&facet.range.gap=10

Now, to illustrate my point about where ordering matters, lets group each similarly named parameter together:

    /select?q=*:*&facet=true&facet.range=salary&facet.range=salary&facet.range.start=0&facet.range.start=100&facet.range.end=1000&facet.range.end=500&facet.range.gap=100&facet.range.gap=10

Notice, that each paramater name (e.g. facet.range.start) still appears in the same order relative to others of the same name, but its relation to the rest of the parameters doesn't matter.

This is the same thing you are doing when specifying your parameters for the PHP client. Our first would have looked like:

$params = array(
    "facet" => "true",
    "facet.range" => "salary",
    "facet.range.start" => "0",
    "facet.range.end" => "1000",
    "facet.range.gap" => "100"
);

now with 2 ranges:

$params = array(
    "facet" => "true",
    "facet.range" => array(
        "salary",  // first ranges field
        "salary"   // second ranges field
    ),
    "facet.range.start" => array(
        "0",    // first range's start
        "100"  // second range's start
    ),
    "facet.range.end" => array(
        "1000", // first range's end
        "500" // second range's end
    )
    "facet.range.gap" => array(
         "100", // first range's gap
         "10" // second range's gap
    )
);

Hope this illustrates the point

Donovan

To view this discussion on the web visit https://groups.google.com/d/msg/php-solr-client/-/UEi3Y5lUBKgJ.
Reply all
Reply to author
Forward
0 new messages