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 Jimi Hullegård <ji...@mogul.com> on 2008/10/02 13:39:46 UTC

Calculation of fieldNorm causes irritating effect of sort order

Hi,

Maybe I have missunderstood the general concept of how search results should be scored in regards to the fieldNorm, but the way i see it it causes an irritating effect of the sort order for me.

Here's the deal:

I'm building a simple site with documents that represents ideas. Each idea can be active or inactive. Our search page have a simple textfield for search text input. Other then that, the only thing the user can influence is whether to search on all ideas, or only active ones. The problem is that if the search for all ideas only had active ideas in the result, the sort order can change if the user then wants to do the same search but for only active ideas.

Example:

A search for "betyg", where the user doesn't care if the ideas are active or inactive, gives this result:

document-153
document-244

The user then checkes the checkbox "Only active ideas", and clicks the search button again. Now the result is:

document-244
document-153

When I turned on debug mode for the lucene part of the 3rd party CMS, I saw the queries that lucene got:

The first query:
+type:idea +alltext:betyg

The second query:
+type:idea +(+alltext:betyg +category:14)

(The category 14 represents the status Active.)


I started Luke, and did the same searches there, and got the same result there (the results sort order of the first search was the reverse of the results sort order of the second search). I then clicked the "Explain" button for each document. There I found that all nodes had the same value for both documents, except for the last one, the fieldNorm for the field category.

I then did a quick google search for this fieldNorm, and found this:

http://www.mail-archive.com/lucene-user@jakarta.apache.org/msg06275.html

so the fieldNorm is the product of the field boost for the document and the lengthNorm for the field in the document. I am pretty sure that the boost is the same for both documents, so that leaves only the lengthNorm. And according to the javadoc for the Similarity class, the lengthNorm value depends on the number of tokens in the field for the particular document. And now the strange behaivor makes sence, because the document 153 has a total of 6 different tokens for the category field, and the document 244 has only 5. But in this case, this behaivor is not really what I want. Do you have any suggestions on how to solve this? Is it possible to disable the lengthNorm calculation for particular fields?

Regards
/Jimi

mogul | jimi hullegård | system developer | hudiksvallsgatan 4, 113 30 stockholm sweden | +46 8 506 66 172 | +46 765 27 19 55 | jimi.hullegard@mogul.com | www.mogul.com

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Calculation of fieldNorm causes irritating effect of sort order

Posted by Jimi Hullegård <ji...@mogul.com>.
Erick wrote:
>
> Another possibility (and I'm not sure it'll work, but what
> the heck) would
> be
> to create a Filter for active ideas. So rather than add a
> "category:14"
> clause,
> you create a Category14Filter that you send to the query
> along with your
> +type:idea +alltext:betyg clauses. Now, category won't be considered
> in scoring (as I understand it, anyway). See the various
> Searcher.search()
> methods that take a Filter.
>
> Filters are pretty inexpensive to create, so if this works
> for you I'd just
> measure the time it takes to create a filter rather than
> cache them. But
> if you do want to cache filters, CachingWrapperFilter may be
> your friend.
>
> NOTE: I have no clue whether this will do what you want, but I vaguely
> remember from wildcard filter discussions that it might. And
> it would still
> allow boosts on the fields you were searching on....

Thanks for the filter suggestion. Filters is something I have not looked into much yet, but I plan to do it soon. For now I tried the setOmitNorms(true) approach (mostly because I wanted to see how easy it was to do this in a clever way, without hacking the CMS), and it worked like a charm.

So, thanks Erik and Erick, for your suggestions!

/Jimi

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Calculation of fieldNorm causes irritating effect of sort order

Posted by Erick Erickson <er...@gmail.com>.
Another possibility (and I'm not sure it'll work, but what the heck) would
be
to create a Filter for active ideas. So rather than add a "category:14"
clause,
you create a Category14Filter that you send to the query along with your
+type:idea +alltext:betyg clauses. Now, category won't be considered
in scoring (as I understand it, anyway). See the various Searcher.search()
methods that take a Filter.

Filters are pretty inexpensive to create, so if this works for you I'd just
measure the time it takes to create a filter rather than cache them. But
if you do want to cache filters, CachingWrapperFilter may be your friend.

NOTE: I have no clue whether this will do what you want, but I vaguely
remember from wildcard filter discussions that it might. And it would still
allow boosts on the fields you were searching on....

Best
Erick

On Thu, Oct 2, 2008 at 8:47 AM, Jimi Hullegård <ji...@mogul.com>wrote:

