【问题标题】:sitecore How to search once we have lucene indexsitecore 一旦我们有 lucene 索引如何搜索
【发布时间】:2015-10-09 21:50:35
【问题描述】:

在从 Internet 搜索和阅读大量内容后,我设法使用 Lucene 创建了一个索引。我的索引名称是:my_text_index。我使用了 Luke,我可以看到现在创建了索引,其中包含一些数据(项目的标题)。

现在我完全不知道如何使用此索引使用 Sitecore API 进行搜索。

如果你能为像我这样的初学者写一些关于“如何从 Sitecore 中的索引进行搜索”的步骤,那将是非常好的。

谢谢!

【问题讨论】:

    标签: sitecore sitecore7 sitecore7.2


    【解决方案1】:

    互联网上有很多关于 Sitecore 搜索的教程和指南。它在 Sitecore 7 和 Sitecore 8 中非常相似,因此您可以同时使用它们。

    您首先应该检查的是 Sitecore 文档:Developer's Guide to Item Buckets and Search(对我来说最有趣的部分从第 5.3 章开始)。

    在快捷方式中,为您的项目创建一个类(它可以从 Sitecore SearchResultItem 类继承,但如果您想自己处理标准 Sitecore 字段则不需要),例如:

    public class Person : SearchResultItem
    {
        [IndexField("firstname_t")]
        public string Firstname { get; set; }
        [IndexField("surname_t")]
        public string Surname { get; set; }
    }
    

    并使用类似的代码来获得结果:

    using (var context = ContentSearchManager.GetIndex("my_text_index").CreateSearchContext())
    {
         IQueryable<Person> query = context.GetQueryable<Person>().Where(p=> p.Firstname.Equals("John"));
    }
    

    就是这样。您无需其他任何东西即可开始将 Sitecore Search API 与 Sitecore 7 一起使用。

    这是一个非常好的"Sitecore 7 Search - a quickstart guide" article

    【讨论】:

    • 我要补充的是,还有值得一看的谓词构建器(取决于您的 Sitecore 版本)。如果你要做很多 where(X=>X.somevalue == "") 等 :)
    • @CharlieAfford 完全同意。我链接的文章中描述了PredicateBuilder
    【解决方案2】:

    我有一个非常详细的步骤,从创建和索引到查询索引的结果。

    http://mrstevenzhao.blogspot.com/2014/04/sitecore-set-up-new-lucene-index-and.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-01
      • 1970-01-01
      • 2012-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多