Thomas Steinhaeuser
Thomas Steinhaeuser

Reputation: 21

Cloudant Lucene index with different relevance per field

How can I specify during the index creation that one field should receive more relevance than another field?

Example: I have documents with a title and a description field and want the content of the title field to be more important during query time.

doc1: title:"Hello, world", description:"Just a greeting" doc2: title:"Greetings", description:"Hello, everybody. Hello, hello"

index("default", doc.title); index("default", doc.description);

A search for the term "hello" should return doc1 one with a higher relevance than doc2 because the word "hello" is present in the title field even though doc2 contains the word 3 times.

How can this be accomplished?

Upvotes: 0

Views: 90

Answers (1)

Glynn Bird
Glynn Bird

Reputation: 5637

You can specify a boost at query time e.g. if you index items separately

index("title", doc.title);
index("description", doc.description);

Then at query time your can specify that the title gets more weight than the description field

q=(title:hello)^100 OR (description:hello)

where ^100 indicates that this term is boosted. See https://docs.cloudant.com/search.html#query-syntax

Upvotes: 1

Related Questions