> Erik wrote:
> >
> > On Oct 2, 2008, at 7:39 AM, Jimi Hullegård wrote:
> > > Is it possible to disable the lengthNorm calculation for particular
> > > fields?
> >
> > Yes, use Field#setOmitNorms(true) when indexing.
>
> Ok, thanks. I will just have to look on how to do this the best way (since
> the CMS is handling most of the indexing stuff).
>
> But apparently this setOmitNorms(true) also disables boosting aswell. That
> is ok for now, but what if we want to use boosting in the future? Is there
> no way to disable the length normalization while still keeping the boost
> calculation?
>
> /Jimi
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
> For additional commands, e-mail: java-user-help@lucene.apache.org
>
>

RE: Calculation of fieldNorm causes irritating effect of sort order

Posted by Jimi Hullegård <ji...@mogul.com>.
Karl Wrote:
>
> 2 okt 2008 kl. 14.47 skrev Jimi Hullegård:
>
> > But apparently this setOmitNorms(true) also disables boosting
> > aswell. That is ok for now, but what if we want to use boosting in
> > the future? Is there no way to disable the length normalization
> > while still keeping the boost calculation?
>
> You can make Similarity#lengthNorm(String fieldName, int numTokens)
> return a constant (1f) to turn off length normalization but keep the
> index time boost.

Thanks for the suggestion, however the CMS has for some reasoned designed its search code so that it is more or less impossible to change the Similarity implementation.

/Jimi

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Calculation of fieldNorm causes irritating effect of sort order

Posted by Karl Wettin <ka...@gmail.com>.
2 okt 2008 kl. 14.47 skrev Jimi Hullegård:

> But apparently this setOmitNorms(true) also disables boosting  
> aswell. That is ok for now, but what if we want to use boosting in  
> the future? Is there no way to disable the length normalization  
> while still keeping the boost calculation?

You can make Similarity#lengthNorm(String fieldName, int numTokens)  
return a constant (1f) to turn off length normalization but keep the  
index time boost.


     kalle
---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


RE: Calculation of fieldNorm causes irritating effect of sort order

Posted by Jimi Hullegård <ji...@mogul.com>.
Erik wrote:
>
> On Oct 2, 2008, at 7:39 AM, Jimi Hullegård wrote:
> > Is it possible to disable the lengthNorm calculation for particular
> > fields?
>
> Yes, use Field#setOmitNorms(true) when indexing.

Ok, thanks. I will just have to look on how to do this the best way (since the CMS is handling most of the indexing stuff).

But apparently this setOmitNorms(true) also disables boosting aswell. That is ok for now, but what if we want to use boosting in the future? Is there no way to disable the length normalization while still keeping the boost calculation?

/Jimi

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Calculation of fieldNorm causes irritating effect of sort order

Posted by Erik Hatcher <er...@ehatchersolutions.com>.
On Oct 2, 2008, at 7:39 AM, Jimi Hullegård wrote:
> Is it possible to disable the lengthNorm calculation for particular  
> fields?

Yes, use Field#setOmitNorms(true) when indexing.

	Erik


---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org


Re: Calculation of fieldNorm causes irritating effect of sort order

Posted by Chris Hostetter <ho...@fucit.org>.
If i'm reading your message correctly, you (and everyone who has replied 
so far) have gotten caught in a red herring.  While an "explain" on the 
results from your queryB will most likely show you that the 
fieldNorm is the main differantiator in score between document-153 and 
document-244 that's not what matters.  the fieldNorms are also the same 
in your first query as well -- so you should be asking "what makes the 
score for document-153 in queryA different from queryB?" (and likewise for 
document-244)

if you do that you'll see that the portion of the score coming from the 
"meat" of your query (+alltext:betyg) is greatly reduced between queryA 
and queryB because of the structure of queryB ... which combined with 
tf/idf and fieldNorms for your "type" and "category" fields can change the 
order of results.

As Erick pointed out, what you really want is for your type and category 
clauses to be implemented as a Filter, so that they don't factor into your 
scores at all.  baring that you should at a minimum change the structure 
and boosts of the queries you execute to be something like...

+alltext:betyg +(+type:idea +category:14)^0.00001)



: A search for "betyg", where the user doesn't care if the ideas are 
: active or inactive, gives this result:
: 
: document-153
: document-244
: 
: The user then checkes the checkbox "Only active ideas", and clicks the 
: search button again. Now the result is:
: 
: document-244
: document-153

: The first query:
: +type:idea +alltext:betyg
: 
: The second query:
: +type:idea +(+alltext:betyg +category:14)


-Hoss

---------------------------------------------------------------------
To unsubscribe, e-mail: java-user-unsubscribe@lucene.apache.org
For additional commands, e-mail: java-user-help@lucene.apache.org