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 Jed Reynolds <li...@benrey.is-a-geek.net> on 2007/08/30 19:29:44 UTC
minimum occurances of term in document
Apologies if this is in the Lucene FAQ, but I was looking thru the
Lucene syntax and I just didn't see it.
Is there a way to search for documents that have a certain number of
occurrences of a term in the document? Like, I want to find all
documents that have the term Calico mentioned three or more times in the
document?
Thanks
Jed
Re: minimum occurances of term in document
Posted by Jed Reynolds <li...@benrey.is-a-geek.net>.
Mike Klaas wrote:
>
> On 30-Aug-07, at 4:01 PM, Chris Hostetter wrote:
>
>>
>>>> You could accomplish the goal without any coding by using phrase
>>>> queries: "calico calico calico"~10000 will match only documents
>>>> that have at least three occurrences of calico. If this is
>>>> performant enough, you are done. Otherwise, you'll have to do some
>>>> custom coding.
>>>
>>> I'll be searching article content so literals like "cat cat cat" are
>>> improbable.
>>
>> i think you missunderstood Mike's point ... the query string...
>> foo:"cat cat cat"~10000
>>
>> ...will only match documents containing three instances of the term
>> "cat" in the field "foo" where those instances are all withing 10000
>> term positions of eachother ... hte idea being that as long as the
>> "slop" (number) used is bigger then the largest document you expect
>> to deal with, this will esentially give you want you want.
>
> Note too that by default solr only indexes the first 10k tokens, so
> this should work for all documents in the index.
>
> -Mike
>
Whoa! When I first read the original suggestion, I was thinking ^10000
because I happened to be googling "solr filter by score" (another topic
I learned is hardly worth persuing).
Yeah, I'm going to try that right now....
Jed
Re: minimum occurances of term in document
Posted by Mike Klaas <mi...@gmail.com>.
On 30-Aug-07, at 4:01 PM, Chris Hostetter wrote:
>
>>> You could accomplish the goal without any coding by using phrase
>>> queries: "calico calico calico"~10000 will match only documents
>>> that have at least three occurrences of calico. If this is
>>> performant enough, you are done. Otherwise, you'll have to do
>>> some custom coding.
>>
>> I'll be searching article content so literals like "cat cat cat"
>> are improbable.
>
> i think you missunderstood Mike's point ... the query string...
> foo:"cat cat cat"~10000
>
> ...will only match documents containing three instances of the term
> "cat" in the field "foo" where those instances are all withing
> 10000 term positions of eachother ... hte idea being that as long
> as the "slop" (number) used is bigger then the largest document you
> expect to deal with, this will esentially give you want you want.
Note too that by default solr only indexes the first 10k tokens, so
this should work for all documents in the index.
-Mike
Re: minimum occurances of term in document
Posted by Chris Hostetter <ho...@fucit.org>.
>> You could accomplish the goal without any coding by using phrase queries:
>> "calico calico calico"~10000 will match only documents that have at least
>> three occurrences of calico. If this is performant enough, you are done.
>> Otherwise, you'll have to do some custom coding.
>
> I'll be searching article content so literals like "cat cat cat" are
> improbable.
i think you missunderstood Mike's point ... the query string...
foo:"cat cat cat"~10000
...will only match documents containing three instances of the term "cat"
in the field "foo" where those instances are all withing 10000 term
positions of eachother ... hte idea being that as long as the "slop"
(number) used is bigger then the largest document you expect to deal with,
this will esentially give you want you want.
-Hoss
Re: minimum occurances of term in document
Posted by Jed Reynolds <li...@benrey.is-a-geek.net>.
Mike Klaas wrote:
> On 30-Aug-07, at 1:22 PM, Jed Reynolds wrote:
>
>> Jed Reynolds wrote:
>>>
>>> Apologies if this is in the Lucene FAQ, but I was looking thru the
>>> Lucene syntax and I just didn't see it.
>>>
>>> Is there a way to search for documents that have a certain number of
>>> occurrences of a term in the document? Like, I want to find all
>>> documents that have the term Calico mentioned three or more times in
>>> the document?
>>
>> Apologies for the ignorant question. I believe what I'm looking to do
>> is filter results on term frequency. I of course can get term
>> frequency data from the debug output, but I'd rather not engage in
>> application-level filtering by parsing the debug output.
>>
>> It looks like there could be a few ways to purse incorporating a term
>> frequency modifier into a search. I'd think that results could be fq
>> filtered thru the fq step, if I could change the fq step to filter on
>> term freq. I presume a QueryHandler could be made to do that, too. I
>> presume that a QueryParser and a Searcher could do the job.
>>
>> Any suggestions about a reasonable way to go about this would be
>> appreciated.
>
> You could accomplish the goal without any coding by using phrase
> queries: "calico calico calico"~10000 will match only documents that
> have at least three occurrences of calico. If this is performant
> enough, you are done. Otherwise, you'll have to do some custom coding.
I'll be searching article content so literals like "cat cat cat" are
improbable.
> One way would be to create your own Query subclass (similar to
> TermQuery) that returned a score of zero for docs below a certain tf
> threshold. This is probably the most efficient. Rather than creating
> a custom queryparser, it probably would be easier to add an extra
> parameter to a custom request handler than parsed
> (<field>:<term>:<count>) into your custom query class add added it in
> the appropriate place (eg. as a filter).
A Query subclass sounds the most efficient, and probably allows the most
accurate way to control results.
Thanks for the suggestions!
Jed
Re: minimum occurances of term in document
Posted by Mike Klaas <mi...@gmail.com>.
On 30-Aug-07, at 3:30 PM, Chris Hostetter wrote:
>> One way would be to create your own Query subclass (similar to
>> TermQuery) that returned a score of zero for docs below a certain
>> tf threshold. This is
>
> minor clarification: a score of zero is still a match ... the key
> to writting custom queries is to "skip" past a document that
> doesn't meet the criteria you want and not return any score for it
> at all.
Good to know. Thanks Hoss.
-Mike
Re: minimum occurances of term in document
Posted by Chris Hostetter <ho...@fucit.org>.
> One way would be to create your own Query subclass (similar to TermQuery)
> that returned a score of zero for docs below a certain tf threshold. This is
minor clarification: a score of zero is still a match ... the key to
writting custom queries is to "skip" past a document that doesn't meet the
criteria you want and not return any score for it at all.
if you wnat to write a custom query class, start by making sure you
understand all of hte internals of Scoring...
http://lucene.apache.org/java/docs/scoring.html
...at that point the java-user mailing list is probably a better place to
ask questions about the details involved in writing custom Query classes.
-Hoss
Re: minimum occurances of term in document
Posted by Mike Klaas <mi...@gmail.com>.
On 30-Aug-07, at 1:22 PM, Jed Reynolds wrote:
> Jed Reynolds wrote:
>>
>> Apologies if this is in the Lucene FAQ, but I was looking thru the
>> Lucene syntax and I just didn't see it.
>>
>> Is there a way to search for documents that have a certain number
>> of occurrences of a term in the document? Like, I want to find all
>> documents that have the term Calico mentioned three or more times
>> in the document?
>
> Apologies for the ignorant question. I believe what I'm looking to
> do is filter results on term frequency. I of course can get term
> frequency data from the debug output, but I'd rather not engage in
> application-level filtering by parsing the debug output.
>
> It looks like there could be a few ways to purse incorporating a
> term frequency modifier into a search. I'd think that results could
> be fq filtered thru the fq step, if I could change the fq step to
> filter on term freq. I presume a QueryHandler could be made to do
> that, too. I presume that a QueryParser and a Searcher could do the
> job.
>
> Any suggestions about a reasonable way to go about this would be
> appreciated.
You could accomplish the goal without any coding by using phrase
queries: "calico calico calico"~10000 will match only documents that
have at least three occurrences of calico. If this is performant
enough, you are done. Otherwise, you'll have to do some custom coding.
One way would be to create your own Query subclass (similar to
TermQuery) that returned a score of zero for docs below a certain tf
threshold. This is probably the most efficient. Rather than
creating a custom queryparser, it probably would be easier to add an
extra parameter to a custom request handler than parsed
(<field>:<term>:<count>) into your custom query class add added it in
the appropriate place (eg. as a filter).
best,
-Mike
Re: minimum occurances of term in document
Posted by Jed Reynolds <li...@benrey.is-a-geek.net>.
Jed Reynolds wrote:
>
> Apologies if this is in the Lucene FAQ, but I was looking thru the
> Lucene syntax and I just didn't see it.
>
> Is there a way to search for documents that have a certain number of
> occurrences of a term in the document? Like, I want to find all
> documents that have the term Calico mentioned three or more times in
> the document?
Apologies for the ignorant question. I believe what I'm looking to do is
filter results on term frequency. I of course can get term frequency
data from the debug output, but I'd rather not engage in
application-level filtering by parsing the debug output.
It looks like there could be a few ways to purse incorporating a term
frequency modifier into a search. I'd think that results could be fq
filtered thru the fq step, if I could change the fq step to filter on
term freq. I presume a QueryHandler could be made to do that, too. I
presume that a QueryParser and a Searcher could do the job.
Any suggestions about a reasonable way to go about this would be
appreciated.
Thanks!
Jed