【问题标题】:getting dtsearch in sitecore to sort items by createdDate在 sitecore 中获取 dtsearch 以按 createdDate 对项目进行排序
【发布时间】:2013-10-09 17:41:59
【问题描述】:

dtSearch 的文档在这方面有点混乱。我试图让 dtSearch 返回的项目按创建日期的降序顺序返回(所以最新的在前)。现在,engine.Search 方法在返回的结果中似乎根本不包含有关日期的任何信息。

我知道在创建索引时需要使用高级选项来获取其中的日期字段,以便我可以按此排序,但我该怎么做?

我看到了这个:http://support.dtsearch.com/dts0150.htm 但我不确定在哪里或如何应用它。我没有文档中引用的演示,任何人都可以展示我如何将日期添加到索引中吗?

【问题讨论】:

  • 无论如何都不确定这个帮助,但我从来没有发现 dtSearch 特别好。如果您只想要基本搜索,或多或少无法配置它,它可以使用。但是让它工作并索引所有页面等我发现是一件麻烦事,只是不值得。如果可能,切换到其他东西,Lucene、Google 等。

标签: indexing sitecore dtsearch


【解决方案1】:

为了能够对这个(用于 dtSearch)自定义字段进行排序,您需要将带有创建日期的元标记添加到被 dtSearch 索引的页面。您可以获取 dtSearch 文档并检查其中的操作方式。

你的元标记看起来像这样:

<meta id="scDateCreated" name="scDateCreated" content="20100629" />

在 dtSearch 爬虫工具中,您可以指定该元标记(字段)应该被索引。在 dtSearch 索引此字段后,您可以使用此字段来按项目/页面的创建日期对搜索结果进行排序。请注意,如果您使用通配符设置(url 中的 /*)在通配符项目上显示来自不同数据源的项目,则必须从通配符上显示的项目获取创建日期,而不是 Sitecore.Context .项目。

按日期排序的示例代码:

ISearch engine = this.GetEngine();

        // Search with the given searchPhrase and the set SearchOptions
        engine.Search(searchPhrase, this.searchOptions);      

        // If there are searchResults return the searchResults formatted
        if (engine.SearchResults != null)
        {
            return this.FormatSearchResults(engine.SearchResults, engine, searchPhrase, templateId, publishedFrom, publishedTo, specifiedPath, sortOrder);
        }

这将得到你的结果。现在排序(this.FormatSearchResults):

// If a templateId was given
            if (templateId != string.Empty)
            {
                list = xmlResult.SelectNodes("/sitecore/result/item[scWebsitePath='" + sitecoreContextItemPath + "' and scTemplateId='" + templateId + "' and scDateCreated > '" + publishedFrom + "' and scDateCreated < '" + publishedTo + "']");
            }
            else
            {
                list = xmlResult.SelectNodes("/sitecore/result/item[scWebsitePath='" + sitecoreContextItemPath + "' and scDateCreated > '" + publishedFrom + "' and scDateCreated < '" + publishedTo + "']");
            }  

如您所见,元标记将出现在此搜索引擎将返回的 XML 中。您可以让自己的类能够将 dtSearchResult 转换为 List,然后使用 Linq 进行排序。

【讨论】:

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