关于c#:sitecore搜索的基本用法 您所在的位置:网站首页 queryrunner的用法 关于c#:sitecore搜索的基本用法

关于c#:sitecore搜索的基本用法

2023-03-27 12:58| 来源: 网络整理| 查看: 265

我正在尝试设置一个非常基本的搜索索引,以索引特定文件夹中的所有项目。我并没有真正使用太多的搜索功能,但是我正在尝试使用开箱即用的功能,因为它的搜索非常简单。我只想索引所有字段。 sitecore文档确实并没有提供太多信息-我读过一些博客,而且它们似乎都暗示我需要高级数据库搜寻器(http://trac.sitecore.net/AdvancedDatabaseCrawler)-基本上,如果没有自定义的搜寻器,将无法正常运行)。

这是对的吗?我只想创建一个简单的索引,然后开始使用它。没有任何共享模块或其他方式的最简单方法是什么?我浏览了sitecore上的文档,但是(至少对我而言)不是很清楚。它在web.config中定义了索引配置的不同元素,但并没有真正解释它们的作用以及可用的值。也许我找不到合适的位置。.

相关讨论 如果您可以选择Sitecore 7,则此文档应会有所帮助。 请参阅我的帖子 @先生。我已经在Sitecore中包含了Lucene索引配置的说明以及用于从自定义索引中获取项目的工作代码。

在Sitecore中创建新Lucene索引的简单方法,只需3个步骤即可在特定节点下创建所有Lucene索引:

1:将以下配置添加到Sitecore配置中的configuration/sitecore/search/configuration/indexes:

1234567891011121314151617181920     $(id)     __my-custom-index                                 master             /sitecore/content/home/my/specific/folder      

2:重建新索引(仅一次,将自动检测所有进一步的更改):

1SearchManager.GetIndex("my-custom-index").Rebuild();

3:使用新索引:

12345678// use id of from the index configuration using (IndexSearchContext indexSearchContext = SearchManager.GetIndex("my-custom-index").CreateSearchContext()) {     // MatchAllDocsQuery will return everything. Use proper query from the link below     SearchHits hits = indexSearchContext.Search(new MatchAllDocsQuery(), int.MaxValue);     // Get Sitecore items from the results of the query     List items = hits.FetchResults(0, int.MaxValue).Select(result => result.GetObject()).Where(item => item != null).ToList(); }

此处是描述Sitecore搜索和索引的pdf文件。

这是有关解决Sitecore Lucene搜索和索引问题的博客文章。

这是Lucene查询语法教程

并介绍Lucene.Net

相关讨论 是的,遍历了该文档(如问题中所述)。这对我来说不是很清楚,因此是一个问题。

Sitecore Search Contrib(高级数据库搜寻器的新名称)是最好的选择,您只需在app config文件夹中配置其config即可告诉它启动路径数据库等。

然后,您可以使用其API在特定字段具有特定值的文件夹中按模板类型进行搜索。这是一个代码示例。

12345678910MultiFieldSearchParam parameters = new MultiFieldSearchParam(); parameters.Database ="web"; parameters.InnerCondition =  QueryOccurance.Should; parameters.FullTextQuery = searchTerm;         parameters.TemplateIds = array of pipe seperated ID's var refinements = Filters.Select(item => new MultiFieldSearchParam.Refinement(item.Value, item.Key.ToString())).ToList(); parameters.Refinements = refinements;

//实际搜索

12345var returnItems = new List(); var runner = new QueryRunner(IndexName); var skinnyItems = runner.GetItems(new[] {parameters}); skinnyItems.ForEach(x => returnItems.Add(Database.GetItem(new ItemUri(x.ItemID)))); return returnItems;

否则,您可以仅将web.config配置为标准lucene搜索,然后使用此代码进行搜索。 (使用" web"的数据库,开始项等)

123456789101112131415161718192021222324252627282930313233public Item[] Search(string searchterms)         {             var children = new List();             var searchIndx = SearchManager.GetIndex(IndexName);             using (var searchContext = searchIndx.CreateSearchContext())             {                 var ftQuery = new FullTextQuery(searchterms);                 var hits = searchContext.Search(ftQuery);                 var results = hits.FetchResults(0, hits.Length);                 foreach (SearchResult result in results)                 {                     if (result.GetObject() != null)                     {                         //Regular sitecore item returned                               var resultItem = result.GetObject();                         if (ParentItem == null)                         {                             children.Add(resultItem);                         }                         else if (resultItem.Publishing.IsPublishable(DateTime.Now, false) &&                                  ItemUtilities.IsDecendantOfItem(ParentItem, resultItem))                         {                             children.Add(resultItem);                         }                     }                 }             }             return children.ToArray();         }

然后,您可以为Sitecore下载Lucene Index Viewer扩展来查看索引,也可以下载Lucene Tool来查看索引。查看是否可以填充文档(索引中的文件)。这些在Lucene中称为"文档",从技术上讲,这些文档是您指定的节点下提供的内容项。

Brian Pedersen的帖子很不错。您将从一个简单的搜寻器开始。需要下载"高级数据库爬网程序",并在构建项目后将其添加到您的项目中。

然后,您必须创建Brian博客中提到的配置文件,并且必须按原样进行复制(模板ID为n all除外)。您基本上在这里明白了这一点。

然后,您可以为Sitecore下载Lucene Index Viewer扩展来查看索引,也可以下载Lucene Tool来查看索引。查看是否可以填充文档(索引中的文件)。这些在Lucene中称为"文档",从技术上讲,这些文档是您指定的节点下提供的内容项。

希望这会有所帮助!

让我用谷歌搜索一下。

相关讨论 不是我的不赞成,而是一些见解:Lucene索引查看器在Sitecore 6.5上不能很好地工作,因为Sitecore中Lucene.NET的本机实现中的版本不匹配已升级。至于对高级数据库爬网程序的需求,确实没有。 OP要求一种简单的实现,而利用Advanced Database Crawler则需要更多自定义和非常规的搜索索引方法-普通用户不需要它。



【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有