I am trying to make a command like !find England Michanel to return list of people with a name Michael whose live in England.
let [country, name] = input.split(" ").slice(1);
This gives me exact data I want. But the problem is when the county name is more than one word like United States and also for person names like John Doe. If I apply my current logic will be like; country = United, name = States and will ignore the rest after that.
Is ther any way to retrieve country name person name with spaces correctly? Thanks
3 Answers 3
I assume you fetch your data from some kind of database? Ok, using a lot of assumption here:
1) You can simply NOT use the space as a separator (don't know if you have that option)
2) Moment you fetch your data, replace the space with e.a. '~'. ("United~States"). After you split and assign "United~States" to the array, replace the "~" again (or just search incl. ~)
Comments
I you really want to support this and you dont mind extra latency:
Try all three:
!find United States John Doe:
Anyone called "Doe" in the country "United States John"
Anyone called "John Doe" in "United States" and
Anyone called "States John Doe" in "United"
Its extra work but answers the question.
Comments
Assuming that you can make minor adjustments to the commands.
To me the best way is to simply use flags and then apply regular expressions to get the full input after the flag.
Example !find -c United States -p Jonh Doe
All you have to do is use a regular expression to extract the values from -c until another flag, and basically the same for the name.
united-states) or underscores (united_states). Beyond that, you'll either have to do some kind of fuzzy searching, or rely on a search provider like Solr.inputlook like? do you have control over it? please give an example ofinput"country name"why are you using.slice(1)and why are you using!before your command/function name?