title: Android Search with Multiple words
body: <p>I have to implement the multiple search query, how to achieve it , I know the basic idea of filtering the text with the search view but not getting the idea how to search with multiple string ,I am attaching the snapshot show it will make you feel better to get an idea.</p>
  
  <p>I am loading the data from the webserver.<a href="https://i.stack.imgur.com/yZAyU.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/yZAyU.jpg" alt="Click Here to see"></a></p>
  
  <p>TruckInfo columns are:</p>
  
  <ul>
  <li>Name of the truck</li>
  <li>Total capacity (is the capacity of the truck)</li>
  <li>Status Free/Busy (is the status of the truck which is currently all truck is free)</li>
  <li>Free location (is the where truck is going to free).</li>
  </ul>
  
  <p><a href="https://i.stack.imgur.com/el8NL.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/el8NL.jpg" alt="Here is search implementation i have to do"></a></p>
  
  <p>Now as in snapshot second i have to filter this data , I had searched in the capacity column --> 10 tonnes to 45 tonnes, status is--> free , free location is -->CV , from 7wed2016 to 20 Fri 2016 and then i hit search button .</p>
  
  <p>Expected output should not show any result because:</p>
  
  <ol>
  <li>10 tonnes to 45 tonnes there is 2 truck ..which is right. as data coming from server</li>
  <li>status of both the truck is free, which is right</li>
  <li>Free location is CV that I searched, but as you can see both truck have free location mumbais, chandigarh, so this condition is false so overall search should show no data</li>
  </ol>
  
  <p>My Try:</p>
  
  <pre><code>filter_search.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
  
                  Log.e("filter_search","filter_search");
                  Localytics.tagEvent("Trucks Search Screen");
                  if(frmcap.getText().toString().length()==0){
                      frmcap_val=0;
                      cap_bool=1;
                  }
                  else
                  {
                      frmcap_val=Integer.parseInt(frmcap.getText().toString());
                      cap_bool=0;
                  }
                  if(tocap.getText().toString().length()==0) {
                      tocap_val=0;
                      cap_bool = 1;
                  }
                  else {
                      tocap_val=Integer.parseInt(tocap.getText().toString());
                      cap_bool=0;
                  }
                  if(from_loc_text.getText().length()==0)
                      loc_bool=1;
                  else
                      loc_bool=0;
  
                  if(frm_date_value.length()==0 || to_date_value.length()==0)
                      date_bool=1;
                  else
                      date_bool=0;
  
                  if(free.isChecked())
                      status_value="true";
                  if(busy.isChecked())
                      status_value="false";
                  if(any.isChecked())
                      status_value="any";
                  if(!any.isChecked()&amp;&amp;!free.isChecked()&amp;&amp;!busy.isChecked()){
                      Log.e("@@inside","inside");
                      status_value="-default value";
                  }
  
  
                  if(!any.isChecked()&amp;&amp;!free.isChecked()&amp;&amp;!busy.isChecked())
                      status_bool=1;
  
                  if(search.getText().length()==0)
                      loc_search_info=1;
                  else
                      loc_search_info=0;
  
                  try {
                      if(status_value!=null &amp;&amp; status_value.length()&gt;0 &amp;&amp; !status_value.equalsIgnoreCase("any")){
                          truckadapter.advanceSearchFilter(status_value,"checkBox");
                          list_mytrucks.setVisibility(View.VISIBLE);
  
                      }else if(status_value!=null &amp;&amp; status_value.equalsIgnoreCase("any")){
                          list_mytrucks.setVisibility(View.VISIBLE);
                      }else if(frmcap.getText().toString()!=null &amp;&amp; frmcap.getText().toString().length()&gt;0){
                          truckadapter.advanceSearchFilter(frmcap_val+"","capacity");
                          list_mytrucks.setVisibility(View.VISIBLE);
                      }else if(tocap.getText().toString()!=null &amp;&amp; tocap.getText().toString().length()&gt;0){
                          truckadapter.advanceSearchFilter(tocap_val+"","capacity");
                          list_mytrucks.setVisibility(View.VISIBLE);
                      }else if(current_location.getText().length()&gt;=0){
                          truckadapter.advanceSearchFilter(current_location.getText().toString(),"freeLocation");
                          list_mytrucks.setVisibility(View.VISIBLE);
                      }else if(fromdt.getText().length()&gt;=0){
                          truckadapter.advanceSearchFilter(current_location.getText().toString(),"dateStamp");
                          list_mytrucks.setVisibility(View.VISIBLE);
                      }else if(todt.getText().length()&gt;=0){
                          truckadapter.advanceSearchFilter(current_location.getText().toString(),"dateStamp");
                          list_mytrucks.setVisibility(View.VISIBLE);
                      }
                      view_advance_search.setVisibility(View.GONE);
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
  
  
              }
          });
  </code></pre>
  
  <p>Here is searchFiletring in getViewMethod:</p>
  
  <pre><code>public void advanceSearchFilter(String constraint,String tag) throws JSONException {
              items.clear();
              if(constraint.isEmpty()){
                  items.addAll(advanceSearchArrayList);
              } else{
                  constraint = constraint.toUpperCase();
                  for(int i=0;i&lt;advanceSearchArrayList.size();i++){
                      JSONObject jsonData = new JSONObject(String.valueOf(advanceSearchArrayList.get(i).getVehicle()));
                      if(tag.equalsIgnoreCase("capacity")){
                          int truckCapacity=Integer.parseInt(constraint);
                          if(Integer.parseInt(jsonData.getJSONObject("type").getString("capacity").toUpperCase())&gt;=truckCapacity){
                              items.add(advanceSearchArrayList.get(i));
                          }
                      }
                      if(tag.equalsIgnoreCase("checkBox")){
                          if(advanceSearchArrayList.get(i).getFree().toUpperCase().contains(constraint)){
  
                              items.add(advanceSearchArrayList.get(i));
                          }
                      }
                      if(tag.equalsIgnoreCase("freeLocation")){
                          if(advanceSearchArrayList.get(i).getFree().toUpperCase().equalsIgnoreCase("true")){
                              Log.e("getFree_loc",""+advanceSearchArrayList.get(i).getFree_loc());
                              if(advanceSearchArrayList.get(i).getFree_loc().toUpperCase().contains(constraint)){
                                  items.add(advanceSearchArrayList.get(i));
                              }
  
                          }
  
                      }
                     if(tag.equalsIgnoreCase("dateStamp")){
                         SimpleDateFormat formatter = new SimpleDateFormat("dd-MMM-yyyy");
                         Date date = null;
                         try {
                             date = formatter.parse(constraint);
                         } catch (ParseException e) {
                             e.printStackTrace();
                         }
                         try {
                             if(formatter.parse(advanceSearchArrayList.get(i).getFree().toUpperCase()).before(date) ){
                                 items.add(advanceSearchArrayList.get(i));
                             }
                         } catch (ParseException e) {
                             e.printStackTrace();
                         }
  
                     }
  
  
                  }
              }
              notifyDataSetChanged();
          }
  </code></pre>