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 Evgeniy Strokin <ev...@yahoo.com> on 2008/02/12 21:01:06 UTC

Filter Query

Hello,.. Lets say I have one query like this:
NAME:Smith
I need to restrict the result and I'm doing this:
NAME:Smith AND AGE:30
Also, I can do this using fq parameter:
q=NAME:Smith&fq=AGE:30
The result of second and third queries should be the same, right?
But why should I use fq then? In which cases this is better? Can you give me example to better understand the problem?
 
Thank you
Gene

Re: SolrQuery.add

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Feb 14, 2008, at 7:26 AM, matthias walter wrote:
> I'm having problems using SolrQuery.add(String, String).
>
> My Sample code is:
>        SolrQuery anotherQuery = new SolrQuery();
>        anotherQuery.add("city", cmd.getCity());

This is incorrect (though admittedly confusing) use of the SolrQuery  
API.   What that does is the same as making this URL query:   ? 
city=<cmd.getCity()>

SolrQuery is-a SolrParams.

> If I do it like that:
>
>        SolrQuery query = new SolrQuery();
>        query.setQuery("city:" + cmd.getCity() + " AND age:24");
>
> Everything works fine.
>
> It's not a real problem because the second version does the job,  
> but the code is quite ugly.

There ya go!

	Erik


SolrQuery.add

Posted by matthias walter <ma...@smeet.de>.
Hi,

I'm having problems using SolrQuery.add(String, String).

My Sample code is:
        SolrQuery anotherQuery = new SolrQuery();
        anotherQuery.add("city", cmd.getCity());

I get the following error:
null  java.lang.NullPointerException     at 
org.apache.solr.common.util.StrUtils.splitSmart(StrUtils.java:36)     at 
org.apache.solr.search.OldLuceneQParser.parse(LuceneQParserPlugin.java:104) 
    at org.apache.solr.search.QParser.getQuery(QParser.java:80)     at 
org.apache.solr.handler.component.QueryComponent.prepare(QueryComponent.java:66) 
    at 
org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:143) 
    at 
org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:117) 
    at org.apache.solr.core.SolrCore.execute(SolrCore.java:902)     at 
org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:280) 
    at 
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:237) 
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202) 
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173) 
    at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213) 
    at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178) 
    at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126) 
    at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105) 
    at 
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:541) 
    at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107) 
    at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148) 
    at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869) 
    at 
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664) 
    at 
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527) 
    at 
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80) 
    at 
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684) 
    at java.lang.Thread.run(Thread.java:619)

request: 
http://localhost.local:8080/solr/select?city=Berlin&wt=xml&version=2.2

If I do it like that:

        SolrQuery query = new SolrQuery();
        query.setQuery("city:" + cmd.getCity() + " AND age:24");

Everything works fine.

It's not a real problem because the second version does the job, but the 
code is quite ugly.

Thanks for your help,

Matthias



Re: Filter Query

Posted by Shalin Shekhar Mangar <sh...@gmail.com>.
Using q=NAME:Smith&fq=AGE:30 would be better because filter queries
are cached separately and can be re-used regardless of the NAME query.
So if you expect your filter queries to be re-used, you should use fq,
otherwise performance would probably be the same for both "NAME:Smith
AND AGE:30" and "q=NAME:Smith&fq=AGE:30"

On Feb 13, 2008 1:31 AM, Evgeniy Strokin <ev...@yahoo.com> wrote:
> Hello,.. Lets say I have one query like this:
> NAME:Smith
> I need to restrict the result and I'm doing this:
> NAME:Smith AND AGE:30
> Also, I can do this using fq parameter:
> q=NAME:Smith&fq=AGE:30
> The result of second and third queries should be the same, right?
> But why should I use fq then? In which cases this is better? Can you give me example to better understand the problem?
>
> Thank you
> Gene



-- 
Regards,
Shalin Shekhar Mangar.