From a8ed7f2c17512f36ef883a9805603488df6c5b42 Mon Sep 17 00:00:00 2001 From: Shannon Date: Tue, 23 Jul 2019 22:11:02 +1000 Subject: [PATCH] adds new method --- src/Umbraco.Examine/ExamineExtensions.cs | 25 ++++++++++++++++++++++++ src/Umbraco.Web/PublishedContentQuery.cs | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/Umbraco.Examine/ExamineExtensions.cs b/src/Umbraco.Examine/ExamineExtensions.cs index 1b8033c458..d97278f31c 100644 --- a/src/Umbraco.Examine/ExamineExtensions.cs +++ b/src/Umbraco.Examine/ExamineExtensions.cs @@ -48,6 +48,31 @@ namespace Umbraco.Examine } } + /// + /// Returns all index fields that are culture specific (suffixed) or invariant + /// + /// + /// + /// + public static IEnumerable GetCultureAndInvariantFields(this IUmbracoIndex index, string culture) + { + var allFields = index.GetFields(); + // ReSharper disable once LoopCanBeConvertedToQuery + foreach (var field in allFields) + { + var match = CultureIsoCodeFieldNameMatchExpression.Match(field); + if (match.Success && match.Groups.Count == 3 && culture.InvariantEquals(match.Groups[2].Value)) + { + yield return field; //matches this culture field + } + else if (!match.Success) + { + yield return field; //matches no culture field (invariant) + } + + } + } + internal static bool TryParseLuceneQuery(string query) { // TODO: I'd assume there would be a more strict way to parse the query but not that i can find yet, for now we'll diff --git a/src/Umbraco.Web/PublishedContentQuery.cs b/src/Umbraco.Web/PublishedContentQuery.cs index 2772cc94f6..19e303602d 100644 --- a/src/Umbraco.Web/PublishedContentQuery.cs +++ b/src/Umbraco.Web/PublishedContentQuery.cs @@ -215,7 +215,7 @@ namespace Umbraco.Web //search only the specified culture //get all index fields suffixed with the culture name supplied - var cultureFields = umbIndex.GetCultureFields(culture).ToArray(); + var cultureFields = umbIndex.GetCultureAndInvariantFields(culture).ToArray(); var qry = searcher.CreateQuery().Field(UmbracoContentIndex.VariesByCultureFieldName, "y"); //must vary by culture qry = qry.And().ManagedQuery(term, cultureFields); results = qry.Execute(count);