Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Searching subreddits for a small string array of keywords #14

Open
chrisjmccrum opened this issue Aug 3, 2021 · 1 comment
Open

Searching subreddits for a small string array of keywords #14

chrisjmccrum opened this issue Aug 3, 2021 · 1 comment

Comments

@chrisjmccrum
Copy link

First off, it's refreshing to find a simple library to access the Reddit API. I was hoping you could help point me in the right direction. Basically, I have a web application where each record has a handful of keywords\tags associated with it. I want to search a couple of subreddits with those keywords in both the post and comments. Any thoughts on the simplest way to approach this?

@JedS6391
Copy link
Owner

JedS6391 commented Aug 3, 2021

Thanks for reaching out!

To search for a keyword in submissions for a particular subreddit, you can use the SearchSubmissionsAsync method, e.g.

var keyword = "...";
var subreddit = client.Subreddit("...");

var searchResults = subreddit.SearchSubmissionsAsync(
    keyword,
    builder => builder.WithSyntax(SearchQuerySyntax.Lucene));

await foreach (var submissionDetails in searchResults)
{
    // Do something with submission
    ...
}

You can find more details of how to use the search API (e.g. the query syntax) in the reddit documentation.

As far as searching comments is concerned, I don't believe the reddit API directly offers any way to do this. There are other services like pushshift.io that support more search options, but this client doesn't currently integrate with that service.

If you want to search new submissions/comments for keywords as they become available, take a look at the streaming sample.

Hope that helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants