As you start to write your first interaction filters with PYLON, a good place to start is filtering for content by keywords. Even as you write more complex filters you'll still want to include conditions that examine content of interactions.
You can use any of the examples below when creating an Interaction Filter in the dashboard or when compiling a filter using the API & client libraries.
Remember when you write any filter you need to consider whether you are looking for stories, engagements or both. In these examples we'll look for both, so we will make use of both the fb.* and fb.parent.* namespaces.
You can read our introduction to Facebook topic data for more details.
Filtering by Keyword
- fb.content - If the interaction is a story, this is the text content
- fb.parent.content - If the interaction is an engagement, this is the text content of the story being engaged with
- fb.all.content - This target covers both stories and engagements it is populated by the story content if the interaction is a story, or the parent story's content if the interaction is an engagement
You can look for keywords in these targets using operators such as contains_any, wildcard and regex_partial.
A full list is available on the CSDL operators page, but let's look at a few examples.
The following examples explicitly make use of the fb.content and fb.parent.content targets to help you understand exactly what is being filtered for. You can though make use of the fb.all.content to make your filters more concise.
The contains_any operator lets you look for any occurence of a set of words and phrases in content. For example here we're filtering for well known car brands:
fb.content contains_any "BMW,Audi,Nissan,General Motors" OR fb.parent.content contains_any "BMW,Audi,Nissan,General Motors"
Notice the two conditions are combined using the logical operator OR. You can combine any number of conditions this way.
As in this example we're looking for the same phrases in stories and parent stories of engagements the following CSDL is equivalent, making use of the fb.all.content target instead.
fb.all.content contains_any "BMW,Audi,Nissan,General Motors"
The contains_near operator lets you look for words that near to exist close to each other. This can be extremely useful when for example search for book titles, movie titles or anything where in conversation authors are likely to leave out small word.
For example if you're searching for the 'The Girl with the Dragon Tattoo', people may miss out the or with. To cater for this you could use the following CSDL:
fb.content contains_near "girl,dragon,tattoo:5" OR fb.parent.content contains_near "girl,dragon,tattoo:5"
The wildcard operator is great when searching for groups of similar words, or common misspellings.
For example if you're looking for words relating to printing, you'll want to search for words including print, prints, printer, printers, printing and printable. With CSDL this is easy:
fb.content wildcard "print*" OR fb.parent.content wildcard "print*"
Or, if you're looking for a word that's often misspelled, such as accommodation, you can use a wildcard to cater for an 'optional' m:
fb.content wildcard "accom*odation" OR fb.parent.content wildcard "accom*odation"
The regex_partial operator is extremely powerful, giving you the full power of regular expressions in your filters.
For example if you are looking for mentions of 'cashtags' such as $MSFT, you can use a regular expression like so:
fb.content regex_partial "([^A-Z:\\$]|\\A)\\$[A-Z][A-Z]+" OR fb.parent.content regex_partial "([^A-Z:\\$]|\\A)\\$[A-Z][A-Z]+"
Filtering by Language
When filtering by keywords, you're naturally creating bias towards a language. If I filter for Spanish keywords, natually I'll receive mainly Spanish content.
Filtering to one or more languages
It might be important for you to filter to one language:
fb.language == "es" OR fb.parent.language == "es"
Or a list of languages:
fb.language in "en,es" OR fb.parent.language in "en,es"
Aligning keywords with languages
Or for tighter control you can align your content conditions with languages.
( fb.language == "en" AND (fb.content contains "coffee" OR fb.parent.content contains "coffee" ) ) OR ( fb.language == "es" AND (fb.content contains "café" OR fb.parent.content contains "café" ) )
Filtering by Hashtag
Hashtags are used on Facebook just like on Twitter and Instagram.
fb.hashtags in "sun,summer,sunny" OR fb.parent.hashtags in "sun,summer,sunny"