lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mufaddal Khumri" <MKhu...@allegromedical.com>
Subject Question regarding boosting
Date Fri, 20 May 2005 22:34:29 GMT
Hi,

I wanted to know what method would be the best way to do something that
I am describing below.

I am creating an index of all my products and categories. While
indexing, I am creating the following documents for my products and
categories:

Product:
		doc.add(Field.UnIndexed("id", (String)obj[0]));
		doc.add(Field.Keyword("entity","product"));
		doc.add(Field.Text("name", name));
		doc.add(Field.Text("content", content));

Category:
		doc.add(Field.UnIndexed("id", (String)obj[0]));
		doc.add(Field.Keyword("entity","category"));
		doc.add(Field.Text("name", name));
		doc.add(Field.Text("content", content));

As you can see above the id is stored to retrieve the objects from the
database. The entity field distinguishes whether I want to carry out my
search on products or categories. The content field is a combination of
the name and description of the product and category. The name field is
the name of the product or the name of the category.

My searches and indexing works great.

This is how I am searching:

	Query query1 =
QueryParser.parse(queryString,"content",analyzer);
		
	Term term = null;
	if(entity.equals("product"))
	  term = new Term("entity","product");
	else
	if(entity.equals("category"))
	  term = new Term("entity","category");
		  
	TermQuery query2 = new TermQuery(term); 
	BooleanQuery bq = new BooleanQuery();
	bq.add(query1, true, false);
	bq.add(query2, true, false);
		
	return indexSearcher.search(bq);

As you can see above I am using the content and entity fields to do my
search and everything works fine. What I want to do now is that I want
to boost the results such that if the query matches the name field it
gives a higher rank. How do I do this?

For example adding something like this:
	...
	Query query3 = QueryParser.parse(queryString,"name",analyzer);
	query3.setBoost(2);
	...
	...
	bq.add(query3, true, false);

When I do the above, I print a toString on my final Boolean query which
is:

	+content:radio +entity:category +name:radio^2.0

When I am doing my search for "products", lets say, how do I tell lucene
that - "Show me all products such that the results are ordered in such a
way that if a product's name matches the querystring more it gets a
higher relevance"

So the relevance should be in the following order:

1. Product name matches more - more relevance.
2. Product content matches - relevance is more but less than the
relevance given to product name in 1.

Any ideas?

Thanks.

------------------------------------------------------------------------------------------
This email and any files transmitted with it are confidential 
and intended solely for the use of the individual or entity 
to whom they are addressed. If you have received this 
email in error please notify the system manager. Please
note that any views or opinions presented in this email 
are solely those of the author and do not necessarily
represent those of the company. Finally, the recipient
should check this email and any attachments for the 
presence of viruses. The company accepts no liability for
any damage caused by any virus transmitted by this email.
Consult your physician prior to the use of any medical
supplies or product.
------------------------------------------------------------------------------------------


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


Mime
View raw message