DanielaSfregola / twitter4s

An asynchronous non-blocking Scala client for both the Twitter Rest and Streaming API
Apache License 2.0
255 stars 100 forks source link

Streaming: Hashtags in OR rather than in AND #221

Open DanielaSfregola opened 6 years ago

DanielaSfregola commented 6 years ago

This came from a discussion on Gitter:

""" I am going to create a ticket to investigate if we can compose hashtags when streaming, i.e.: create a stream that returns tweet about #scala OR #functionalprogramming. I know you can do it with the search REST api (since they have a dedicated syntax) ....not sure about the streaming API """

DanielaSfregola commented 6 years ago

You can indeed! ~By concatenating tracks using spaces instead of commas.~

EDIT: ORs are expressed with commas, AND are expressed with spaces

See https://developer.twitter.com/en/docs/tweets/filter-realtime/guides/basic-stream-parameters#track

wzorgdrager commented 6 years ago

I think it is the other way around if I read the docs. By this model, you can think of commas as logical ORs, while spaces are equivalent to logical ANDs (e.g. ‘the twitter’ is the AND twitter, and ‘the,twitter’ is the OR twitter). So that means you would support OR by default, while AND is also implicitly supported (just add one string with spaces)

DanielaSfregola commented 6 years ago

Thanks @wzorgdrager! You are absolutely right -- I've fixed my comment.

SHORT TERM SOLUTION: Currently we use Seq[String] that is then converted to comma-separated list. So maybe all we need is just better scaladoc to clarify this difference

LONG TERM SOLUTION: When we have time, we should also think of having a dedicated type to express this ANDs - ORs relations (we could use it for the search API too!): Seq[String] is not expressive enough!