Using Search Weights
Go to WooCommerce > Settings > Search, check the option Use weights and save the changes.
The default values provide search results with an increased relevance for products with matching Titles, Product Short Descriptions and Tags in that order.
The relevance of a product in search results is based on matches in its Title, the Product Short Description (Excerpt), its Content and related Tags. Its relevance increases with the search weight of the categories that the product belongs to and its specific search weight.
To adjust the relevance of a product category, go to Products > Categories. Edit the desired category and indicate a Search Weight – the relevance of all products that belong to the category can be increased by indicating a positive value. If a product belongs to several categories, the maximum Search Weight is used.
To adjust the relevance of a single product, go to Products. Edit the desired product and under Product Data > Search indicate the desired Search Weight.
How Search Weights Work
Search Weights are calculated by summing weights based on matches in the product title, excerpt, short description and content plus category weights and individual product weights if they are set for products that are included in search results. To better help you understand how this works, we provide the following examples.
Assuming the default settings under WooCommerce > Search > Weights > Relevance
- Any matching search keyword will sum 50 when it occurs in the title. One matching keyword will sum 50 to the product’s relevance, two matching keywords in the title will sum 100 etc.
- Matching keywords in the excerpt sum 20 each.
- As the weight for content is set at 0, matches in the product’s content will not increase or decrease the relevance in search results.
- Tags are set to sum 10 per match, for example, three matching keywords in a product’s related tags will sum 30 to its relevance.
If a product or a product category defines a specific weight, it is added to the weights obtained based on these settings.
Let’s assume these three products :
- Product ID : 1
- Title: Yellow Banana
- Excerpt: A fruity experience full of joy
- Content: The Yellow Banana is a tasteful experience for the connoisseur.
- Tags: fruit, yellow, banana, sweet
- Product ID : 2
- Title: Green Apple
- Excerpt: It’s pretty sour!
- Content: An apple a day keeps the doctor away. This is a green apple, other varieties such as red or yellow apples are also available.
- Tags: fruit, green, apple, sour
- Product ID : 3
- Title: Red Orange
- Excerpt: Great for juice and cakes!
- Content: The Red Orange is the prettier variety of the ordinary Orange, with a deep red color and intense flavor.
- Tags: red, orange, juice, fruit
- Search Weight: 11 – Note that this product has a specific search weight defined.
Here are some example searches and computed weights. Only the computed weights of products that are included in search results are shown.
– Search #1 : fruit
W(1) = 20 + 10 = 30
W(2) = 10
W(3) = 10 + 11 = 21
Results in order of relevance: 1, 3, 2
– Search #2 : red fruit
W(1) = 20 + 10 = 30
W(2) = 10
W(3) = 10 + 10 + 11 = 31
Results in order of relevance: 3, 2
– Search #3 : green orange
W(2) = 50
W(3) = 50 + 11 = 61
Results in order of relevance : –
– Search #4 : red orange
W(2) = 0
W(3) = 50 + 50 + 11 = 111
Results in order of relevance : 3