0

我有一个嵌套字段形式为的 solr 索引

{ record: [
    { tag1: foo, tag2: bar }
  ]
}

遗憾的是,solr 配置无法更改。

在 Blacklight 中,我想在不同的字段下分别显示foo和显示,如下所示:bar

Tag1: foo
Tag2: bar

我在想我可以使用 config.add_index_field 和辅助方法来实现这一点:

catalog_controller.rb
config.add_index_field 'record', label: 'Tag1', helper_method: :get_tag1
config.add_index_field 'record', label: 'Tag2', helper_method: :get_tag2
application_helper.rb
  def get_tag1(options={})
    options[:value][0]['tag1']
  end
  def get_tag2(options={})
    options[:value][0]['tag2']
  end

但是,这样做时我收到错误A index_field with the key record already exists.

显然,我一次只能为每个 solr 字段添加一个索引字段。如何在 Blacklight 中将一个这样的字段变成多个字段?

4

1 回答 1

1

找到了答案。我只需要添加字段变量以指向同一个标签,这样我就可以更改原始变量。

catalog_controller.rb
config.add_index_field 'record1', label: 'Tag1', field: 'record', helper_method: :get_tag1
config.add_index_field 'record2', label: 'Tag2', field: 'record', helper_method: :get_tag2
于 2019-10-23T11:09:49.017 回答