lib/finapps/rest/documents_orders.rb in finapps-5.0.30 vs lib/finapps/rest/documents_orders.rb in finapps-5.0.31

- old
+ new

@@ -49,24 +49,37 @@ search_query(params[:searchTerm]).merge(consumer_query(params[:consumer])).merge(tag_query(params[:tag])) end def search_query(term) if term + query = with_space_search(term).concat(name_search(term)) { - "$or": [ - { "applicant.email": term }, - { "applicant.first_name": term }, - { "applicant.last_name": term }, - { - "reference_no": { - "$regex": "^#{term}", "$options": 'i' - } - } - ] + "$or": query } else {} end + end + + def name_search(term) + search_arr = [] + if term.match(/\s/) + term.split.each { |t| search_arr.append({ "applicant.first_name": t }, "applicant.last_name": t) } + end + search_arr + end + + def with_space_search(term) + [ + { "applicant.email": term }, + { "applicant.first_name": term }, + { "applicant.last_name": term }, + { + "reference_no": { + "$regex": "^#{term}", "$options": 'i' + } + } + ] end def tag_query(tag) if tag { "tag": tag.empty? ? nil : tag }