Partial Search

R

Ruby Geo

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
 
R

Ruby Geo

Well I changed the method, so that it can take the three parameters.

And my question would be How can I modify the ruby block code so that I
can do the perform the matching.



def self.search_by_keyword(businesses, searched_keyword_as_array,
flag_exact_or_partial_match)
businesses.select do |b|
b.my_keywords.include?(searched_keyword)
end
end
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Printing result of class method 1
Search Array 0
method use ? 1
Refactor into a class method. 1
Checking results 0
Crawling 1
Partial Search 0
several replacing problems 4

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,099
Latest member
AmbrosePri
Top