Smart Search - Exact Phrase Match for Document Tags (or how to use IDs)

Tristan Thompson asked on January 5, 2016 12:26

We are using the Smart Search API to search through documents and want to filter by:

  1. text
  2. document category
  3. document tag

We have it working 100% fine for text and category, however, we're still not happy with tag matching. With the category it lets us search by ID for an exact category match using +documentcategoryids((int)1|(int)2). However, there doesn't seem to be an equivalent for tag IDs - we're forced to use the tag name. This wasn't too much of a problem, until we realised that when doing this, it's not doing an exact phrase match. For example, 2 of the tags in our system are "Cash Flow" and "Petty Cash".

If we search for "Cash Flow" as follows... +documenttags:(Cash Flow) ...this is matching tags for both "Petty Cash" and "Cash Flow"

I have tried the following to attempt to force an exact phrase match (based on what I saw for Lucene syntax), however, nothing seems to work - they either bring back no results or they bring back all pages (i.e. they don't filter).

+documenttags:("Cash Flow") +documenttags:"Cash Flow" +documenttags:[Cash Flow] +documenttags:([Cash Flow])

Ideally, I'd like to filter by ID, but I can't seem to (I've tried tagids, tagid, documenttagids, documenttagid but never seem to get anything useful from them.

So - does anyone know how to: - filter by tag ID? - force an exact phrase match when searching by documenttags?

Thanks in advance

Correct Answer

Tristan Thompson answered on January 12, 2016 13:28

I had lengthy emails with the Kentico support team and couldn't find a way to make the exact phrase match work, nor searching by tag IDs. I have, however, come up with a work-around.

I've replaced the spaces in the phrase it with "+" signs to require each word.

i.e. +documenttags:(Cash+Flow)

In order to search for multiple terms, I use the following:

+documenttags:((Cash+Flow) || (Petty+Cash))

0 votesVote for this answer Unmark Correct answer

Recent Answers

Brian McKeiver answered on January 5, 2016 15:03

I'm not 100% if this will work, but I think it might. Try the syntax of +documenttags{0} where 0 is the label of the tag name. This worked for me when I was using the Smart Search filter web parts. See my example: Smart Search Filter blog post

0 votesVote for this answer Mark as a Correct answer

Roman Hutnyk answered on January 5, 2016 15:09

Make sure DocumentTags field is not tokenized - this might help.

There are some articles on DevNet, that I found useful:

0 votesVote for this answer Mark as a Correct answer

Tristan Thompson answered on January 5, 2016 18:06

@Brian - thanks for the suggestion, but I'm not using the Kentico Smart Search web part as it's not fit for what we need - we're writing our own bespoke search web part using the SearchHelper.Search() C# method. I'd already come across your suggestion but unfortunately it doesn't work - I think that syntax is specifically for that web part.

@Roman - thanks, but as documenttags is an in-built field, I can't see it listed in the "Search Fields" tab of my Page Type - is there somewhere else I should be looking for it?

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.