Esempio n. 1
0
 public static IOrderedQueryable <T> AddNameOrder <T>(this IQueryable <T> criteria, ContentLanguagePreference languagePreference)
     where T : IEntryWithNames
 {
     return(FindHelpers.AddNameOrder(criteria, languagePreference));
 }
Esempio n. 2
0
 public static IQueryable <Tag> WhereHasName(this IQueryable <Tag> query, TagSearchTextQuery textQuery)
 {
     return(FindHelpers.AddTagNameFilter(query, textQuery));
 }
Esempio n. 3
0
 public static IQueryable <T> AddEntryNameFilter <T>(this IQueryable <T> query, SearchTextQuery textQuery)
     where T : LocalizedString
 {
     return(FindHelpers.AddEntryNameFilter(query, textQuery));
 }
Esempio n. 4
0
        // TODO: should be combined with common name query somehow, but NH is making it hard
        /// <summary>
        /// Filters an artist query by a name query.
        /// </summary>
        /// <param name="query">Artist query. Cannot be null.</param>
        /// <param name="nameFilter">Name filter string. If null or empty, no filtering is done.</param>
        /// <param name="matchMode">Desired mode for matching names.</param>
        /// <param name="words">
        /// List of words for the words search mode.
        /// Can be null, in which case the words list will be parsed from <paramref name="nameFilter"/>.
        /// </param>
        /// <returns>Filtered query. Cannot be null.</returns>
        public static IQueryable <Artist> WhereHasName(this IQueryable <Artist> query, string nameFilter,
                                                       NameMatchMode matchMode, string[] words = null)
        {
            if (string.IsNullOrEmpty(nameFilter))
            {
                return(query);
            }

            switch (FindHelpers.GetMatchMode(nameFilter, matchMode))
            {
            case NameMatchMode.Exact:
                return(query.Where(m => m.Names.Names.Any(n => n.Value == nameFilter)));

            case NameMatchMode.Partial:
                return(query.Where(m => m.Names.Names.Any(n => n.Value.Contains(nameFilter))));

            case NameMatchMode.StartsWith:
                return(query.Where(m => m.Names.Names.Any(n => n.Value.StartsWith(nameFilter))));

            case NameMatchMode.Words:
                words = words ?? FindHelpers.GetQueryWords(nameFilter);

                switch (words.Length)
                {
                case 1:
                    query = query.Where(q => q.Names.Names.Any(n => n.Value.Contains(words[0])));
                    break;

                case 2:
                    query = query.Where(q =>
                                        q.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[1]))
                                        );
                    break;

                case 3:
                    query = query.Where(q =>
                                        q.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[1])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[2]))
                                        );
                    break;

                case 4:
                    query = query.Where(q =>
                                        q.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[1])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[2])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[3]))
                                        );
                    break;

                case 5:
                    query = query.Where(q =>
                                        q.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[1])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[2])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[3])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[4]))
                                        );
                    break;

                case 6:
                    query = query.Where(q =>
                                        q.Names.Names.Any(n => n.Value.Contains(words[0])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[1])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[2])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[3])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[4])) &&
                                        q.Names.Names.Any(n => n.Value.Contains(words[5]))
                                        );
                    break;
                }
                return(query);
            }

            return(query);
        }
Esempio n. 5
0
 public static IQueryable <T> AddEntryNameFilter <T>(this IQueryable <T> query, string nameFilter, NameMatchMode matchMode,
                                                     string[] words = null)
     where T : LocalizedString
 {
     return(FindHelpers.AddEntryNameFilter(query, nameFilter, matchMode, words));
 }