2017-12-27 28 views
1

레일의 경우 검색 용으로 searchkick 보석을 사용하고 있습니다. 필터에 대해 status이라는 문자열 필드 하나를 추가해야합니다. 이 플러그인에 어떻게 추가 할 수 있습니까?Rails - searchkick에서 문자열 필드를 필터링하는 방법은 무엇입니까?

이미 나는

Rails - How to add more fields for filter in searchkick? 지금 난 여전히 작동하지 않는 검색 문자열 필드 대신 부울 함께 노력하고이 문제에 대한 하나 개의 질문을 제기했다. 제발 도와주세요.

where: {status: 'approved'}과 같은 조건을 추가 했으므로이 조건에 따라 활성 사용자 ('삭제 된 사용자'가 아님) 만 가져와야합니다. 현재 검색 데이터가 표시되지 않습니다. 또한 내가 searchkick word_start: [:name], filterable: [:status]

서버 로그와 같은 필터링 추가하여 시도

searchkick word_start: [:name] 

def initialize(name, limit = User::SUGGESTION_LIMIT, page = nil) 
    @name = name 
    @limit = limit 
    @page = page 
    @per_page = limit.to_i 
end 

query = { 
    match: :word_start, 
    where: {status: 'approved'}, 
    fields: [{ emails: "exact" }, "name^5"], 
    misspellings: { prefix_length: 2 }, 
    load: false 
} 

User.search(name, query).records 

, 당신의 조건에 따라,

Processing by UsersController#search as JSON 
Parameters: {"query"=>"sal"} 
ETHON: Libcurl initialized 
ETHON: performed EASY 
effective_url=http://elastic:[email protected]:9200/users-some_index-en/_search response_code=200 return_code=ok total_time=0.498938 
User Search (589.3ms) curl http://14.127.18.141:9200/users-some_index-en/_search?pretty -d '{"query":{"bool":{"must":{"dis_max":{"queries":[{"match":{"emails.true":{"query":"sal","boost":10,"operator":"and","analyzer":"searchkick_autocomplete_search"}}},{"match":{"emails.true":{"query":"sal","boost":1,"operator":"and","analyzer":"searchkick_autocomplete_search","fuzziness":1,"prefix_length":2,"max_expansions":3,"fuzzy_transpositions":true}}},{"bool":{"must":{"bool":{"should":[{"match":{"name.word_start":{"query":"sal","boost":50.0,"operator":"and","analyzer":"searchkick_word_search"}}},{"match":{"name.word_start":{"query":"sal","boost":5.0,"operator":"and","analyzer":"searchkick_word_search","fuzziness":1,"prefix_length":2,"max_expansions":3,"fuzzy_transpositions":true}}}]}},"should":{"match":{"name.analyzed":{"query":"sal","boost":50.0,"operator":"and","analyzer":"searchkick_word_search"}}}}}]}},"filter":[{"term":{"status":"approved"}}]}},"size":5,"from":0,"timeout":"11s"}' 
User Load (0.8ms) SELECT "users".* FROM "users" WHERE "users"."id" = $1 LIMIT $2 [["id", 1], ["LIMIT", 1]] 
ETHON: performed EASY effective_url=http://elastic:[email protected]:9200/entities-some_index-en/_search response_code=200 return_code=ok total_time=0.251783 
+0

추가 한 코드 스 니펫으로는 사용자가하려는 것을 이해하기에 충분하지 않습니다. 더 많은 코드를 추가하십시오. –

+0

질문이 업데이트되었습니다. –

답변

1

변경 scope :search_import과 같은 should_index? 방법을 수정

def should_index? 
    User.search_import 
end 

이 값이 변경되면 rei를 호출하십시오. ndex 별도로 after_update 모든 데이터 중