Tuesday, January 12, 2016

How to filter out BCS top level entities in search

imageProblem

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.

Solution

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.

image

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

image

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

image

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.

image

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.

3 comments:

  1. Hi Mikael, in your example "Deviation" is the model name, the entity name, the content source name, etc, it is a bit confusing. We want all the entities in our model to appear. Does the filter entityname:modelname return all the entities in the model without having to name them individually? Thanks

    ReplyDelete
    Replies
    1. Good question and I didn't test that. I only had one entity per model, so not sure if you get one value per entity or per actual model. If you get to test this out let me know, and I'll update my post. I don't have an on-prem environment running at the moment to test on.

      Delete
    2. You could also filter on path, and remove the top two entries.

      Delete