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 Colvin Cowie <co...@gmail.com> on 2020/12/05 10:04:25 UTC

What's the most efficient way to check if there are any matches for a query?

Hello,

I was just wondering. If I don't care about the number of matches for a
query, let alone what the matches are, just that there is *at least 1*
match for a query, what's the most efficient way to execute that query (on
the /select handler)? (Using Solr 8.7)

As a general approach for a query is "rows=0&sort=id asc" the best I can
do? Is there a more aggressive short circuit that will stop a searcher as
soon as it finds a match?

For a specific case where the query is for a single exact term in an
indexed field (with or without doc values) is there a different answer?

Thanks for any suggestions

Re: What's the most efficient way to check if there are any matches for a query?

Posted by Colvin Cowie <co...@gmail.com>.
Thanks for the suggestions. At some point I'll have to actually put it to
the test and see what impact everything has.

Cheers

On Sat, 5 Dec 2020 at 13:31, Erick Erickson <er...@gmail.com> wrote:

> Have you looked at the Term Query Parser (_not_ the TermS Query Parser)
> or Raw Query Parser?
>
> https://lucene.apache.org/solr/guide/8_4/other-parsers.html
>
> NOTE: these perform _no_ analysis, so you have to give them the exact
> term...
>
> These are pretty low level, and if they’re “fast enough” you won’t have to
> do
> any work. You could do some Lucene-level coding I suspect to improve that,
> depends on whether you think those are fast enough…
>
> Best,
> Erick
>
>
> > On Dec 5, 2020, at 5:04 AM, Colvin Cowie <co...@gmail.com>
> wrote:
> >
> > Hello,
> >
> > I was just wondering. If I don't care about the number of matches for a
> > query, let alone what the matches are, just that there is *at least 1*
> > match for a query, what's the most efficient way to execute that query
> (on
> > the /select handler)? (Using Solr 8.7)
> >
> > As a general approach for a query is "rows=0&sort=id asc" the best I can
> > do? Is there a more aggressive short circuit that will stop a searcher as
> > soon as it finds a match?
> >
> > For a specific case where the query is for a single exact term in an
> > indexed field (with or without doc values) is there a different answer?
> >
> > Thanks for any suggestions
>
>

Re: What's the most efficient way to check if there are any matches for a query?

Posted by Erick Erickson <er...@gmail.com>.
Have you looked at the Term Query Parser (_not_ the TermS Query Parser)
or Raw Query Parser? 

https://lucene.apache.org/solr/guide/8_4/other-parsers.html

NOTE: these perform _no_ analysis, so you have to give them the exact term...

These are pretty low level, and if they’re “fast enough” you won’t have to do
any work. You could do some Lucene-level coding I suspect to improve that,
depends on whether you think those are fast enough…

Best,
Erick


> On Dec 5, 2020, at 5:04 AM, Colvin Cowie <co...@gmail.com> wrote:
> 
> Hello,
> 
> I was just wondering. If I don't care about the number of matches for a
> query, let alone what the matches are, just that there is *at least 1*
> match for a query, what's the most efficient way to execute that query (on
> the /select handler)? (Using Solr 8.7)
> 
> As a general approach for a query is "rows=0&sort=id asc" the best I can
> do? Is there a more aggressive short circuit that will stop a searcher as
> soon as it finds a match?
> 
> For a specific case where the query is for a single exact term in an
> indexed field (with or without doc values) is there a different answer?
> 
> Thanks for any suggestions