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 Ching-Pei Hsing <cp...@comergent.com> on 2003/03/11 04:11:20 UTC

Need help in changing the search score

Hi,

Can somebody help us to figure out how to build queries (or tune Lucene) to
return the result in a specific order? When search against multiple fields,
It seems like Lucene will give partial matching in multiple fields higher
score than better matching in a single field. Take the following as an
example,

		Product1
		Name: "Comfort Inn Shampoo"
		Manufacture Model Number (MMNUM): "XXXX"
		Supplier Model Number (SMNUM): "YYYY"

		Product2
		Name: "Inn xxxx yyyy"
		Manufacture Model Number (MMNUM): "Inn aaaa bbbb"
		Supplier Model Number (SMNUM): "Inn cccc dddd"

If we enter the search term "comfort inn shampoo" to search against all
three fields "Name", "Manufacture Model Number" and "Supplier Model Number",
Product2 will come back on top of Product1 because "Inn" is partially
matched in 3 fields in Product2, even though Name is a perfect match in
Product1. What we really want is to some how give Product1 higher score than
Product2.

The query issued is like the following (The queries are generated
programmatically and the booster is put by calling "setBoost" on the Query
object)

query = (NAME:inn NAME:comfort NAME:shampoo) (MMNUM:inn MMNUM:shampoo
MMNUM:comfort) (SMNUM:shampoo SMNUM:comfort SMNUM:inn)

Even if we boost the Name by 10 like the following query, It's still the
same. 

query = (NAME:inn NAME:comfort NAME:shampoo)^10 (MMNUM:inn MMNUM:shampoo
MMNUM:comfort) (SMNUM:shampoo SMNUM:comfort SMNUM:inn)

Is there any thing we can do to make better matching in a single fields earn
higher score than partial matching in several fields?

Any help would be greatly appreciated.

Ching-pei


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


what's wrong with getting a standardTokenizer from a standardAnalyzer ?

Posted by Alain Lauzon <al...@libertefinanciere.com>.
When I run code that includes this :

StandardAnalyzer analyzer = new StandardAnalyzer();
StandardTokenizer tokenizer = 
(StandardTokenizer)analyzer.tokenStream("someFieldName", someReader);

I get that:
  caught a class java.lang.ClassCastException
  with message: org.apache.lucene.analysis.StopFilter
java.lang.ClassCastException: org.apache.lucene.analysis.StopFilter
         at SearchCompanies.search(SearchCompanies.java:432)
         at SearchCompanies.main(SearchCompanies.java:134)

Any clue on what's wrong with getting a standardTokenizer from a 
standardAnalyzer ?

Alain Lauzon

Re: Need help in changing the search score

Posted by Doug Cutting <cu...@lucene.com>.
Ching-Pei Hsing wrote:
> Even if we boost the Name by 10 like the following query, It's still the
> same. 
> 
> query = (NAME:inn NAME:comfort NAME:shampoo)^10 (MMNUM:inn MMNUM:shampoo
> MMNUM:comfort) (SMNUM:shampoo SMNUM:comfort SMNUM:inn)

In the 1.2 release, I don't think this sort of boosting (of a complex 
clause) has any affect.  To do what you want in 1.2 you need to instead 
formulate this as follows, boosting individual terms only:

(NAME:inn^10 NAME:comfort^10 NAME:shampoo^10) (MMNUM:inn MMNUM:shampoo 
MMNUM:comfort) (SMNUM:shampoo SMNUM:comfort SMNUM:inn)

This is fixed in the pre-1.3 sources.  In 1.3 there will also be a query 
explanation feature and extensible scoring, both of which could be 
useful to you.  But I suspect that just boosting the individual terms, 
as above, will meet your needs now.

Doug


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