Solr/SolrJ:如何突出显示非文本字段?

发布于 2024-11-24 02:26:49 字数 167 浏览 2 评论 0原文

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

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

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

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

I have been successful in enabling highlighting on Text based field types, but not for non-text field types...

How does one configure solr to highlight non-text field types? I cannot find a example on the web for non-text fields. Is it even possible?

Specifically I want to highlight the Date value in the document that meets the query.

I am using solrJ to peform the query, could it be the limiting factor?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

此刻的回忆 2024-12-01 02:26:49

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

/**
   * 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;
  }

Highlighting is not possible on non "text" fields. Look at this:

/**
   * 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);

Especially here:

          if (field.stored() &&
                  ((field.getType() instanceof org.apache.solr.schema.TextField) ||
                  (field.getType() instanceof org.apache.solr.schema.StrField))) {

until here

            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;
  }
踏雪无痕 2024-12-01 02:26:49

您不能按照所解释的那样执行此操作。

但让 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 添加到您的查询中。

You can't do this as was explained.

But it's super simple to adapt Solr to handle this. Create another field for your date but in string format. Now just use a 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"/>

Then just add the field date1_str to your query.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文