diff --git a/server/AyaNova/biz/Search.cs b/server/AyaNova/biz/Search.cs index 9f5ff96b..b4e943a5 100644 --- a/server/AyaNova/biz/Search.cs +++ b/server/AyaNova/biz/Search.cs @@ -197,16 +197,18 @@ namespace AyaNova.Biz //EXACT MATCH SEARCH TERMS foreach (string Term in SearchTerms) - q.Append($"COUNT(*) FILTER (WHERE asearchdictionary.word = '{Term}') AS 'st{++termCount}', "); + q.Append($"COUNT(*) FILTER (WHERE asearchdictionary.word = '{Term}') AS st{++termCount}, "); //WILDCARD SEARCH TERMS foreach (string WildCardSearchTerm in PreWildCardedSearchTerms) - q.Append($"COUNT(*) FILTER (WHERE asearchdictionary.word LIKE '{WildCardSearchTerm}') AS 'st{++termCount}', "); + q.Append($"COUNT(*) FILTER (WHERE asearchdictionary.word LIKE '{WildCardSearchTerm}') AS st{++termCount}, "); + + q.Length=q.Length-2;//trim the final comma and space - q.Append("FROM asearchdictionary INNER JOIN asearchkey ON asearchdictionary.id = asearchkey.wordid GROUP BY asearchkey.objectid, asearchkey.atype) SELECT objectid, atype FROM qr WHERE "); + q.Append(" FROM asearchdictionary INNER JOIN asearchkey ON asearchdictionary.id = asearchkey.wordid GROUP BY asearchkey.objectid, asearchkey.atype) SELECT objectid, atype FROM qr WHERE "); for (; termCount > 0; termCount--) - q.Append($"st{termCount} > 0 {(termCount > 1 ? "AND" : "")}"); + q.Append($"st{termCount} > 0 {(termCount > 1 ? "AND " : "")}"); //execute the query and iterate the results