Android Open Source - Team7-301Project Simple Search Command






From Project

Back to project page Team7-301Project.

License

The source code is released under:

Apache License

If you think the Android project Team7-301Project listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package ca.ualberta.cs.remote_server;
//  w w w.  j a  v a  2 s . c  om
import android.content.Context;
import ca.ualberta.cs.controllers.AuthorController;
import ca.ualberta.cs.intent_singletons.ContextSingleton;

/**
 * turns query into a proper elastic search command
 * so that it can be passed into the elastic search server
 * 
 * taken from:
 * https://github.com/dfserrano/AndroidElasticSearch
 * @author lexie
 * 
 */
public class SimpleSearchCommand {

  private String query;
  private String[] fields;
  private Boolean byLocation=false;
  public SimpleSearchCommand(String query, String[] fields, Boolean byLocation_) {
    this.query = query;
    this.fields = fields;
    byLocation = byLocation_;
  }

  public String getJsonCommand() {
    StringBuffer command = new StringBuffer();

    final AuthorController ac= new AuthorController();
    
    if(ac.getModel().isGpsSet()){
        double latitude = ac.getModel().getSessionLatitude();
        double longitude = ac.getModel().getSessionLongitude();
    
        if(byLocation){
          command = new StringBuffer("{\"sort\":[{\"_geo_distance\" : { \"pin.location\": ["+latitude+ ","+ longitude+"],"
              + "\"order\":\"asc\", \"unit\": \"km\" } } ] ,"+
              "{\"from\":0, \"size\": 100, \"query\" : {\"query_string\" : {\"query\" : \"" + query
              + "\"");
        }
      }
    else{
      command = new StringBuffer(
        "{\"from\":0, \"size\": 100, \"query\" : {\"query_string\" : {\"query\" : \"" + query
            + "\"");
    }

    if (fields != null) {
      command.append(", \"fields\":  [");

      for (int i = 0; i < fields.length; i++) {
        command.append("\"" + fields[i] + "\", ");
      }
      command.delete(command.length() - 2, command.length());

      command.append("]");
    }

    command.append("}}}");

    return command.toString();
  }
}




Java Source Code List

ca.ualberta.cs.controllers.AuthorController.java
ca.ualberta.cs.controllers.BrowseController.java
ca.ualberta.cs.controllers.ForumEntryController.java
ca.ualberta.cs.controllers.SearchController.java
ca.ualberta.cs.f14t07_application.Hits.java
ca.ualberta.cs.f14t07_application.LogoActivity.java
ca.ualberta.cs.f14t07_application.Post.java
ca.ualberta.cs.intent_singletons.BrowseRequestSingleton.java
ca.ualberta.cs.intent_singletons.ContextSingleton.java
ca.ualberta.cs.intent_singletons.EntrySingleton.java
ca.ualberta.cs.intent_singletons.ForumEntrySingleton.java
ca.ualberta.cs.models.Answer.java
ca.ualberta.cs.models.AuthorModel.java
ca.ualberta.cs.models.DataManager.java
ca.ualberta.cs.models.Entry.java
ca.ualberta.cs.models.ForumEntryList.java
ca.ualberta.cs.models.ForumEntry.java
ca.ualberta.cs.models.JsonDriver.java
ca.ualberta.cs.models.Observable.java
ca.ualberta.cs.models.Question.java
ca.ualberta.cs.models.Reply.java
ca.ualberta.cs.remote_server.NetworkChecker.java
ca.ualberta.cs.remote_server.SearchHit.java
ca.ualberta.cs.remote_server.SearchResponse.java
ca.ualberta.cs.remote_server.SimpleSearchCommand.java
ca.ualberta.cs.views.AnswerActivity.java
ca.ualberta.cs.views.AnswerListAdapter.java
ca.ualberta.cs.views.AskActivity.java
ca.ualberta.cs.views.BrowseActivity.java
ca.ualberta.cs.views.HelpActivity.java
ca.ualberta.cs.views.MainScreenActivity.java
ca.ualberta.cs.views.Observer.java
ca.ualberta.cs.views.QuestionActivity.java
ca.ualberta.cs.views.ReplyListAdapter.java