public static string Build(string searchTerm, int?companyId = null, int enforceSearchTermLimit = 0, [System.Runtime.CompilerServices.CallerMemberName] string memberName = "") { if (!string.IsNullOrEmpty(searchTerm) && searchTerm.Length >= enforceSearchTermLimit) { searchTerm = FullTextSearchInterceptor.FullTextSearch(searchTerm); } return(string.IsNullOrEmpty(searchTerm) ? null : searchTerm); }
/// <summary> /// Searches the quote text and keywords for the given string using SQL full-text searching. /// </summary> /// <param name="searchText"></param> /// <param name="searchKeyword"></param> /// <returns></returns> public IEnumerable <QuoteDto> Search(string searchText, string searchKeyword, bool recordSearch = true) { bool error = false; try { BeginContextTrans(); if (recordSearch) { //always save a record of each search performed for analytics purposes CurrentContext.PerformedSerarches.Add(new PerformedSearch() { DateSearched = DateTime.Now, TextSearchString = searchText, KeywordSearchString = searchKeyword, }); CurrentContext.SaveChanges(); } if (searchText != null) { searchText = FullTextSearchInterceptor.AsFullTextSearch(searchText); } if (searchKeyword != null) { searchKeyword = FullTextSearchInterceptor.AsFullTextSearch(searchKeyword); } return(CurrentContext.Quotes .Include(r => r.QuoteReferences) .Include(r => r.Founder) .Where(r => r.QuoteText.Contains(searchText) || r.Keywords.Contains(searchKeyword)) .ToArray() .Select(r => MapToDto <Quote, QuoteDto>(r)) .ToArray()); } catch { error = true; RollBackContextTrans(); throw; } finally { if (!error) { CommitContextTrans(); } } }
private DbCommand GetDbCommand() { var sqlCommand = new SqlCommand(@"SELECT [Extent1].[Id] AS [Id], [Extent1].[FirstName] AS [FirstName], [Extent1].[SecondName] AS [SecondName] FROM [dbo].[Users] AS [Extent1] WHERE [Extent1].[FirstName] LIKE @p__linq__0 ESCAPE N'~'"); sqlCommand.Parameters.AddWithValue("p__linq__0", FullTextSearchInterceptor.FullTextSearch("test")); return(sqlCommand); }
public void ReplaceLikeStatement() { var fullTextSearchInterceptor = new FullTextSearchInterceptor(); var dbCommand = GetDbCommand(); Assert.Contains("LIKE", dbCommand.CommandText); Assert.DoesNotContain("CONTAINS", dbCommand.CommandText); fullTextSearchInterceptor.ReaderExecuting(dbCommand, null); Assert.DoesNotContain("LIKE", dbCommand.CommandText); Assert.Contains("CONTAINS", dbCommand.CommandText); }
public static bool IsFullTextApplied(string searchTerm) { return(FullTextSearchInterceptor.IsFullTextApplied(searchTerm)); }