Luis Ashurei

Thinking in Data

| | email

Search Result Order Issue

While you have a website selling product, data structures as follows:

default_order_issue1 image

Order Issue

Web-styled application usually have two entrance: Search and Browse.
When you input term and search, the result order will be descent by matched "score", normally it is fine.

But how about products have the same score? Lucene and a lot of search libraries sort them by index order. That will be a problem, especially in Browse mode.
Base on the data from above picture, if I query skus for catalog under "Laptop Accessories", results will be:

No. Name
1Brand-1 Laptop Chill Mat
2Brand-1 Metro Roller Notebook Bag
3Brand-1 Laptop/LCD Privacy Filter
......
7Brand-2 Laptop Chill Mat
8Brand-2 Metro Roller Notebook Bag
9Brand-2 Laptop/LCD Privacy Filter

See? Brand-1's product might be above all other brands, it is unfair to Brand-2.

Rank Field

To solve the issue, we need to set a secondary sort field/column after score (let's say "rank"), to handle the cases when score is same.
Firstly have an order with catalog:

default_order_issue2 image

In this case lower level dimensions will have higher rank. You can write your own business order, set whatever catalog higher you want in the same nav level.

Next design an encoding method for field rank value.
For example, put the catalog rank# in the first of rank, with given a sequence# follows for each brand:

default_order_issue3 image

After all, query with rank desc, you'll see products is show with brand mixed.

No. Name Rank
1Brand-2 Laptop/LCD Privacy Filter83
2Brand-1 Laptop/LCD Privacy Filter83
3Brand-2 Metro Roller Notebook Bag82
4Brand-1 Metro Roller Notebook Bag82
5Brand-2 Laptop Chill Mat81
6Brand-1 Laptop Chill Mat81
.........

In Conclusion

Field rank encoding is not simple, it is hard. Above example may not have good experience while Brand-1's product is more than Brand-2's (vice versa), and don't have product factor (promo, seller, stock etc.) support. But it is the basic way to solve the issue.
About factor of rank algorithm will be in another topic.

28 Feb 2015