Sitecore:用于搜索GUID的ADC全文查询

时间:2013-03-06 11:18:08

标签: sitecore sitecore6

SearchParam searchParam = new SearchParam();
        searchParam.Database = Fields.Database;
        searchParam.Language = Fields.Language;
        searchParam.TemplateIds = templateID;
        if (txtQuery != null && !string.IsNullOrEmpty(txtQuery))
            searchParam.FullTextQuery = txtQuery;
        QueryRunner runner = new QueryRunner("Web");
        IEnumerable<SkinnyItem> items = runner.GetItems(searchParam, sc.Search.QueryOccurance.Should, false, "", true, 0, 500);

我想搜索包含某些GUID的字段,是否可能? 我试过了,但它返回0的结果,我确信会有结果。 我错过了什么或者我是否需要格式化GUID格式? 这是我使用的格式“{xxx-xxx-xxx-xxxx}”

5 个答案:

答案 0 :(得分:1)

确保您的索引设置正确,以包含您要搜索的字段以及您使用的是正确的查询语法。 有关如何配置索引以及如何进行简单和高级搜索,请参阅this page

还尝试使用硬编码查询,以确保您没有在某处使用错误的值或格式错误。

答案 1 :(得分:1)

你的问题不清楚所以我将在这里解释。您说您想要对GUID进行全文搜索。这些当然是两件事。我假设你有一个GUID,并希望找到索引中通过某些(任何?)字段分配GUID的所有项目。您需要使用RelatedIdscode here)的SearchParam属性:

以下是一些示例代码:

var searchParam = new SearchParam
{
  Database = Sitecore.Context.Database.Name,
  Language = Sitecore.Context.Language.Name,
  RelatedIds = {YOUR GUID HERE}
};

using (var runner = new QueryRunner(indexName))
{
  return runner.GetItems(searchParam);
}

此外,如果您有多个GUID,则可以对它们进行管道分隔,例如RelatedIds = {GUID1}|{GUID2}

答案 2 :(得分:0)

查看索引中的内容,您可以检查使用Sitecore Rocks存储的字段值 - &gt;

右键单击您的站点,管理,索引,{您的索引}。

检查其中一个guid字段,看看那里有什么。

我认为它们的存储没有大括号,连字符和小写,你只需要在传入之前格式化guid。

答案 3 :(得分:0)

如果要搜索字段值,则应使用FieldSearchParam而不是SearchParam。以下是示例代码:

    var searchParam = new FieldSearchParam
        {
            Database = Sitecore.Context.Database.Name,
            Language = Sitecore.Context.Language.Name,
            TemplateIds = DealerTemplateId,
            FieldName = <FieldName>,
            FieldValue = <FieldValue>
        };

        QueryRunner runner = new QueryRunner("Web");
    IEnumerable<SkinnyItem> items = runner.GetItems(searchParam);

此FieldSearchParam是从"Sitecore.SharedSource.Searcher"库中的SearchParam扩展而来的。这在开源中,您可以在项目中添加引用或获取代码。

这里要注意的一点是FieldValue的格式,你的字段值应该都很小而没有“ - ”,所以如果你的GUID是“{A9294EF5-0E36-4616-A77E-B7B100057EBA}”那么你应该通过“”a9294ef50e364616a77eb7b100057eba“即没有”{}“,所有字符都应该小。 试试这个,因为这对我有用。

注意:请确保您已根据@martijn

中的建议检查了配置

答案 4 :(得分:0)

对我有用的是:

    <configuration xmlns:patch="http://www.sitecore.net/xmlconfig/">
  <sitecore>
    <databases>
      <database id="master" singleInstance="true" type="Sitecore.Data.Database, Sitecore.Kernel">
        <Engines.HistoryEngine.Storage>
          <obj type="Sitecore.Data.$(database).$(database)HistoryStorage, Sitecore.Kernel">
            <param connectionStringName="$(id)" />
            <EntryLifeTime>30.00:00:00</EntryLifeTime>
          </obj>
        </Engines.HistoryEngine.Storage>
        <Engines.HistoryEngine.SaveDotNetCallStack>false</Engines.HistoryEngine.SaveDotNetCallStack>
      </database>
    </databases>
    <search>
      <configuration>
        <indexes>
          <index id="newsArticles" type="Sitecore.Search.Index, Sitecore.Kernel">
            <param desc="name">$(id)</param>
            <param desc="folder">newsArticle</param>
            <Analyzer ref="search/analyzer" />
            <locations hint="list:AddCrawler">
              <master type="Sitecore.SharedSource.SearchCrawler.Crawlers.AdvancedDatabaseCrawler,Sitecore.SharedSource.SearchCrawler">
                <Database>master</Database>
                <Root>/sitecore/content/Data</Root>
                <IndexAllFields>true</IndexAllFields>
                <MonitorChanges>true</MonitorChanges>
                <include hint="list:IncludeTemplate">
                  <News>{EF11A8D0-D373-4A4B-90BA-16984D277612}</News>
                </include>

现在我已经包含了我需要搜索索引的模板ID。当我构建时,我可以看到包含此​​特定模板ID的项目存在。

现在搜索:

try
        {
            List<Item> items = new List<Item>();
            Sitecore.Search.Index indx = SearchManager.GetIndex("newsArticles");
            using (IndexSearchContext searchContext = indx.CreateSearchContext())
            {
                var db = Sitecore.Context.Database;
                CombinedQuery query = new CombinedQuery();

                QueryBase catQuery = new FieldQuery("category", GuidsToSearchFor); //FieldName, FieldValue.
                SearchHits results = searchContext.Search(catQuery); //Searching the content items by fields.

                SearchResultCollection result = results.FetchResults(0, numOfArticles);
                RetrieveUrlListings(myItems, db, result, true);
            }
        }

您的结果将包含索引查看器中存在的项目列表。

希望这有帮助!查看此link了解更多信息。