【问题标题】:Modifying the resulting columns of an elasticsearch query修改弹性搜索查询的结果列
【发布时间】:2017-10-22 16:28:13
【问题描述】:

所以我接手了一个更大的项目,但不确定在哪里可以找到修改它的代码。我们有一个数据库,它被读取为 Essay -> Section -> figure,我们正在尝试添加一个名为“video_url”的新列。我相信这与非规范化有关,但我不完全确定。

这是论文模型:

class Essay
  include ActiveModel::Model
  include ActiveModel::Serialization
  include Draper::Decoratable
  include Import::HtmlEssay
  include Searchable

  FACETS = %w(author)
  FULLTEXT_FIELDS = %w(title sections.title sections.body sections.figures.caption)

  def self.define_mappings!
    mapping mapping_options do
      analyzer = I18n.locale == :tr ? :turkish : :snowball

      indexes :author, index: :not_analyzed
      indexes :publication_id, index: :not_analyzed
      indexes :sequence, type: 'long'
      indexes :title, analyzer: analyzer
      indexes :sections do
        indexes :title, analyzer: analyzer
        indexes :body, analyzer: analyzer
        indexes :figures do
          indexes :caption, analyzer: analyzer
        end
      end
    end
  end

  class Query
    include Searchable::Query

     def sort
       [
         { publication_id: { order: 'asc'}},
         { sequence: { order: 'asc' }}
       ]
     end
  end
end

现在它只显示 [Mash caption, credit, figure(#), url]。我想将 video_url 附加到 Image 模型的一部分(我们从中提取 url),但是我不确定它是如何工作的并且遇到了麻烦。我认为他们正在使用的唯一相关 gem 是 elasticsearch-model,但是我已经浏览了他们的一堆东西,但仍然不确定。

控制也是如此(虽然这里没有真正发生)如下:

class EssaysController < SearchBaseController
  def show
    @essay = Essay.find(params[:id]).decorate
  end
end

老实说,即使您不知道答案,如果您能告诉我“FULLTEXT_FIELDS”var 之类的内容来自哪里,那将非常有帮助,如果需要,我可以编辑它以添加其他代码部分.我真的需要弄清楚如何将 video_url 列添加到结果中,它在 elasticsearch 中,可以通过其他方法访问,但这里没有显示。

【问题讨论】:

    标签: ruby-on-rails elasticsearch elasticsearch-model


    【解决方案1】:

    所以我最终发现 /models/concerns/import/* 内还有另一个文件夹,其中包含有关数据库设置的更多信息。我不确定他们使用的是什么宝石/为什么会这样设置,但我会在了解更多信息时更新这个答案。

    【讨论】:

      猜你喜欢
      • 2021-02-10
      • 1970-01-01
      • 2021-07-12
      • 2020-06-15
      • 1970-01-01
      • 2015-06-21
      • 2019-07-20
      • 2020-06-05
      • 2016-07-21
      相关资源
      最近更新 更多