lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Andrea Gazzarini <a.gazzar...@sease.io>
Subject Re: searching only within a date range
Date Fri, 07 Jun 2019 13:50:37 GMT
Hi Mark, you are using a "range facet" which is a "query-shape" feature, 
it doesn't have any constraint on the results (i.e. it doesn't filter at 
all).
You need to add a filter query [1] with a date range clause (e.g. 
fq=field:[<some date or DateMath exp or *> TO <some date or DateMath exp 
or *>]).

Best,
Andrea

[1] 
https://lucene.apache.org/solr/guide/6_6/common-query-parameters.html#CommonQueryParameters-Thefq_FilterQuery_Parameter
[2] https://lucene.apache.org/solr/guide/6_6/working-with-dates.html

On 07/06/2019 14:02, Mark Fenbers - NOAA Federal wrote:
> Hello!
>
> I have a search setup and it works fine.  I search a text field called
> "logtext" in a database table.  My Java code is like this:
>
> SolrQuery query - new SolrQuery();
> query.setQuery(searchWord);
> query.setParam("df", "logtext");
>
> Then I execute the search... and it works just great.  But now I want to
> add a constraint to only search for the "searchWord" within a certain range
> of time -- given timestamps in the column called "posttime".  So, I added
> the code in bold below:
>
> SolrQuery query - new SolrQuery();
> query.setQuery(searchWord);
> *query.setFacet(true);*
> *query.addDateRangeFacet("posttime", new Date(System.currentTimeMillis() -
> 1000L * 86400L * 365L), new Date(System.currentTimeMillis()), "+1DAY"); /*
> from 1 year ago to present) */*
> query.setParam("df", "logtext");
>
> But this gives me a complaint: *undefined field: "posttime"* so I clearly
> do not understand the arguments needed to addDateRangeFacet().  Can someone
> help me determine the proper code for doing what I want?
>
> Further, I am puzzled about the "gap" argument [last one in
> addDateRangeFacet()].  What does this do?  I used +1DAY, but I really have
> no idea the purpose of this.  I haven't found any documentation that
> explains this well.
>
> Mark
>


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message