我是Elasticsearch和NEST世界的新人。我对以下查询感到困惑:
Article对象由Elasticsearch
编制索引public class Article
{
public Guid Id { get; set; }
public string Title { get; set; }
public DateTime PublishDate { get; set; }
public string Body { get; set; }
public string Author { get; set;
public List<Category> Categories { get; set; }
}
public class Category
{
public int Id {get;set;}
public string Title {get;set;}
}
用户可以按3个字段搜索文章
有人可以帮我写一个会返回所有文章的查询 其中Article.Author包含 Bob 和Article.Body至少有一个单词 book 的实例,并且具有类别5或7
EF查询如下所示:
var query = _unitOfWork.ArticleRepository.GetAll();
if (!Strin.IsEmptyOrNull(model.SearchParameters.Keyword))
{
query = query.Where(a => a.Title.Contains(model.SearchParameters.Keyword))
}
if (model.SearchParameters.SelectedCategory.Count > 0)
{
query = query.Where(b => b.ArticleCategory.Where(t => model.SearchParameters.SelectedCategory.Contains(t.CategoryId)).Any());
}
if (!Strin.IsEmptyOrNull(model.SearchParameters.Author))
{
query = query.Where(a => a.Author.Contains(model.SearchParameters.Author))
}