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 jx...@yahoo.com on 2010/01/27 19:28:07 UTC

filter query error

NewBie Using Solr1.4

I am trying to use a filter query that filters on more than one value for a given filter  ie. filters on field equals value1 or value2

If I enter the following 2 urls in a browser I get back the correct results I am looking for:

http://localhost:8080/apache-solr-1.4.0/select/?q=help&fl=*,score&fq=+searchScope:SRM+searchScope:SMN&indent=on
or
http://localHost:8080/apache-solr-1.4.0/select/?q=help&fl=*,searchScope,score&fq=searchScope:(SRM+OR+SMN)&indent=on

But when I try to do it programitically I get an error.  It only works when I am filtering on 1 value, but when I try more than one value it fails.
See code snippet  and error message below.  When I use filter2 or filter3 it fails, but filter1 gives me no Errors

Not sure what I am doing wrong.  Any help would be greatly appreciated.

-----Begin Code snippet ---
String query = "help";

//String filter1 = "searchScope:SRM
//String filter2 = "+searchScope:SRM+searchScope:SMN";
String filter3 = "searchScope:(SRM+OR+SMN)";

SolrQuery solrQuery = new SolrQuery(query);
solrQuery.addFilterQuery(filter3);
QueryResponse response = solr.query(solrQuery);
-----End Code snippet ---

I have tried using 
    SolrQuery solrQuery = new SolrQuery(ClientUtils.escapeQueryChars(query));
    solrQuery.addFilterQuery(ClientUtils.escapeQueryChars(filter));

But that returns no results


Also note that if I cut and paste the url from the error message below, it fails when I paste it in a browser,
but I can get it to work only if I remove the wt=javabin parameter.

Error Message

Exception in thread "main" org.apache.solr.client.solrj.SolrServerException: Error executing query
    at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:95)
    at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:118)
    at com.xyz.search.SolrSearch.performSearch(SolrSearch.java:126)
    at com.xyz.search.SearchMain.main(SearchMain.java:23)
Caused by: org.apache.solr.common.SolrException: org.apache.lucene.queryParser.ParseException: Cannot parse ' searchScope:SRM searchScope:SMN': Encountered " ":" ": "" at line 1, column 28.  Was expecting one of:      <EOF>       <AND> ...      <OR> ...      <NOT> ...      " " ...      "-" ...      "(" ...      "*" ...      "^" ...      <QUOTED> ...      <TERM> ...      <FUZZY_SLOP> ...      <PREFIXTERM> ...      <WILDTERM> ...      "[" ...      "{" ...      <NUMBER> ...

org.apache.lucene.queryParser.ParseException: Cannot parse ' searchScope:SRM searchScope:SMN': Encountered " ":" ": "" at line 1, column 28.  Was expecting one of:      <EOF>       <AND> ...      <OR> ...      <NOT> ...      " " ...      "-" ...      "(" ...      "*" ...      "^" ...      <QUOTED> ...      <TERM> ...      <FUZZY_SLOP> ...      <PREFIXTERM> ...      <WILDTERM> ...      "[" ...      "{" ...      <NUMBER> ...

request: http://localhost:8080/apache-solr-1.4.0/select?q=help&fq=+searchScope:SRM+searchScope:SMN&hl=true&rows=15&wt=javabin&version=1
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:424)
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:243)
    at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:89)
    ... 3 more

Re: filter query error

Posted by jx...@yahoo.com.

thanks! that worked.



________________________________
From: Ahmet Arslan <io...@yahoo.com>
To: solr-user@lucene.apache.org
Sent: Wed, January 27, 2010 2:00:32 PM
Subject: Re: filter query error

> I am trying to use a filter query that filters on more than
> one value for a given filter  ie. filters on field
> equals value1 or value2
> 
> If I enter the following 2 urls in a browser I get back the
> correct results I am looking for:
> 
> http://localhost:8080/apache-solr-1.4.0/select/?q=help&fl=*,score&fq=+searchScope:SRM+searchScope:SMN&indent=on
> or
> http://localHost:8080/apache-solr-1.4.0/select/?q=help&fl=*,searchScope,score&fq=searchScope:(SRM+OR+SMN)&indent=on
> 
> But when I try to do it programitically I get an
> error.  It only works when I am filtering on 1 value,
> but when I try more than one value it fails.
> See code snippet  and error message below.  When
> I use filter2 or filter3 it fails, but filter1 gives me no
> Errors
> 
> Not sure what I am doing wrong.  Any help would be
> greatly appreciated.
> 
> -----Begin Code snippet ---
> String query = "help";
> 
> //String filter1 = "searchScope:SRM
> //String filter2 = "+searchScope:SRM+searchScope:SMN";
> String filter3 = "searchScope:(SRM+OR+SMN)";
> 

You need to replace + with space: 
String filter3 = "searchScope:(SRM OR SMN)"; should work.

Re: filter query error

Posted by Ahmet Arslan <io...@yahoo.com>.
> I am trying to use a filter query that filters on more than
> one value for a given filter  ie. filters on field
> equals value1 or value2
> 
> If I enter the following 2 urls in a browser I get back the
> correct results I am looking for:
> 
> http://localhost:8080/apache-solr-1.4.0/select/?q=help&fl=*,score&fq=+searchScope:SRM+searchScope:SMN&indent=on
> or
> http://localHost:8080/apache-solr-1.4.0/select/?q=help&fl=*,searchScope,score&fq=searchScope:(SRM+OR+SMN)&indent=on
> 
> But when I try to do it programitically I get an
> error.  It only works when I am filtering on 1 value,
> but when I try more than one value it fails.
> See code snippet  and error message below.  When
> I use filter2 or filter3 it fails, but filter1 gives me no
> Errors
> 
> Not sure what I am doing wrong.  Any help would be
> greatly appreciated.
> 
> -----Begin Code snippet ---
> String query = "help";
> 
> //String filter1 = "searchScope:SRM
> //String filter2 = "+searchScope:SRM+searchScope:SMN";
> String filter3 = "searchScope:(SRM+OR+SMN)";
> 

You need to replace + with space: 
String filter3 = "searchScope:(SRM OR SMN)"; should work.