I'm working on a Sitecore Azure PaaS instance using the Azure Marketplace ARM template which sets up Azure Search. For much of the project things are OK, but I'm having difficulty with Multilist fields. Multilist field values are stored as text in the format of pipe delimited GUIDs. When you use the Sitecore ContentSearch API you cannot search for a particular ID within the string due to the way that Azure search works. I know that it does some weird Regex matching which throws off a bunch of stuff.
So my question is, has anyone found a way to overcome this? There doesn't seem to be a lot of help out there in reference to Azure Search with Sitecore. Googling just gets a bunch of "news" from the Fall when Update 1 came out.
var test2 = context.GetQueryable<SBJSearchItem>()
.Where(p => p.Authors.Contains("9C66"))
.ToArray();
var test3 = context.GetQueryable<SBJSearchItem>()
.Where(p => p.Authors.Contains("8292632F-244A-4327-9C66-80DCF98CCAB8"))
.ToArray();
In the code example above I have a class SBSearchItem
that inherits SearchResultItem
and adds the Authors
property as an index field type of string (see bottom). In the code example above the test2
array returns a number of items as "9C66" matches a portion of an author's item id. But when I pass in the entire ID in the test3
array it returns 0 items.
Here's some data from my Azure Search logs showing the 2 queries. You can see how it's escaping for the URL & Regex.
?api-version=2015-02-28&search=authors:(/.*9C66.*/)&queryType=full&$count=true
?api-version=2015-02-28&search=authors:(/.*8292632F%5C-244A%5C-4327%5C-9C66%5C-80DCF98CCAB8.*/)&queryType=full&$count=true
If I use a REST client and manually pass in the following query I get all of the results as expected. It appears to be the way that the Sitecore ContentSearch API is handling the input.
?api-version=2015-02-28&search=authors:(%22%7B8292632F-244A-4327-9C66-80DCF98CCAB8%7D%22)&queryType=full&$orderby=date%20desc&$count=true
[IndexField("authors")]
public string Authors { get; set; }