Skip to content
This repository has been archived by the owner on Jun 30, 2018. It is now read-only.

empty array #966

Open
awaisilyastkxel opened this issue Jun 3, 2014 · 2 comments
Open

empty array #966

awaisilyastkxel opened this issue Jun 3, 2014 · 2 comments

Comments

@awaisilyastkxel
Copy link

I don't know the reason why it is returning an empty array of result. Looking forward a help from you guys.

class Post < ActiveRecord::Base
    include Tire::Model::Search
    include Tire::Model::Callbacks

    has_many :attachments, as: :attachable
    accepts_nested_attributes_for :attachments, allow_destroy: true

    mapping do
        indexes :work_type
        indexes :title
        indexes :location
        indexes :industry_type
        indexes :key_words
        indexes :type       
    end

    after_save { update_index }

    def self.search(params)
        tire.search(load: true) do
            query do
                boolean do
                    must   { string                              params[:query] }         if params[:query].present?
                    must   { match :type,          params[:type] }          if params[:type].present? && params[:type] != "all"
                    must   { match :title,         params[:title] }         if params[:title].present?
                    must   { match :industry_type, params[:industry_type] } if params[:industry_type].present?
                    must   { match :key_words,     params[:key_words] }     if params[:key_words].present?
                end
            end

            sort { by :title, 'desc' }
        end
    end

my params{} =>

{"utf8"=>"✓",
 "type"=>"Job",
 "query"=>"",
 "location"=>"",
 "post"=>{"work_type"=>"", "type"=>"Job"},
 "action"=>"index",
 "controller"=>"posts"}

Thanks

@awaisilyastkxel
Copy link
Author

I am searching on type and i have 100 of rows in database of type Job but i dont know its returning empty array :(

@Ashviniv
Copy link

@awaisilyastkxel check whether they are indexed properly by localhost:9200/index_name/_search?v in the browser. Because I was facing the same problem but with the different query. Solved by indexing all of them.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants