internal static string CanCompile(QueryInfo queryInfo, bool withMessages) { var msg = "error"; if (queryInfo.AllVersions) { if (withMessages) { msg = "Cannot compile to SQL: AllVersions"; } return(msg); } if (queryInfo.CountOnly) { if (withMessages) { msg = "Cannot compile to SQL: CountOnly"; } return(msg); } if (0 < queryInfo.Top) { if (withMessages) { msg = "Cannot compile to SQL: Top:" + queryInfo.Top; } return(msg); } if (0 < queryInfo.Skip) { if (withMessages) { msg = "Cannot compile to SQL: Skip:" + queryInfo.Skip; } return(msg); } if (0 < queryInfo.PhraseQueries) { if (withMessages) { msg = "Cannot compile to SQL: PhraseQuery is forbidden."; } return(msg); } if (0 < queryInfo.FuzzyQueries) { if (withMessages) { msg = "Cannot compile to SQL: FuzzyQuery is forbidden."; } return(msg); } if (0 < queryInfo.QuestionMarkWildcards) { if (withMessages) { msg = "Cannot compile to SQL: a question mark wildcard exists."; } return(msg); } if (0 < queryInfo.FullRangeNumericQueries + queryInfo.FullRangeTermQueries) { if (withMessages) { msg = "Cannot compile to SQL: in a range query both limit are defined."; } return(msg); } var forbiddenFields = queryInfo.QueryFieldNames.Except(_enabledFields).ToArray(); if (forbiddenFields.Length > 0) { if (withMessages) { msg = string.Format("Cannot compile to SQL: Forbidden fields: [{0}]", string.Join(", ", forbiddenFields)); } return(msg); } forbiddenFields = queryInfo.SortFieldNames.Except(_enabledFields).ToArray(); if (forbiddenFields.Length > 0) { if (withMessages) { msg = string.Format("Cannot compile to SQL: Forbidden sort fields: [{0}]", string.Join(", ", forbiddenFields)); } return(msg); } if (!queryInfo.QueryFieldNames.Intersect(_indexedFields).Any()) { if (withMessages) { msg = string.Format("Cannot compile to SQL: Missing required field, at least one of the followings: [{0}]", string.Join(", ", _indexedFields)); } return(msg); } return(null); }
public QueryClassifierVisitor(QueryInfo queryInfo) { _queryInfo = queryInfo; }