Return different content based on page_type, or some other indicator

I am trying to determine the best way to display different content in the search results based on some static indicator, like a meta tag maybe. I am hoping to avoid having to go with a full custom API driven solution.

For a bit more detail… Our site is partly CMS driven and we have a number of different page templates. For most of our page types it will make sense for us to just display a few lines from the Body field in the results. There are going to be some pages, though, for which this won’t make sense. What I would like to be able to do is to have certain page types display something other than the Body text in the results.

For instance, I’d like the search results to look like this:

Title
URL
Highlight
A couple lines from Body

Title
URL
Highlight
A couple lines from Section Title

Title
URL
Highlight
A couple lines from Body

etc.

Is this possible? The second item represents a special case where it doesn’t make sense to display the text of the Body in the results.

I can write the logic to parse the results no problem, the issue is getting Swiftype to return the content of this field in the results based on some indicator.

Lastly, note that I am performing the search by calling the API directly so I can structure the query in any way I want to if that helps.

We are working on ways to index more metadata with the Swiftype web crawler.

However, you should be able to come up with a solution based on the fields we have right now.

For example, you can index the different page types using the type meta tag:

<meta class='swiftype' name='type' data-type='enum' content='[type value]' />

This is returned with the search results as the type field. You could use that value as a basis to conditionally switch between the different types of search results you want to render.

Additionally, you can store any information you want in the info tag, which could be useful for storing unique pieces of data for the content types to display in the results.

You may find it useful to check out our tutorial on adding Swiftype support to any CMS for some more meta tag examples. There is also an example of using different type values in our jQuery result customization tutorial.