Skip to content

User Improved Search Results

Daniel Whyte edited this page Sep 7, 2016 · 1 revision

User Improved Search Results

As a very basic way of improving search results based on popularity of results we are tracking the amount of clicks each item on a search results page receives.

Storing Results

The click counts are being stored in a LevelDB database called counts. A request to the /analytics endpoint is made every time a user clicks on an item on the search results page. This endpoint calls the update function in the scores.js file.

Result Structure

The click counts are stored in LevelDB with a key, and a value. The value is simply the click count. The key is a seven digit number, followed by a !, followed by the item id. The seven digit number will be one of the following: 0000000, 0010000, 0100000, 1000000. These represent the number of clicks an item has received, separated into four groups, which will be used to apply the different boost to the search result.

The number is prefixed to the key because of the way LevelDB stores items. The items are stored alphanumerically, so items with the same prefix will all be grouped together. This makes for a very quick request when we want to know what boost to give each item.

Update

The update function first looks for the item in the database. To find the item in the database, we have to check each count group + the item id. We do this using async.waterfall, checking one group at a time. If the item is found, we add one to the count, then check to see if the prefixed number group needs to be updated. If so, a new item with the same count and a new key (the id prefixed with the new count group) is added to the database, and the old one is deleted.

If the item is not found, it is added to the database with a count of 1, and a prefix of 0000000.

GetCount

To get the items in each count group, we create a read stream, then supply it with the ids we want to search between, as a 'lessthan' and 'greaterthan' argument. We then push that data into an array and return it to the search function to apply the relevant boost.