title: Altering twitter4j to search
body: <p>I am currently creating code that should search through tweets based on keywords.  i originally created a streamer using the twitter4j API, only to find out that you cant filter multiple filters.  my code for this is listed below.</p>
  
  <pre><code>public class TweetStreamer {
  public static void stream(String[] apiKeys, String[] stopwords, long[] users, double[][] coordinates, BiConsumer&lt;Status, String&gt; fn) throws InterruptedException {
      // Save the arguments
      String consumerKey = apiKeys[0];
      String consumerSecret = apiKeys[1];
      String token = apiKeys[2];
      String secret = apiKeys[3];
  
      // Store the configuration
      ConfigurationBuilder config = new ConfigurationBuilder();
      config.setDebugEnabled(true);
      config.setOAuthConsumerKey(consumerKey);
      config.setOAuthConsumerSecret(consumerSecret);
      config.setOAuthAccessToken(token);
      config.setOAuthAccessTokenSecret(secret);
  
      config.setJSONStoreEnabled(true);
  
      // Create a status listener. When a new tweet arives, the function object will accept it.
      StatusListener listener = new TwitterStatusListener(fn);
  
      // Create the filter. Can filter:
      //  * by Users (follow[])
      //  * by Stopword (track[])
      //  * by Location (locations[][])
      //  * by Language (language[])
      FilterQuery filter = new FilterQuery();
      filter.track(stopwords);
      filter.follow(users);
      filter.locations(coordinates);
  
      // Create the stream-object
      // Documentation: http://twitter4j.org/javadoc/twitter4j/TwitterStream.html
      TwitterStream stream = new TwitterStreamFactory(config.build()).getInstance();
  
      stream.addListener(listener);
      stream.filter(filter);
  }
  }
  </code></pre>
  
  <p>I have wrote some code that will work as a search using Query instead of FilterQuery. however im struggling to replace one with the other.</p>
  
  <p>my search code is as follows:</p>
  
  <pre><code>public class TweetGetter {
  
  /**
   * @param response
   */
  public void searchTwitter(String searchString) {
  
      /*
       * The TwitterFactory is what interacts directly with Twitter
       */
      ConfigUtil twitterConfig = new ConfigUtil();
      TwitterFactory tf = new TwitterFactory(twitterConfig.configureTwitter().build());
      Twitter twitter = tf.getInstance();
  
      Scanner scan = new Scanner (System.in);
  
      // The factory instance is re-useable and thread safe.
      try {
          Query query = new Query();
          query.setLang("en");
          // query.setCount(10);
          query.setQuery(searchString);
  
          double lat = 28.6538100;
          System.out.println();
  
  
          double lon =77.2289700;
          System.out.println();
  
          //GeoLocation gl = new GeoLocation(28.6538100, 77.2289700);
          GeoLocation gl = new GeoLocation(lat, lon);
  
  
          double rad = 1000;
          System.out.println();
  
          //query.setGeoCode(gl, 1500, Query.KILOMETERS);
          query.setGeoCode(gl, rad, Query.KILOMETERS);
          query.setLang("en");
          query.setCount(500);
  
          // The object the will contain the results of the query
          QueryResult result;
  
          do {
              result = twitter.search(query);
              List&lt;Status&gt; tweets = result.getTweets();
  
              SaveUtil saver = new SaveUtil();
              saver.saveTweets(tweets);
  
          } while ((query = result.nextQuery()) != null);
  
      } catch (TwitterException te) {
          te.printStackTrace();
          System.out.println("Failed to search tweets: " + te.getMessage());
          // System.exit(-1);
      } catch (Exception e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
  
      scan.close();
  
  }
  
  }
  </code></pre>
  
  <p>where saveUtil simply saves data in a text file.</p>
  
  <p>is there anyway i could modify the search code to replace the TweetStreamer?</p>