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 Mugeesh Husain <mu...@gmail.com> on 2015/11/17 15:07:39 UTC

Date Math, NOW and filter queries

hi!,

http://lucidworks.com/blog/2012/02/23/date-math-now-and-filter-queries/

for date range query i am following above article,in this article

I try to querying fq=date:[NOW/DAY-7DAYS TO NOW/DAY], it is working fine,

when i fire query fq=date:[NOW/DAY-7DAYS TO NOW/DAY+1DAY], it is giving
below error 

"fq":"initial_release_date:[NOW/DAY-7DAYS TO NOW/DAY 1DAY]",
      "rows":"32"}},
  "error":{
    "msg":"org.apache.solr.search.SyntaxError: Cannot parse
'initial_release_date:[NOW/DAY-7DAYS TO NOW/DAY 1DAY]': Encountered \"
<RANGE_GOOP> \"1DAY \"\" at line 1, column 47.\nWas expecting one of:\n   
\"]\" ...\n    \"}\" ...\n    ",
    "code":400}}


why it is giving error 

Thanks
mugeesh

 
 




--
View this message in context: http://lucene.472066.n3.nabble.com/Date-Math-NOW-and-filter-queries-tp4240561.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Date Math, NOW and filter queries

Posted by Shawn Heisey <ap...@elyograg.org>.
On 11/17/2015 7:07 AM, Mugeesh Husain wrote:
> when i fire query fq=date:[NOW/DAY-7DAYS TO NOW/DAY+1DAY], it is giving
> below error 
>
> "fq":"initial_release_date:[NOW/DAY-7DAYS TO NOW/DAY 1DAY]",
>       "rows":"32"}},
>   "error":{
>     "msg":"org.apache.solr.search.SyntaxError: Cannot parse
> 'initial_release_date:[NOW/DAY-7DAYS TO NOW/DAY 1DAY]': Encountered \"
> <RANGE_GOOP> \"1DAY \"\" at line 1, column 47.\nWas expecting one of:\n   
> \"]\" ...\n    \"}\" ...\n    ",
>     "code":400}}

How are you sending the queries to Solr?  I'm betting that you are
constructing a URL manually in your own code and sending it to Solr
directly via HTTP, rather than using a Solr library like SolrJ,
Solarium, Sunspot, etc.

https://wiki.apache.org/solr/IntegratingSolr

What's happening here is that the query is not URL escaped, which means
the URL contains an actual plus sign for the "NOW/DAY+1DAY" part of your
query.  A plus sign in a URL is interpreted by the webserver as a space,
in accordance with the standards that govern HTTP.  This is not a bug.

A Solr library would have taken care of all the URL escaping for
characters that require it, and the user code is typically a lot easier
to write than URL construction code.

Whatever programming language you are using to construct your queries
very likely has a function for doing URL escaping on the parameters for
your URL.  You would want to be careful to only run it on the values in
your parameters, not the entire URL, or it would escape everything and
the URL would not work.

The URL escaped version of a plus sign is %2B if you want to quickly fix
this before you look into URL escaping functions or a Solr library.

Thanks,
Shawn


Re: Date Math, NOW and filter queries

Posted by Chris Hostetter <ho...@fucit.org>.
: the '+' sign is a URL-escape for space, which you
: see in the error message.

more specifically, the error indicates that something/somewhere/somehow 
when you are construction your request to Solr, your HTTP request params 
are not getting properly escaped -- so the '+' is being sent literlay over 
the wire, and Solr is URL un-escaping it as whitespace.

: Escape it as %2B and you should be fine.

Rather then you manually "escaping" just the "+" character in your code, 
you should instead figure out where/how to ensure that *all* the HTTP 
communication you have with Solr gets properly escaped -- so you don't 
have this problem over and over with other params/characters.

if you can tell us a bit more about how you communicate with Solr, we can 
try to help you with the larger problem you are having.  (any decent HTTP 
client library should  automatically escape any request param keys/values 
you ask it to include in the request)

-Hoss
http://www.lucidworks.com/

Re: Date Math, NOW and filter queries

Posted by Mugeesh Husain <mu...@gmail.com>.
thanks all of you,
actually the problem was '+' sign is a URL-escape for space,

Using %2B instead of + sign, should be fine



--
View this message in context: http://lucene.472066.n3.nabble.com/Date-Math-NOW-and-filter-queries-tp4240561p4240675.html
Sent from the Solr - User mailing list archive at Nabble.com.

Re: Date Math, NOW and filter queries

Posted by Erick Erickson <er...@gmail.com>.
Congratulations, you are in "Url escaping hell" ;)

the '+' sign is a URL-escape for space, which you
see in the error message.

Escape it as %2B and you should be fine.

Best,
Erick

On Tue, Nov 17, 2015 at 6:07 AM, Mugeesh Husain <mu...@gmail.com> wrote:
> hi!,
>
> http://lucidworks.com/blog/2012/02/23/date-math-now-and-filter-queries/
>
> for date range query i am following above article,in this article
>
> I try to querying fq=date:[NOW/DAY-7DAYS TO NOW/DAY], it is working fine,
>
> when i fire query fq=date:[NOW/DAY-7DAYS TO NOW/DAY+1DAY], it is giving
> below error
>
> "fq":"initial_release_date:[NOW/DAY-7DAYS TO NOW/DAY 1DAY]",
>       "rows":"32"}},
>   "error":{
>     "msg":"org.apache.solr.search.SyntaxError: Cannot parse
> 'initial_release_date:[NOW/DAY-7DAYS TO NOW/DAY 1DAY]': Encountered \"
> <RANGE_GOOP> \"1DAY \"\" at line 1, column 47.\nWas expecting one of:\n
> \"]\" ...\n    \"}\" ...\n    ",
>     "code":400}}
>
>
> why it is giving error
>
> Thanks
> mugeesh
>
>
>
>
>
>
>
> --
> View this message in context: http://lucene.472066.n3.nabble.com/Date-Math-NOW-and-filter-queries-tp4240561.html
> Sent from the Solr - User mailing list archive at Nabble.com.