I am working on a script using Twitter's API and I am trying to find matches to exact phrases.
The API however doesn't allow queries for exact phrases so I've been trying to find a workaround however I am getting results that contain words from the phrases but not in the exact match as the phrase.
var search_terms = "buy now, look at this meme, how's the weather?";
let termSplit = search_terms.toLowerCase();
let termArray = termSplit.split(', ');
//["buy now", "look at this meme", "how's the weather?"];
client.stream('statuses/filter', { track: search_terms }, function (stream) {
console.log("Searching for tweets...");
stream.on('data', function (tweet) {
if(termArray.some(v => tweet.text.toLowerCase().includes(v.toLowerCase()) )){
//if(tweet.text.indexOf(termArray) > 0 )
console.log(tweet);
}
});
});
Expected results should be a tweet with any text as long as it contains the exact phrase somewhere.
The results I am getting returns tweets that have an array value present but not an exact phrase match of the value.
Example results being returned - "I don't know why now my question has a close request but I don't buy it."
Example results I am expecting - "If you like it then buy now."
What am I doing wrong?