Solrnet Facet Price Range Query

688 views
Skip to first unread message

Siva

unread,
Sep 7, 2011, 8:50:25 AM9/7/11
to SolrNet
Hi Mauricio,
I got facet for Product Prices, which i am using jquery slider to
filter products.
In the slider i got two prices, Price_from and Price_to, i want apply
facet filter for price range.

For example:
I got my search results http://localhost:1767/products/searchresults?q=mug
it returned 500 Products,
from this result i want filter products which Price From £1 to £2
(which is around 150 products)

when I query like http://localhost:1767/products/searchresults?q=mug&f_tradeprice=2
( i am only getting the price matched records).

In my solr schema i got below field defined.
<field name="tradeprice" type="float" indexed="true" stored="true"/>

in my result xml i got something like below
<float name="tradeprice">1.0</float>
<float name="tradeprice">2.0</float>
<float name="tradeprice">0.5</float>
<float name="tradeprice">0.01</float>
<float name="tradeprice">0.25</float>
<float name="tradeprice">5.0</float>

Can you please help how to apply facet filter range.

Thanks
Regards
Siva

Mauricio Scheffer

unread,
Sep 7, 2011, 9:18:34 AM9/7/11
to sol...@googlegroups.com
To apply a range filter 1-2 from a facet, add a new SolrQueryByRange<int>("tradeprice", 1, 2) to FilterQueries in QueryOptions.

--
Mauricio




--
You received this message because you are subscribed to the Google Groups "SolrNet" group.
To post to this group, send email to sol...@googlegroups.com.
To unsubscribe from this group, send email to solrnet+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/solrnet?hl=en.


Siva

unread,
Sep 7, 2011, 9:23:30 AM9/7/11
to SolrNet
Hi Mauricio,
Thanks for your quick reply..
How we can pass the from & to value through the URL
i.e http://localhost:1767/products/searchresults?q=pen&fq=tradeprice:[10+TO+20]

Thanks
Siva

On Sep 7, 2:18 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:
> To apply a range filter 1-2 from a facet, add a new
> SolrQueryByRange<int>("tradeprice", 1, 2) to FilterQueries in QueryOptions.
>
> --
> Mauricio
>
>
>
>
>
>
>
> On Wed, Sep 7, 2011 at 9:50 AM, Siva <sivaak...@googlemail.com> wrote:
> > Hi Mauricio,
> > I got facet for Product Prices, which i am using jquery slider to
> > filter products.
> > In the slider i got two prices, Price_from and Price_to, i want apply
> > facet filter for price range.
>
> > For example:
> > I got my search resultshttp://localhost:1767/products/searchresults?q=mug

Mauricio Scheffer

unread,
Sep 7, 2011, 10:12:04 AM9/7/11
to sol...@googlegroups.com
Hi Siva,

You can pass it any way you want...as "tradeprice_1-2" or "tradeprice-1-TO-2" or anything you need.
Serializing / deserializing this from the URL is a problem of your application, out of the scope of SolrNet.

Cheers,
Mauricio

Siva

unread,
Sep 9, 2011, 12:23:45 PM9/9/11
to SolrNet
Hi Mauricio,

I am almost there, struggling to combine the Solr Query field and
Solr Range field.

here is what i got, I am setting value for search parameters pricefrom
and priceto values on controller and trying to build the filter query
as below

public ICollection<ISolrQuery> BuildFilterQueries(SearchParameters
parameters)
{

var queriesFromFacets = from p in parameters.Facets
select (ISolrQuery)Query.Field(p.Key).Is(p.Value);

if (parameters.pricefrom > 0 && parameters.priceto > 0)
{
var myqry = new SolrQueryByRange<decimal>("tradeprice",
parameters.pricefrom, parameters.priceto);

//BEFORE RETURN THE FILTER QUERY I
WANT TO COMBINE THE "queriesFromFacets" with "myqry(RANGE QUERY) " , I
HAVE TRIED CASTING ETC..NOTHING WORKING..CAN YOU HELP
return queriesFromFacets.ToList();
}
else {
return queriesFromFacets.ToList();
}

}

THANKS
Regards
Siva

On Sep 7, 3:12 pm, Mauricio Scheffer <mauricioschef...@gmail.com>
wrote:

Mauricio Scheffer

unread,
Sep 9, 2011, 2:03:59 PM9/9/11
to sol...@googlegroups.com
Hi Siva,

Use AbstractSolrQuery instead of ISolrQuery so you can apply operators: http://code.google.com/p/solrnet/wiki/Querying#Query_operators
Or use SolrMultipleCriteriaQuery, I just added a few examples of that in the documentation.

--
Mauricio
Reply all
Reply to author
Forward
0 new messages