You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Peter Keegan <pe...@gmail.com> on 2009/03/03 20:42:40 UTC
sloppyFreq question
The DefaultSimilarity class defines sloppyFreq as:
public float sloppyFreq(int distance) {
return 1.0f / (distance + 1);
}
For a 'SpanNearQuery', this reduces the effect of the term frequency on the
score as the number of terms in the span increases. So, for a simple phrase
query (using spans), the longer the phrase, the lower the TF. For a simple
SpanTermQuery, the TF is reduced in half (1.0f / 1 + 1).
I'm just wondering why this is the default behavior. For 'SpanTermQuery',
I'd expect the TF to reflect the actual number of occurrences of the term.
For a SpanNearQuery, wouldn't it still be the number of occurrences of the
whole span, not the number of terms in the span?
Thanks,
Peter
Re: sloppyFreq question
Posted by Chris Hostetter <ho...@fucit.org>.
: Sorry, here's the example I meant to show. Doc 1 and doc 2 both contain the
: terms "hey look, the quick brown fox jumped very high", but in Doc 1 all the
: terms are indexed at the same position. In doc 2, the terms are indexed in
: adjacent positions (normal way). For the query "the quick brown fox", doc 1
: will score higher than doc 2 because the sloppyFreq = 1/2 for doc 1 and 1/5
: for doc 2. So, the term frequency factor for the score takes into account
: both the number of matching terms and the distance between them.
:
: This is fine for most span queries with more than 1 term (i guess), but I'd
: still suggest that a simple SpanTermQuery should behave more like TermQuery
I don't disagree with you ... that's why i said...
>> I suppose SpanTermQuery could override the weight/scorer methods so
>> that it behaved more like a TermQuery if it was executed directly ...
...especially since BoostingTermQuery subclasses SpanTermQuery.
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: sloppyFreq question
Posted by Peter Keegan <pe...@gmail.com>.
Sorry, here's the example I meant to show. Doc 1 and doc 2 both contain the
terms "hey look, the quick brown fox jumped very high", but in Doc 1 all the
terms are indexed at the same position. In doc 2, the terms are indexed in
adjacent positions (normal way). For the query "the quick brown fox", doc 1
will score higher than doc 2 because the sloppyFreq = 1/2 for doc 1 and 1/5
for doc 2. So, the term frequency factor for the score takes into account
both the number of matching terms and the distance between them.
This is fine for most span queries with more than 1 term (i guess), but I'd
still suggest that a simple SpanTermQuery should behave more like TermQuery
w.r.t. sloppyFreq. Fortunately all of this is can be overridden in the
Similarity class. No real problem here - the discussions are quite helpful
though.
Thanks,
Peter
On Tue, Mar 17, 2009 at 7:18 PM, Chris Hostetter
<ho...@fucit.org>wrote:
>
> : > I suppose SpanTermQuery could override the weight/scorer methods so
> that
> : > it behaved more like a TermQuery if it was executed directly ... but
> : > that's really not what it's intended for.
> :
> : This is currently the only way to boost a term via payloads.
> : BoostingTermQuery extends SpanTermQuery.
>
> probably because it was the easiest way to get at the payload ... another
> reason to cahnge SpanTermQuery's weight i guess.
>
> : > if you're talking about a SpanNearQuery of "the quick brown fox" vs a
> : > SpanNearQuery of "brown fox" -- both against some doc like "hey look,
> the
> : > quick brown fox jumped very high" -- then sure, that doc might produce
> a
> : > lower score for the first query then it does for the second query ...
> but
> : > scores from differnet queries aren't comparable.
> :
> : Yes, this is the case I meant. To the casual observer, they both appear
> to
> : be "exact matches' with respect to term frequency. However, I realize
> that
> : the first query would score higher than the 2nd if all 4 terms were
> indexed
> : at the same position. I guess this is part of the point you're making
> about
> : spans. Would a plain PhraseQuery behave this way, too?
>
> i think you're missing my point -- it's not specific to spans: it doesn't
> mean *anything* to say "the first query would score higher then the 2nd"
> because scores aren't comparable between queries. (unless you really go
> out of your way to make them comparable by customizing Similarity, and
> ensuring that they have hte exact same structure -- a SpanNearQuery
> containing 5 SpanTermQueries doesn't have the same structure as a
> SpanNearQuery containing two SpanTermQueries)
>
>
>
> -Hoss
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: sloppyFreq question
Posted by Chris Hostetter <ho...@fucit.org>.
: > I suppose SpanTermQuery could override the weight/scorer methods so that
: > it behaved more like a TermQuery if it was executed directly ... but
: > that's really not what it's intended for.
:
: This is currently the only way to boost a term via payloads.
: BoostingTermQuery extends SpanTermQuery.
probably because it was the easiest way to get at the payload ... another
reason to cahnge SpanTermQuery's weight i guess.
: > if you're talking about a SpanNearQuery of "the quick brown fox" vs a
: > SpanNearQuery of "brown fox" -- both against some doc like "hey look, the
: > quick brown fox jumped very high" -- then sure, that doc might produce a
: > lower score for the first query then it does for the second query ... but
: > scores from differnet queries aren't comparable.
:
: Yes, this is the case I meant. To the casual observer, they both appear to
: be "exact matches' with respect to term frequency. However, I realize that
: the first query would score higher than the 2nd if all 4 terms were indexed
: at the same position. I guess this is part of the point you're making about
: spans. Would a plain PhraseQuery behave this way, too?
i think you're missing my point -- it's not specific to spans: it doesn't
mean *anything* to say "the first query would score higher then the 2nd"
because scores aren't comparable between queries. (unless you really go
out of your way to make them comparable by customizing Similarity, and
ensuring that they have hte exact same structure -- a SpanNearQuery
containing 5 SpanTermQueries doesn't have the same structure as a
SpanNearQuery containing two SpanTermQueries)
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: sloppyFreq question
Posted by Peter Keegan <pe...@gmail.com>.
> I suppose SpanTermQuery could override the weight/scorer methods so that
> it behaved more like a TermQuery if it was executed directly ... but
> that's really not what it's intended for.
This is currently the only way to boost a term via payloads.
BoostingTermQuery extends SpanTermQuery.
> if you're talking about a SpanNearQuery of "the quick brown fox" vs a
> SpanNearQuery of "brown fox" -- both against some doc like "hey look, the
> quick brown fox jumped very high" -- then sure, that doc might produce a
> lower score for the first query then it does for the second query ... but
> scores from differnet queries aren't comparable.
Yes, this is the case I meant. To the casual observer, they both appear to
be "exact matches' with respect to term frequency. However, I realize that
the first query would score higher than the 2nd if all 4 terms were indexed
at the same position. I guess this is part of the point you're making about
spans. Would a plain PhraseQuery behave this way, too?
Peter
On Wed, Mar 11, 2009 at 3:16 PM, Chris Hostetter
<ho...@fucit.org>wrote:
>
> : For a SpanNearQuery that contains SpanTermQueries, the score for a match
> on
> : "the quick brown fox" would be lower than a match on "brown fox" because
> of
> : the edit distance (4 vs 2). This seems counter intuitive, too.
>
> you have to clarify what you mean ...
>
> if you're talking about a SpanNearQuery of "the quick brown fox" vs a
> SpanNearQuery of "brown fox" -- both against some doc like "hey look, the
> quick brown fox jumped very high" -- then sure, that doc might produce a
> lower score for the first query then it does for the second query ... but
> scores from differnet queries aren't comparable.
>
> if you mean that a doc containing "the quick brown fox" will score lower
> then a doc containing just "brown fox" then you have to elaborate on waht
> query structure you're talking about where this is true.
>
>
>
> -Hoss
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>
Re: sloppyFreq question
Posted by Chris Hostetter <ho...@fucit.org>.
: For a SpanNearQuery that contains SpanTermQueries, the score for a match on
: "the quick brown fox" would be lower than a match on "brown fox" because of
: the edit distance (4 vs 2). This seems counter intuitive, too.
you have to clarify what you mean ...
if you're talking about a SpanNearQuery of "the quick brown fox" vs a
SpanNearQuery of "brown fox" -- both against some doc like "hey look, the
quick brown fox jumped very high" -- then sure, that doc might produce a
lower score for the first query then it does for the second query ... but
scores from differnet queries aren't comparable.
if you mean that a doc containing "the quick brown fox" will score lower
then a doc containing just "brown fox" then you have to elaborate on waht
query structure you're talking about where this is true.
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org
Re: sloppyFreq question
Posted by Peter Keegan <pe...@gmail.com>.
The reason I asked about Span scoring is that the behavior changed when I
switched from TermQuery to BoostingTermQuery to take advantage of payloads.
It seems to me that a SpanTermQuery and BoostingTermQuery should behave the
same as TermQuery with respect to term frequency. The 'edit distance' isn't
really relevant for these queries, is it?
For a SpanNearQuery that contains SpanTermQueries, the score for a match on
"the quick brown fox" would be lower than a match on "brown fox" because of
the edit distance (4 vs 2). This seems counter intuitive, too.
Any comments?
Thanks,
Peter
On Tue, Mar 3, 2009 at 2:42 PM, Peter Keegan <pe...@gmail.com> wrote:
> The DefaultSimilarity class defines sloppyFreq as:
>
> public float sloppyFreq(int distance) {
> return 1.0f / (distance + 1);
> }
>
> For a 'SpanNearQuery', this reduces the effect of the term frequency on the
> score as the number of terms in the span increases. So, for a simple phrase
> query (using spans), the longer the phrase, the lower the TF. For a simple
> SpanTermQuery, the TF is reduced in half (1.0f / 1 + 1).
>
> I'm just wondering why this is the default behavior. For 'SpanTermQuery',
> I'd expect the TF to reflect the actual number of occurrences of the term.
> For a SpanNearQuery, wouldn't it still be the number of occurrences of the
> whole span, not the number of terms in the span?
>
> Thanks,
> Peter
>
Re: sloppyFreq question
Posted by Chris Hostetter <ho...@fucit.org>.
: For a 'SpanNearQuery', this reduces the effect of the term frequency on the
: score as the number of terms in the span increases. So, for a simple phrase
: query (using spans), the longer the phrase, the lower the TF. For a simple
: SpanTermQuery, the TF is reduced in half (1.0f / 1 + 1).
:
: I'm just wondering why this is the default behavior. For 'SpanTermQuery',
: I'd expect the TF to reflect the actual number of occurrences of the term.
: For a SpanNearQuery, wouldn't it still be the number of occurrences of the
: whole span, not the number of terms in the span?
I believe it's because a Span typically encomases multiple positions --
there's no advantage i can think of for executing a SpanTermQuery
directly. note that when you execute a SpanQuery, it doesn't pay any
attention to the tf/idf of any nested queries, it only looks at the
aggregated Spans.
I suppose SpanTermQuery could override the weight/scorer methods so that
it behaved more like a TermQuery if it was executed directly ... but
that's really not what it's intended for.
(it's unfortunate that all of the SpanQueries use a hierarchical class
structure instead of having a single SpanQuery that composes a
"SpanClause" hierarchy)
-Hoss
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org