2012-08-07 1 views
2

Player와 Player의 프로필 이름은 full입니다. Player에서 elasticsearch를 사용합니다. fullname으로 기본 정렬이 필요합니다. 어떻게 설정할 수 있습니까? 플레이어의 클래스 파일에서 내 코드 :RoR : Elasticsearch 매핑 된 필드로 분류

...... 
    mapping do 
    indexes :id, type: 'integer' 
    indexes :fullname, boost: 10 
    indexes :name 
    indexes :surname 
    indexes :position_name 
    indexes :info 
    indexes :club_id, type: 'integer' 
    indexes :club_name 
    end 

    def self.search(params) 
    tire.search(load: true, page: params[:page], per_page: 20) do 
     query do 
     boolean do 
      if params[:query].present? 
      must { string params[:query], default_operator: "AND" } 
      else 
      must {string '*'} 
      end 
      must { term :position_id, params[:position_id]} if params[:position_id].present? 
      must { term :club_id, params[:club_id]} if params[:club_id].present? 
     end 
     end 
     # filter :term, user_id: params[:user_id] if params[:user_id].present? 
     # sort { by Item.column_names.include?(params[:sort]) ? params[:sort] : "created_at", %w[asc desc].include?(params[:direction]) ? params[:direction] : "desc" } if params[:query].blank? 

     sort { by Player.column_names.include?(params[:sort]) ? params[:sort] : :id ,%w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"} 
     facet "positions" do 
     terms :position_id 
     end 
     facet "clubs" do 
     terms :club_id 
     end 
     # raise to_curl 
    end 
    end 

    def to_indexed_json 
    to_json(methods: [:fullname, :name, :surname, :position_name, :club_name]) 
    end 

    def fullname 
     self.profil.fullname 
    end 
...... 

내가 변경 한 경우 : 이드 :

500 : {"error":"SearchPhaseExecutionException[Failed to execute phase [query], total failure; shardFailures {[DBgvi6JiQAi0FTwhonq8Ag][players][0]: QueryPhaseExecutionException[[players][0]: query[ConstantScore(NotDeleted(cache(_type:player)))],from[0],size[20],sort[<custom:\"fullname\": o[email protected]33a626ac>!]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field]; }{[DBgvi6JiQAi0FTwhonq8Ag][players][4]: QueryPhaseExecutionException[[players][4]: query[ConstantScore(NotDeleted(cache(_type:player)))],from[0],size[20],sort[<custom:\"fullname\": o[email protected]3274eb8a>!]: Query Failed [Failed to execute main query]]; nested: IOException[Can't sort on string types with more than one value per doc, or more than one token per field]; }]","status":500} 
+0

이 업데이트는 무엇입니까? –

+0

죄송합니다. jQuery 정렬을 사용합니다. 그러나 좋은 해결책이 아닙니다. – quatermain

답변

7

알았습니다. 어리석은 양의 연구 후에 나는 this article here을 발견했다.

mapping do 
    indexes :id, type: 'integer' 
    indexes :fullname, :index => 'not_analyzed' 
    indexes :name 
    indexes :surname 
    indexes :position_name 
    indexes :info 
    indexes :club_id, type: 'integer' 
    indexes :club_name 
    end 

그리고 그것은 작동합니다 : 당신이해야 할 모든입니다, 당신의 상황에서

The field user by default gets analyzed and broken down into one or more tokens. If it gets broken down into more than one token, then you can't really sort on it. If you want to sort on it, you either need to set it i(in the mappings) as not analyzed

: 첫 번째 대답은 언급하고있다.

+1

완벽하게 작동합니다. – quatermain

0
sort { by Player.column_names.include?(params[:sort]) ? params[:sort] : :fullname ,%w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"} 

작동합니다 '전체 이름'에서 'ID를'변경 : 일종의 전체 이름 난이 오류가 있습니다.

+0

아니요, 오류, 내 게시물에 추가합니다. – quatermain