Filtering by Topics

Topics are a key feature when working with Facebook topic data in PYLON. Topics are inferred from the content of stories created by authors. Instead of attempting to filter by long lists of keywords, topics give you a strong concept in the Facebook graph to work with. Topics exist for everything from brands to movies to locations!

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.

tip icon

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 Topic Category

Topics on the Facebook graph are grouped into high-level categories. This is extremely useful is you're aiming to capture a broad set of data into your index.

To filter by topic category you make use of the fb.topics.category and fb.parent.topics.category targets.

For instance if you're looking to capture all interactions relating to cars, it's very straight forward:

fb.topics.category == "Cars" or fb.parent.topics.category == "Cars"

Another great use of topic categories is to tighten up a filter. For instance you could look for conversation around luxury cars:

(fb.content contains_any "luxury,executive" OR fb.parent.content contains_any "luxury,executive") 
AND (fb.topics.category == "Cars" or fb.parent.topics.category == "Cars")

The full list of topic categories is available on the fb.topics.category page.

Filtering by Topic Name or ID

As well as filtering to topic categories, you can also filter to individual categories or lists of categories. You can do so by ID or name.

To filter to a well-known brand for example you can filter by name using and == "BMW" or == "BMW"

Or to a list of brands: in "BMW,Nissan,Renault" or in "BMW,Nissan,Renault"

You can also filter by topic IDs using fb.topic_ids and fb.parent.topic_ids:

fb.topic_ids in [22893372268,333711736686957,116825037862] or in [22893372268,333711736686957,116825037862]

See our guide on Discovering Topics for more details on finding topics IDs.

tip icon

Should I use topic names or IDs? Note that the name of a topic is determined by the page name on Facebook. There's a chance the page owner may choose to update the name of their page, this change will be reflected in the topic's name. Topic names are great for exploration, but we recommend you use Topic IDs for production work. (Note there are no IDs for topic categories.)

Note you can also make use of the fb.topics.category_name and fb.parent.topics.category_name targets. These expose topics with their parent category together.

So for example the following CSDL filters to just stories that have the 'BMW' topic within the 'Cars' topic category.

fb.topics.category_name == "Cars|BMW"

This is an alternative to using a combination of the and fb.topics.category targets.

Filtering by Topic Attributes

Aside from having an ID, name and category, topics can also have number of attributes. These are all listed on the targets page.

For instance you could look to filter to interactions relating to San Francisco based companies:

(fb.topics.category == "Company" OR fb.parent.topics.category == "Company") 
AND (fb.topics.location_city == "San Francisco" OR fb.parent.topics.location_city == "San Francisco")

Or, you could filter to interactions relating to companies who sell books:

(fb.topics.category == "Company" OR fb.parent.topics.category == "Company") 
AND (fb.topics.company_overview contains_all "books,retailer" OR fb.parent.topics.company_overview contains_all "books,retailer")