【问题标题】:Exclude multi-word keywords from Twitter Search API从 Twitter 搜索 API 中排除多词关键字
【发布时间】:2020-11-07 11:55:47
【问题描述】:

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

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”等关键字?

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

【问题讨论】:

  • 您是否对在字符串中存储多字数组或将它们传递给 Twitter 有问题?如果您手动构建 @client.search 参数以包含多字字符串,是否有效?
  • 问题在于将多词数组传递给 Twitter。我尝试构建这样的参数 @client.search("(javascript) -#{exclude} -"off the rails" ") 但这不起作用。 @max-pleaner
  • 您是否查看过有关如何构建这些搜索查询的文档?他们特别提到应该逐字处理多字排除,例如-off -the -railsdeveloper.twitter.com/en/docs/labs/recent-search/guides/…
  • 澄清一下,Twitter Ruby gem 使用的是旧搜索 developer.twitter.com/en/docs/tweets/search/api-reference/… 而不是实验室中的搜索,但是是的,您仍然需要单独否定每个术语。
  • 谢谢!我确实看过 Twitter 文档。但是如果我必须排除完全匹配的 "off the rails" 怎么办?如果我像 -off -the -rails 那样构建它,那么它也会排除出现任何这些词的推文。我只想排除与关键字 "off the rails" 完全匹配的推文

标签: ruby ruby-on-rails-3 twitter


【解决方案1】:

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

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

所以,基本上是通过使用转义字符,它允许我将多字关键字作为精确字符串传递。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-09-21
    • 2011-10-16
    • 1970-01-01
    • 2018-11-18
    • 2014-12-06
    • 1970-01-01
    • 2018-11-26
    • 2015-12-06
    相关资源
    最近更新 更多