views:

17

answers:

1

Hello!

I am working on a mobile site that lets you search for tags of a MongoDB collection of articles.

Basically, each article object has a tags property, which stores an array of tag strings. The search works fine, but I also want to add logging to the searches.

The reason is that I want to see what visitors are searching for and what results they are getting in order to optimize the tags.

For example, if the user enters the tag grocery, then I want to save the query results.

Hope my question is clear. thank you!

+1  A: 

You can't optimize something without measuring. You'll need to be able to compare new results with old results. So you'll have to save a snapshot of all the information crucial to a search query. This obviously includes the search terms itself, but also an accurate snapshot of the result.

You could create snapshots of entire products, but it's probably more efficient to save only the information involved in determining the search results. In your case these are the article tags, but perhaps also the article description if this is used by your search engine.

After each search query you'll have to build a document similar to the following, and save this in a searchLog collection in MongoDB.

{
  query: "search terms",
  timestamp: new Date(), // time of the search
  results: [ // array of articles in the search result
    {
      articleId: 123, // _id of the original article
      name: "Lettuce", // name of the article, for easier analysis
      tags: [ "grocery", "lettuce" ] // snapshot of the article tags
      // snapshots of other article properties, if relevant
    },
    {
      articleId: 456,
      name: "Bananas",
      tags: [ "fruit", "banana", "yellow" ]
    }
  ]
}
Niels van der Rest
Thanks! That's exactly what I did. I just save the search term and snapshots of the relevant result set. In my case, I just saved the article id.
AbeP