1

我已成功启用基于文本的字段类型的突出显示,但不适用于非文本字段类型...

如何配置 solr 以突出显示非文本字段类型?我在网上找不到非文本字段的示例。甚至可能吗?

具体来说,我想突出显示满足查询的文档中的 Date 值。

我正在使用 solrJ 执行查询,这可能是限制因素吗?

4

2 回答 2

3

在非“文本”字段上无法突出显示。看这个:

/**
   * 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;
  }
于 2011-07-14T08:07:36.033 回答
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 添加到您的查询中。

于 2012-02-16T17:50:30.033 回答