首页 > 解决方案 > 从 Twitter 搜索 API 中排除多词关键字

问题描述

我有一个要从搜索中排除的关键字列表

KEYWORDS = %w[
    covid corona subway railway travel plane brazil ]

exclude = Twitter::KEYWORDS.split(",").join(" -")

这就是我的搜索查询的样子

 json_response = @client.search("(javascript) -#{exclude}", lang: "en", result_type: "recent", tweet_mode: "extended", count: 100)

如何在此处传递多字关键字以排除,例如“off the hand”或“game plan”等关键字?

将它们与其他关键字一起添加不会按预期工作。

标签: rubyruby-on-rails-3twitter

解决方案


如果有人回来寻找同样的问题,这就是我解决它的方法:

@client.search("(javascript) -#{exclude} -\"off the hand\" -\"game plan\", lang: "en", result_type: "recent", tweet_mode: "extended", count: 100)

因此,基本上通过使用转义字符,我可以将多字关键字作为精确字符串传递。


推荐阅读