2010-09-24 90 views
1

我正在使用移动网站,可以搜索MongoDB文章集合的标签。MongoDB C#日志搜索结果

基本上,每个文章对象都有一个tags属性,它存储了一个标签字符串数组。 搜索工作正常,但我也想将日志记录添加到搜索。

原因是我想查看访问者正在搜索的内容以及他们为了优化标签而得到的结果。

例如,如果用户输入标签杂货店,那么我想保存查询结果。

希望我的问题很清楚。谢谢!

回答

1

如果不进行测量,则无法优化。您需要能够将新结果与旧结果进行比较。因此,您必须保存对搜索查询至关重要的所有信息的快照。这显然包括搜索条件本身,但也是结果的准确快照。

您可以创建整个产品的快照,但仅保存确定搜索结果所涉及的信息可能更有效。在你的情况下,这些是文章标签,但也可能是文章描述,如果这是由您的搜索引擎使用。

在每次搜索查询之后,您将不得不构建类似于以下内容的文档,并将其保存在MongoDB的searchLog集合中。

{ 
    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" ] 
    } 
    ] 
} 
+0

谢谢!这正是我所做的。我只保存搜索项和相关结果集的快照。就我而言,我只保存了文章ID。 – Abe 2010-09-26 07:07:16