在使用 Lucene 进行搜索时,我们能否在 templateId 中分配多个模板 ID(就像我们在 relatedId 中所做的那样)? [英] Can we assign more then one template ID in templateId (like we do in relatedId), while searching with Lucene?

查看:26
本文介绍了在使用 Lucene 进行搜索时,我们能否在 templateId 中分配多个模板 ID(就像我们在 relatedId 中所做的那样)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有五个复选框

  • 搜索全部
  • 模板 1
  • 模板 2
  • 模板 3
  • 模板 4

如果用户选择 Search All,那么我们可以简单地传递索引名称并获取结果,如果用户选择模板特定复选框之一,我们同样可以通过传递模板名称来完成,但如果有的话两个模板特定的复选框(或者可能是三个)被选中,然后?

If user selects Search All, then simply we can pass index name and get result, if user selects one of template specific check box, again simply we can do by passing template name, but if any of two templates specific check box(or may be three) are checked, then?

我们可以用管道分隔模板ID吗?

Can we pipe-separate templateIDs?

推荐答案

您可能需要更改 Advanced Database Crawler 中的方法来处理传入的模板的 GUID.SearchParam 类有一个名为 TemplateIds 的属性是复数表示它应该允许多个.但是,如果您查看代码,这就是它的使用方式:

You may need to change the method in the Advanced Database Crawler to handle the GUIDs of templates passed in. The SearchParam class has a property called TemplateIds which by being plural indicates it should allow more than one. However, if you look into the code, this is how it is used:

templateIds = IdHelper.NormalizeGuid(templateIds);

NormalizeGuid() 方法实际上是 只返回一个 GUID.所以我建议您在这里更改 ApplyTemplateFilter() 方法以返回多个模板 GUID:

The NormalizeGuid() method actually only returns a single GUID. So I recommend you alter the ApplyTemplateFilter() method here to return multiple Template GUIDs:

protected void ApplyTemplateFilter(CombinedQuery query, string templateIds, QueryOccurance occurance)
{
  if (String.IsNullOrEmpty(templateIds)) return;

  templateIds = IdHelper.NormalizeGuid(templateIds);
  var fieldQuery = new FieldQuery(BuiltinFields.Template, templateIds);
  query.Add(fieldQuery, occurance);
}

所以更改 templateIds = IdHelper.NormalizeGuid(templateIds) 以处理多个 GUID,也许通过在 | 处拆分输入以获取每个 GUID,然后对其中的每一个进行规范化并通过 | 再次组合它们.

So change templateIds = IdHelper.NormalizeGuid(templateIds) to handle multiple GUIDs, perhaps by splitting the input at a | to get each GUID then normalizing each one of those and combining them again via a |.

这篇关于在使用 Lucene 进行搜索时,我们能否在 templateId 中分配多个模板 ID(就像我们在 relatedId 中所做的那样)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