Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Just an approach (there are many ways to do this I think): split your <code>String</code> in a <code>String[]</code> and process each word as you need:</p> <pre><code>String str = "Find me a christian male 28 years old from Brazil"; for(String s : str.split(" ")){ //splits your String using space char processWord(s); } </code></pre> <p>Where <code>processWord(s)</code> should do something to determine if <code>s</code> is or not a key word based on your business rules.</p> <p><strong>EDIT:</strong> Well, as many people consider this answer insufficient I'll add some more tips.</p> <p>Let's say you have a class in which you put some search criteria (assuming you want to get people that match these criteria):</p> <pre><code>public class SearchCriteria { public void setGender(String gender){...} public void setCountry(String country){...} public void setReligion(String religion){...} ... public void setWatheverYouThinkIsImportant(String str){...} } </code></pre> <p>As @Sotirios pointed in his comment, you may need a pool of matching words. Let's say you can use <code>List&lt;String&gt;</code> with basic matching words:</p> <pre><code>List&lt;String&gt; gender = Arrays.asList(new String[]{"MALE","FEMALE","BOY","GIRL"...}); List&lt;String&gt; country = Arrays.asList(new String[]{"ALGERIA","ARGENTINA","AUSTRIA"...}); List&lt;String&gt; religion = Arrays.asList(new String[]{"CHRISTIAN","JEWISH","MUSLIM"...}); </code></pre> <p>Now I'll modify <code>processWord(s)</code> a little (assuming this method has access to lists above):</p> <pre><code>public void processWord(String word, SearchCriteria sc){ if(gender.contains(word.toUpperCase()){ sc.setGender(word.toUpperCase()); return; } if(country.contains(word.toUpperCase()){ sc.setCountry(word.toUpperCase()); return; } if(religion.contains(word.toUpperCase()){ sc.setReligion(word.toUpperCase()); return; } .... } </code></pre> <p>Finally you need to process user's input:</p> <pre><code>String usersInput = "Find me a christian girl 28 years old from Brazil"; //sorry I change "male" for "girl" but I like girls :P SearchCriteria sc = new SearchCriteria(); for(String word : usersInput.split(" "){ processWord(word, sc); } // do something with your SearchCriteria object </code></pre> <p>Sure you can do this so much better. This is only an approach. If you want to do the search more accurate take a read about Levenshtein's distance. It will help you for example if somebody puts "Brasil" instead "Brazil" or "cristian" instead "christian".</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload