From: Ruby Geo Date: 2007-12-19T20:45:51+09:00 Subject: Partial Search I have created this method but I want to improve to be ale to search based on the keywords partially. def self.search_by_keyword(businesses, searched_keyword) businesses.select do |b| b.my_keywords.include?(searched_keyword) end end ----------------------------------------------------------------------------- This are the objects ----------------------------------------------------------------------------- bsn0 = Business.new("Romain", "02089293323", "22 lilly Road ") bsn0.add_keyword(KEYWORDS[0]) bsn0.add_keyword(KEYWORDS[1]) bsn0.add_keyword(KEYWORDS[2]) bsn1 = Business.new("Steve", "02089293323", "22 lilly Road ") bsn1.add_keyword(KEYWORDS[0]) bsn1.add_keyword(KEYWORDS[2]) bsn2 = Business.new("Al ", "02085431234", "25 Riverside Road ") bsn2.add_keyword(KEYWORDS[1]) -------------------------------------------------------------------------- How can I change the methpd in orrder to be able to perform the folowing task ? -------------------------------------------------------------------------- Business.search_by_keyword([bsn0, bsn1, bsn2], KEYWORDS[3],true) # true here mean 'exact match' # will return nil Business.search_by_keyword([bsn0, bsn1, bsn2], KEYWORDS[1],true) # true here mean 'exact match' # will return bsn2 Business.search_by_keyword([bsn0, bsn1, bsn2], KEYWORDS[1],false) # true here mean 'partial match' # will return bsn0 AND bsn2 Business.search_by_keyword([bsn0, bsn1, bsn2], [KEYWORDS[0],KEYWORDS[1] ],true) # true here mean 'exact match' # will return nil Business.search_by_keyword([bsn0, bsn1, bsn2], [KEYWORDS[0],KEYWORDS[2] ],true) # true here mean 'exact match' # will return bsn1 Business.search_by_keyword([bsn0, bsn1, bsn2], [KEYWORDS[0],KEYWORDS[2] ],false) # true here mean 'partial match' # will return bsn0 AND bsn1 -- Posted via http://www.ruby-forum.com/.