我成功地在基于文本的字段类型上启用突出显示,但不能用于非文本字段类型......
如何配置solr以突出显示非文本字段类型?我在网上找不到非文本字段的示例。它甚至可能吗?
具体来说,我想突出显示符合查询的文档中的日期值。
我正在使用solrJ来执行查询,这可能是限制因素吗?
答案 0 :(得分:2)
非“文字”字段无法突出显示。看看这个:
/**
* Returns a collection of the names of all stored fields which can be
* highlighted the index reader knows about.
*/
public Collection<String> getStoredHighlightFieldNames() {
if (storedHighlightFieldNames == null) {
storedHighlightFieldNames = new LinkedList<String>();
for (String fieldName : fieldNames) {
try {
SchemaField field = schema.getField(fieldName);
特别是在这里:
if (field.stored() &&
((field.getType() instanceof org.apache.solr.schema.TextField) ||
(field.getType() instanceof org.apache.solr.schema.StrField))) {
直到这里
storedHighlightFieldNames.add(fieldName);
}
} catch (RuntimeException e) { // getField() throws a SolrException, but it arrives as a RuntimeException
log.warn("Field \"" + fieldName + "\" found in index, but not defined in schema.");
}
}
}
return storedHighlightFieldNames;
}
答案 1 :(得分:0)
你不能按照解释的那样做。
但是,让Solr适应这一点非常简单。为您的日期创建另一个字段,但采用字符串格式。现在只需使用copyField:
<field name="date1" type="date" indexed="true" stored="true" />
<field name="date1_str" type="string" indexed="true" stored="true" />
<copyField source="date1" dest="date1_str"/>
然后只需将date1_str字段添加到您的查询中。