Tweepy search query issues

旧时模样 提交于 2021-02-19 07:01:52

问题


I'm working on a program to analyse data using Twitter's REST API, I looking to use a query with multiple keywords to get the results I'm looking for. However, I'm having issues when using a search query to get specific results. I have followed the documentation to use 'OR' search for multiple words but it's only working to a certain extent.

In this code when I use the query:

q = ('plane fly OR car drive -filter:retweets AND filter:replies')

It returns tweets that either include the words 'plane' & 'fly' OR 'car' & 'drive'. But if I added another keyword filter on at random, for example:

q = ('plane fly OR car drive OR cadburys chocolate -filter:retweets AND filter:replies')

This does not return any tweets at all. I'm not sure if I'm misunderstanding the way the query works with the use of OR, but I'd imagine even if there were no tweets containing 'cadburys chocolate', it would still return the other tweets for the other keywords?

Does anyone know where I am going wrong? If the query can be structured this way? Or if not, is there a way I can search for multiple keywords/phrases in one query?

Thanks for you time, any help is appreciated.


回答1:


The syntax seems to be fine. Could you try use AND instead of space when using multiple comparison (more than two). q = ('plane AND fly OR car AND drive OR cadburys AND chocolate -filter:retweets AND filter:replies')

You may need to use the AND operator when stringing multiple operators together.




回答2:


https://unionmetrics.com/resources/how-to-use-advanced-twitter-search-queries/ According to this link: You can also chain together multiple keywords to create a more complex query. The OR operator will attach to the word that immediately precedes it, very much like order of operations in algebra. For example, the following query will find tweets that mention social media metrics or social media analytics, because the OR links to the metrics and analytics terms

q="social media metrics OR analytics" would return results containing the words social media metrics or social media analytics

You're not wrong, but it was just never clear on how to search for terms longer than 1 word.



来源:https://stackoverflow.com/questions/54470760/tweepy-search-query-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!