0
문제를 변경 때이 카테고리 이름을 업데이트하는 방법을 알아낼 수 없습니다 :가 나는 종류가 문서 모델에 매여면이 있지만 내가 카테고리 모델에서
- 언제 고토
category/edit/1
카테고리 이름을 변경하면 이전 이름이 여전히 내 패싯 출력에 나타납니다. - 새 카테고리를 만들 때 해당 카테고리 이름이 적어도 하나의 기사를 만들 때까지 내 articles.category 패싯에 표시되지 않습니다 (의미가 있지만 의도하지 않음). 내 기사에
categories
면을 사용하고 어떻게 다음class Category < ActiveRecord::Base include Tire::Model::Search include Tire::Model::Callbacks include ElasticSearch::RefreshIndex mapping do indexes :id, type: "integer", index: "not_analyzed", include_in_all: false indexes :name, type: "string", analyzer: "not_analyzed", boost: 50 indexes :description, type: "string", analyzer: "snowball" end has_many :articles, dependent: :destroy after_touch() { tire.update_index } end
가있다 : 여기에 분류 모델의 관련 비트의
class Article < ActiveRecord::Base include Tire::Model::Search include Tire::Model::Callbacks # This is just a custom module I made that does index.refresh on save/delete # to ensure that I'm getting a fresh view of the index on a page load. include ElasticSearch::RefreshIndex # Trimmed out a bunch of fields, but this should be enough to see what's going on. mapping do indexes :title, type: "string", analyzer: "snowball", boost: 10 indexes :category do indexes :id, type: "integer", index: "not_analyzed", include_in_all: false indexes :name, type: "string", index: "not_analyzed" end end belongs_to :category, touch: true def self.search() # Trimmed out a lot of code here, but this is just the facet. facet "categories" do terms "category.name", all_terms: true end end def to_indexed_json to_json(include: { category: { only: [:id, :name] } }) end end
:
다음은 관련 기사 모델의 비트입니다/색인보기 :
<% @articles.facets["categories"]["terms"].each do |facet| %>
<%= facet_item "checkbox", "category_name[]",
option_value: facet["term"],
option_text: facet["term"],
facet_count: facet["count"],
param: "category_name"
%>
<% end %>
facet_item
이하는 일에 대해 걱정할 필요가 없습니다. 이것은보기 상자, 레이블, 개수를 올바르게 렌더링하고 올바른 상태를 설정하는보기 도우미 일뿐입니다.
2 가지 문제를 해결하려면 무엇을해야합니까? 첫 번째 것은 나에게 가장 중요하지만 이상적으로는 두 가지를 모두 얻는 방법을 찾는 것이 좋습니다.
그래, karmi 너무 할 얘기거야. 카테고리를 업데이트 할 때마다 모든 기사를 일괄 적으로 가져옵니다. 그것은 문제 # 1을 해결하지만 # 2는 여전히 어떤 문제입니까? – AntelopeSalad
탄성 검색에 의존 할 수 없습니다. 데이터베이스에서 범주 목록을 가져온 다음 실제로 표시하려는 경우 Elasticsearch에 대해 쿼리 패싯을 실행하십시오. – concept47