private static IStringSearch GenerateSearch(StringSearchType type, string pat)
        {
            IStringSearch search = type switch
            {
                StringSearchType.KMP => new KMP(pat),
                StringSearchType.BoyerMoore => new BoyerMoore(pat),
                StringSearchType.Robin => new RabinKarp(pat),
                _ => null,
            };

            return(search);
        }
Esempio n. 2
0
		/// <summary>
		/// Search an IQueryable's specified fields if they contain/equal the keywords; fields other than text will be forced to an '==' operator
		/// </summary>
		/// <param name="list_to_search">IQueryable to search</param>
		/// <param name="properties_to_search">Dictionary with KeyValuePairs of [column_name, type_of_column]; such as [record_id, typeof(int)] or [birthdate, typeof(DateTime)]</param>
		/// <param name="keywords">array of objects of 'keywords' to search for, any type of objects</param>
		/// <param name="string_search_type">Whether or not the string operations use the strict 'Equals' or the broader 'Contains' method</param>
		/// <returns>IQueryable of the inputed type filtered by the search specifications</returns>
		public static IQueryable Search( this IQueryable list_to_search, Dictionary<string, Type> properties_to_search, object[] keywords, StringSearchType string_search_type )
		{
			list_to_search.NotNull();
			Dictionary<object, string> search_object_combos = new Dictionary<object, string>();

			foreach( object o in keywords )
			{
				string where_expression = string.Empty;
				foreach( KeyValuePair<string, Type> column in properties_to_search )
				{
					if( o.GetType() == column.Value )
					{
						if( column.Value == typeof( string ) )
						{
							where_expression += column.Key + "." + ( string_search_type == StringSearchType.Equals ? "Equals" : "Contains" ) + "(@0) || ";
						}
						else // any other data types will run against the keyword with a '=='
						{
							where_expression += column.Key + " == @0 || ";
						}
					}
				}
				search_object_combos.AddSearchObjectCombo( where_expression, o );
			}

			IQueryable results;
			if( search_object_combos.Count() == 0 )
			{
				results = null; //nothing to search
			}
			else
			{
				results = list_to_search.SearchInitial( search_object_combos.First().Value, search_object_combos.First().Key );
			}

			if( search_object_combos.Count() > 1 )
			{   // otherwise, keep use the resulting set and recursively filter it
				search_object_combos.Remove( search_object_combos.First().Key );
				foreach( KeyValuePair<object, string> combo in search_object_combos )
				{
					results = Search( results, combo.Value, combo.Key );
				}
			}
			return results;
		}
Esempio n. 3
0
        /// <summary>
        /// Search an IQueryable's specified fields if they contain/equal the keywords; fields other than text will be forced to an '==' operator
        /// </summary>
        /// <param name="list_to_search">IQueryable to search</param>
        /// <param name="columns_to_search">Dictionary with KeyValuePairs of [column_name, type_of_column]; such as [record_id, typeof(int)] or [birthdate, typeof(DateTime)]</param>
        /// <param name="keywords">array of objects of 'keywords' to search for, any type of objects</param>
        /// <param name="string_search_type">Whether or not the string operations use the strict 'Equals' or the broader 'Contains' method</param>
        /// <returns>IQueryable of the inputed type filtered by the search specifications</returns>
        public static IQueryable Search(this IQueryable list_to_search, Dictionary <string, Type> columns_to_search, object[] keywords, StringSearchType string_search_type)
        {
            Dictionary <object, string> search_object_combos = new Dictionary <object, string>();

            foreach (object o in keywords)
            {
                string where_expression = string.Empty;
                foreach (KeyValuePair <string, Type> column in columns_to_search)
                {
                    if (o.GetType() == column.Value)
                    {
                        if (column.Value == typeof(string))
                        {
                            where_expression += column.Key + ".ToLower()." + (string_search_type == StringSearchType.Equals ? "Equals" : "Contains") + "(@0) || ";
                        }
                        else // any other data types will run against the keyword with a '=='
                        {
                            where_expression += column.Key + " == @0 || ";
                        }
                    }
                }
                search_object_combos.AddSearchObjectCombo(where_expression, o);
            }

            IQueryable results;

            if (search_object_combos.Count() == 0)
            {
                results = null;                                    //nothing to search
            }
            else
            {
                results = list_to_search.SearchInitial(search_object_combos.First().Value, search_object_combos.First().Key);
            }

            if (search_object_combos.Count() > 1)
            {   // otherwise, keep use the resulting set and recursively filter it
                search_object_combos.Remove(search_object_combos.First().Key);
                foreach (KeyValuePair <object, string> combo in search_object_combos)
                {
                    results = Search(results, combo.Value, combo.Key);
                }
            }
            return(results);
        }
Esempio n. 4
0
 /// <summary>
 /// Search an IQueryable's specified text fields if they contain/equal the keywords;  will not work for any fields other than string fields, if you ware using fields that are not strings, use on of the more specific overloads
 /// </summary>
 /// <param name="list_to_search">IQueryable to search</param>
 /// <param name="columns_to_search">string names of the columns to be searched within the IQueryable, may be nest relations as well</param>
 /// <param name="keywords">array for strings to search for</param>
 /// <param name="string_search_type">Whether or not the string operations use the strict 'Equals' or the broader 'Contains' method</param>
 /// <returns>IQueryable of the inputed type filtered by the search specifications</returns>
 public static IQueryable Search(this IQueryable list_to_search, string[] columns_to_search, string[] keywords, StringSearchType string_search_type)
 {
     return(Search(list_to_search, MakeDictionary(columns_to_search), keywords, string_search_type));
 }