简体   繁体   English

如何从我的搜索查询结果选项中排除转发

[英]How to exclude retweets from my search query results Options

I'm trying to search tweets using search method in twitter4j. 我正在尝试使用twitter4j中的搜索方法搜索推文。 My code is as follows, 我的代码如下,

    public List<Tweet> searchTweets(Query searchQuery) { 
        QueryResult queryResult = twitter.search(searchQuery); 

        return queryResult != null ? queryResult.getTweets() : new 
             ArrayList<Tweet>(0); 
    } 

How do I exclude retweets from my search query results 如何从搜索查询结果中排除转推

I was looking for how to exclude the replies on the query search, so I found this topic. 我一直在寻找如何排除查询搜索的回复,所以我找到了这个主题。 To exclude retweets, this worked well for me: 要排除转推,这对我来说效果很好:

Query query = new Query("from:"+twitterAccount + " +exclude:retweets");
Query query = new Query(yourQuery + " -filter:retweets");

source 资源

PS. PS。 I don't know the difference betweeen +exclude:retweets and -filter:retweets ; 我不知道+exclude:retweets-filter:retweets的区别; both seem to do the job similarly. 两者似乎都在做同样的工作。

I would rather comment on this but I can't yet so I'll post this as an answer. 我宁愿对此发表评论,但我还不能这样,我会发布这个作为答案。 You need to edit the Query by appending parameters to it. 您需要通过向其添加参数来编辑查询。 The source code for Query.java can be found in the examples folder in the twitter4j folder. Query.java的源代码可以在twitter4j文件夹的examples文件夹中找到。

public Query(String query) {
    this.query = query;
}

Check out Twitter search (atom) API - exclude retweets . 查看Twitter搜索(原子)API - 排除转推 The search basis is different but the concept is the same, which is appending +exclude:retweets to the end of your string query. 搜索基础不同,但概念是相同的,即追加+排除:转发到字符串查询的末尾。 Try it out and do let me know if it works! 尝试一下,让我知道它是否有效!

I used a different approach than above. 我使用了与上面不同的方法。 See my code below: 请参阅下面的代码:

List<Status> tweets = result.getTweets();
for (Status tweet : tweets )
{
      if( !tweet.isRetweet() )
      // processing .... 
} 

It works for me. 这个对我有用。 However, there might be efficiency differences between these approaches. 但是,这些方法之间可能存在效率差异。

You can use set in the configuration builder the option setIncludeRTsEnabled to false, so is going to remove the retweets. 您可以在配置构建器中使用set setIncludeRTsEnabled选项为false,因此将删除转发。

ConfigurationBuilder builder = new ConfigurationBuilder();
builder.setIncludeRTsEnabled(false);
Twitter twitter = new TwitterFactory(builder.build()).getInstance();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM