Tuesday, January 12, 2016

How to filter out BCS top level entities in search


When indexing BCS sources in SharePoint you get two extra top level entries which are not actual data rows. These rows are also searchable by anyone and will appear as noise in your search results unless you filter them away – typically a problem when doing wildcard searches.


When you index BCS entitiy models. SharePoint adds a hidden managed property named entityname to the search schema. This managed property contains the name of the BCS entity being indexed, and is not set for the toplevel BCS items. Hence you can add a filter of entityname:modelname to make sure you filter on exactly what you want, instead of filtering on contentsource.

TL;DR section with an explanation

You have created your BCS models and made them available for indexing, and you might even have added security descriptors to the data being indexed. Here’s my entity called Deviation which fetches data from a SQL database.


Next up you create a content source and configure your search web part to filter items on:


If I search with a user with no access to this model I get the following two hits using the SharePoint Query tool.


As you can see the path of the item is bdc3://deviation_deviation which matches the model and entity name. If I instead query on entityname:deviation, I get zero hits with this user.


How did I discover this? See that link called “View all properties” for the search result? I compared the output for a top level hit and an actual item, I noticed the managed property and value. So for BCS models it’s better to filter on the managed property entityname instead of the managed property contentsource.