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 "Allison, Timothy B." <ta...@mitre.org> on 2016/06/03 13:23:08 UTC

find stores with sales of > $x in last 2 months ?

All,
  This is a toy example, but is there a way to search for, say, stores with sales of > $x in the last 2 months with Solr?
  $x and the time frame are selected by the user at query time.  

If the queries could be constrained (this is still tbd), I could see updating "stats" fields within each store document on a daily basis (sales_last_1_month, sales_last_2_months, sales_last_3_months...etc).  The dataset is fairly small and daily updates of this nature would not be prohibitive.

   Or, is this trying to use a screw driver where a hammer is required?
 
       Thank you.

               Best,

                     Tim

Re: find stores with sales of > $x in last 2 months ?

Posted by Erick Erickson <er...@gmail.com>.
Have you looked at the stats component here?
https://cwiki.apache.org/confluence/display/solr/The+Stats+Component

As for the rolling time period, date math is your friend:
https://cwiki.apache.org/confluence/display/solr/Working+with+Dates

If working with date math in fq clauses, beware of using a bare NOW,
see:
http://searchhub.org/2012/02/23/date-math-now-and-filter-queries/

Best,
Erick

On Mon, Jun 6, 2016 at 5:45 AM, Allison, Timothy B. <ta...@mitre.org> wrote:
> Thank you, Alex.
>
>> Sorry, your question a bit confusing.
> Y. Sorry.
>
>> Also, is this last month as in 'January' (rolling monthly) or as in 'last 30 days'
> (rolling daily).
>
> Ideally, the latter, if this is possible to calculate dynamically in response to a query.  My backoff method (if the 'rolling daily' method isn't possible), would be to index monthly stats and then just use the range query as you suggested.
>
> -----Original Message-----
> From: Alexandre Rafalovitch [mailto:arafalov@gmail.com]
> Sent: Sunday, June 5, 2016 12:52 AM
> To: solr-user <so...@lucene.apache.org>
> Subject: Re: find stores with sales of > $x in last 2 months ?
>
> Are you asking for just numerical comparison during search or about a way to aggregate numbers from multiple records? Also, is this last month as in 'January' (rolling monthly) or as in 'last 30 days'
> (rolling daily). Sorry, your question a bit confusing.
>
> Numerical comparison is just a range (numField:[x TO *])  as per
>
> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-RangeSearches
>
> https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser
>
> Regards,
>    Alex.
> ----
> Newsletter and resources for Solr beginners and intermediates:
> http://www.solr-start.com/
>
>
> On 3 June 2016 at 23:23, Allison, Timothy B. <ta...@mitre.org> wrote:
>> All,
>>   This is a toy example, but is there a way to search for, say, stores with sales of > $x in the last 2 months with Solr?
>>   $x and the time frame are selected by the user at query time.
>>
>> If the queries could be constrained (this is still tbd), I could see updating "stats" fields within each store document on a daily basis (sales_last_1_month, sales_last_2_months, sales_last_3_months...etc).  The dataset is fairly small and daily updates of this nature would not be prohibitive.
>>
>>    Or, is this trying to use a screw driver where a hammer is required?
>>
>>        Thank you.
>>
>>                Best,
>>
>>                      Tim

RE: find stores with sales of > $x in last 2 months ?

Posted by "Allison, Timothy B." <ta...@mitre.org>.
Thank you, Alex.

> Sorry, your question a bit confusing.
Y. Sorry.

> Also, is this last month as in 'January' (rolling monthly) or as in 'last 30 days'
(rolling daily).

Ideally, the latter, if this is possible to calculate dynamically in response to a query.  My backoff method (if the 'rolling daily' method isn't possible), would be to index monthly stats and then just use the range query as you suggested.

-----Original Message-----
From: Alexandre Rafalovitch [mailto:arafalov@gmail.com] 
Sent: Sunday, June 5, 2016 12:52 AM
To: solr-user <so...@lucene.apache.org>
Subject: Re: find stores with sales of > $x in last 2 months ?

Are you asking for just numerical comparison during search or about a way to aggregate numbers from multiple records? Also, is this last month as in 'January' (rolling monthly) or as in 'last 30 days'
(rolling daily). Sorry, your question a bit confusing.

Numerical comparison is just a range (numField:[x TO *])  as per

https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-RangeSearches

https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser

Regards,
   Alex.
----
Newsletter and resources for Solr beginners and intermediates:
http://www.solr-start.com/


On 3 June 2016 at 23:23, Allison, Timothy B. <ta...@mitre.org> wrote:
> All,
>   This is a toy example, but is there a way to search for, say, stores with sales of > $x in the last 2 months with Solr?
>   $x and the time frame are selected by the user at query time.
>
> If the queries could be constrained (this is still tbd), I could see updating "stats" fields within each store document on a daily basis (sales_last_1_month, sales_last_2_months, sales_last_3_months...etc).  The dataset is fairly small and daily updates of this nature would not be prohibitive.
>
>    Or, is this trying to use a screw driver where a hammer is required?
>
>        Thank you.
>
>                Best,
>
>                      Tim

Re: find stores with sales of > $x in last 2 months ?

Posted by Alexandre Rafalovitch <ar...@gmail.com>.
Are you asking for just numerical comparison during search or about a
way to aggregate numbers from multiple records? Also, is this last
month as in 'January' (rolling monthly) or as in 'last 30 days'
(rolling daily). Sorry, your question a bit confusing.

Numerical comparison is just a range (numField:[x TO *])  as per

https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-RangeSearches

https://cwiki.apache.org/confluence/display/solr/The+Standard+Query+Parser#TheStandardQueryParser-DifferencesbetweenLuceneQueryParserandtheSolrStandardQueryParser

Regards,
   Alex.
----
Newsletter and resources for Solr beginners and intermediates:
http://www.solr-start.com/


On 3 June 2016 at 23:23, Allison, Timothy B. <ta...@mitre.org> wrote:
> All,
>   This is a toy example, but is there a way to search for, say, stores with sales of > $x in the last 2 months with Solr?
>   $x and the time frame are selected by the user at query time.
>
> If the queries could be constrained (this is still tbd), I could see updating "stats" fields within each store document on a daily basis (sales_last_1_month, sales_last_2_months, sales_last_3_months...etc).  The dataset is fairly small and daily updates of this nature would not be prohibitive.
>
>    Or, is this trying to use a screw driver where a hammer is required?
>
>        Thank you.
>
>                Best,
>
>                      Tim