module Auth::Search::Main

Public Class Methods

es_six_base_ngram_query(search_on_field,highlight_fields=nil) click to toggle source

this def, returns a hash with the structure for the basic ngram query. the query_string is left blank, and you should merge this in through any def that wants to perform an ngram query. param search_on_field : the field on which we are going to do the n_Gram query. Most of the times this should default to _all_fields @return

# File lib/auth/search/main.rb, line 8
def self.es_six_base_ngram_query(search_on_field,highlight_fields=nil)
        
        search_on_field ||= :tags
        highlight_fields ||= {
                fields: {
                        model_fields: {}
                }
        }

        qc = {
                body: {
                        query: {
                                bool: {
                                        must: {
                                                match: {
                                                        
                                                }
                                        },
                                        filter: {
                                                match_all:{

                                                }
                                        }
                                }
                        },
                        highlight: highlight_fields
                }
        }

        qc[:body][:query][:bool][:must][:match][search_on_field] = {
                        query: "",
                        operator: "and"
        }   

        qc

end
es_six_finalize_search_query_clause(args) click to toggle source

searches all indices, for the search string. @param : This is expected to contain the following: @query_string : the query supplied by the user @resource_id : a resource_id with which to filter search results, if its not provided, no filter is used on the search results @size : if not provided a default size of 20 is used this def will use the base_ngram_query hash and merge in a filter for the resource_id. 'Public' Resources

if the public field is present, don't add any resource_id filter.
if the public field is not present, then add the resource_id filter if the resource_id is provided.

@return : returns a query clause(hash)

# File lib/auth/search/main.rb, line 57
def self.es_six_finalize_search_query_clause(args)

        search_on_field = args[:search_field] || :tags
        
        args = args.deep_symbolize_keys
        
        return [] unless args[:query_string]
        
        query = es_six_base_ngram_query(search_on_field)
        
        query[:size] = args[:size] || 5
        
        query[:body][:query][:bool][:must][:match][search_on_field][:query] = args[:query_string]


        if args[:resource_id]
                ## if a resource id is provided, show all public records + those records which have this resource id as the owner.
                query[:body][:query][:bool][:filter] = {
                                
                                        bool: {
                                                should: [
                                                        {
                                                                bool: {
                                                                        must: [
                                                                                {
                                                                                        term: {
                                                                                                public: "no"
                                                                                        }
                                                                                },
                                                                                {
                                                                                        term: {
                                                                                                resource_id: args[:resource_id]
                                                                                        }
                                                                                }
                                                                        ]
                                                                }
                                                        },
                                                        {
                                                                term: {
                                                                        public: "yes"
                                                                }
                                                        }
                                                ]
                                        }
                                
                        }
        else
                ## if its not provided, and there is no admin in the args, then only show the public records.
                unless args[:resource_is_admin]
                        query[:body][:query][:bool][:filter] = {
                                bool: 
                                {
                                        must: [
                                                {
                                                        term: {
                                                                public: "yes"
                                                        }
                                                }
                                        ]
                                }
                        } 
                end
        end

        query

end