【发布时间】:2013-07-23 00:13:00
【问题描述】:
我有一个结构类似于博客的社交功能:帖子和 cmets。
帖子有一个名为 body 的字段,cmets 也是如此。帖子和 cmets 存储在 SharePoint 列表中,因此直接 SQL 全文查询不可用。
如果有人输入“11月份的停电恢复效率”,我真的不知道如何根据帖子的内容及其附加的cmets正确返回帖子列表。
好消息是,我一次需要搜索的帖子永远不会超过 50-100 个。知道这一点,解决这个问题的最简单方法是我将帖子和 cmets 加载到内存中并通过循环搜索它们。
理想情况下,这样的解决方案是最快的:
class Post
{
public int Id;
public string Body;
public List<Comment> comments;
}
class Comment
{
public int Id;
public int ParentCommentId;
public int PostId;
public string Body;
}
public List<Post> allPosts;
public List<Comment> allComments;
public List<Post> postsToInclude (string SearchText)
{
var returnList = new List<Post>();
foreach(Post post in allPosts)
{
//check post.Body with bool isThisAMatch(SearchText, post.Body)
//if post.Body is a good fit, returnList.add(post);
}
foreach(Comment comment in allComments)
{
//check post.Body with bool isThisAMatch(SearchText, comment.Body)
//if comment.Body is a good fit, returnList.add(post where post.Id == comment.PostId);
}
}
public bool isThisAMatch(string SearchText, string TextToSearch)
{
//return yes or no if TextToSearch is a good match to SearchText
}
【问题讨论】:
标签: c# search full-text-search