Search code examples
twittertwitter4jtwitter-streaming-apiapache-storm

How to get a Twitter4j keyword that's being returned by twitter?


I'm building a system that uses Apache Storm and the library Twitter4j to process real-time Twitter. But I have a problem: Have a way to know which keyword filter gave me that tweet?

Example:

//Topology builder parameter
String keywords = {"Keyword 1", "Keyword 2"};

//Call of Twitter strem API return
  @Override
  public void execute(Tuple tuple, BasicOutputCollector collector) {
      Status status = (Status) tuple.getValueByField("tweet");
      System.out.println(status);
  }

//Result of Sysout
StatusJSONImpl{createdAt=Thu Aug 20 16:55:52 BRT 2015, id=645265788760587264, text='RT @user: This is a Keyword 1 tweet' ... }

StatusJSONImpl{createdAt=Thu Aug 20 16:55:56 BRT 2015, id=645265788760587265, text='RT @user: This is a Keyword 2 tweet' ... }

How I know which keyword was used without string comparison? I didn't find any attribute of the object that have the keyword, only tweet data.


Solution

  • The Twitter Streaming API returns only standard tweet payloads , it does not add any additional metadata with regards to your query. The only way to do what you are asking is to process the message client side against your keyword list.