Content Manager query ignoring part of Where clause

Topics: Troubleshooting, Writing modules
Jun 12, 2015 at 11:12 PM
I seem to be having a small issue with a Content Manager query...it's completely ignoring the second part of the where clause
        public IEnumerable<ContentItem> GetTenants(string query) {
            return _contentManager
                .Query(ContentTypes.Tenant)
                .Where<TenantPartRecord>(record => record.IsSearchable && (record.Name.ToLower().Contains(query) || record.FirstName.ToLower().Contains(query) || record.LastName.ToLower().Contains(query) || (record.FirstName.ToLower() + " " + record.LastName.ToLower()).Contains(query)))
                .List();
        }
The first part that checks IsSearchable works fine, but the second part where it should filter based on the "query" value is being ignored.

Is there maybe something special about Content Manager queries and strings that would make this type of query not work properly? Thanks.
Jun 15, 2015 at 9:39 PM
I was able to resolve this issue by modifying the code to the following:
        public IEnumerable<ContentItem> GetTenants(string query) {
            return _contentManager
                .Query(ContentTypes.Tenant)
                .Where<TenantPartRecord>(record => !record.Name.Equals("Default") && (record.Name.Contains(query) || record.FirstName.Contains(query) || record.LastName.Contains(query) || string.Concat(record.FirstName, " ", record.LastName).Contains(query)) && record.IsSearchable)
                .List();
        }
There were 2 issues. First I needed to exclude the Default tenant right from the start because it doesn't contain the additional fields I'm adding values into. Second, hibernate didn't like the string + " " + string method, so I changed it to a string.Concat which is much better anyways. I also moved the IsSearchable check to the end.
Marked as answer by psenechal on 6/15/2015 at 1:39 PM