0

我以 java 对象的形式获得搜索请求,从中构造 SOLR 查询对象并查询索引。

例如,假设用户想要对名为 title 的字段进行精确搜索。他会发送表格查询

  Field = "title", value = "Algebra", Operator = "EQUALS"

当我看到运算符为“EQUALS”时,构造一个这样的 solr 查询

  title:Algebra

对于通配符或词干搜索,请求将是这样的,

  Field = "title", value = "Algebra", Operator = "LIKE"

由于运算符是“LIKE”我正在构建的 solr 查询是,

  title:*Algebra*

这里的问题是通配符和其他词干选项工作标题字段在我的 schema.xml 中定义为 text_general 和 text(通过复制字段选项),所以当我使用运算符“:”时,它会进行词干搜索并检索我的结果在标题字段中有代数词,我期望的输出只是标题为代数的记录。

我知道一种解决方案,我需要在配置文件中将标题字段更改为“字符串”。但这会影响我的词干搜索和通配符搜索选项。

所以基本上我想要一个字段支持词干搜索(和所有其他 text_general 字段选项)以及基于我传递给它的运算符的精确匹配。有没有可能。如果是这样,请指导我如何完成同样的事情。

4

1 回答 1

1

You'll have to have two fields, one for the stemmed / processed version, and one for the clean string version. Use <copyField> to make sure that both gets populated when indexing.

While there are no "global" conventions for this, I'd suggest adopting a naming convention for the field name depending on it's processing. If you have fieldname as string, you have fieldname_stemmed as the text field (or fieldname_text), if you see Operator = 'LIKE', append _stemmed or _text to the fieldname. You can also do it the other way around, have the regular fieldname be stemmed and processed, while you have fieldname_clean as the exact version.

于 2012-12-07T10:01:05.500 回答