The current filter of composite c1 is Case-sensitive ?

Topics: General, Troubleshooting, XSLT
Jul 13, 2011 at 9:19 AM

Hi all.

I create a new data type that has 4 fields ( Firstname , Lastname , Address , Telephone ) and I want to search all of fileds ( Case-insensitive ) by a keyword  that i get from URL.

For example :

.........test.aspx?keyword=abcd

Please show me how to search multi fileds and Case-insensitive .

Thank you very much.

 

 

 

 

 

 

 

Jul 13, 2011 at 9:39 AM

Use StringComparison.InvariantCultureIgnoreCase or StringComparison.OrdinalIgnoreCase ie.

String.Equals(field.FirstName, "abcd", StringComparison.OrdinalIgnoreCase);

or

field.FirstName.IndexOf("abcd", StringComparison.OrdinalIgnoreCase) > -1;

Jul 13, 2011 at 1:00 PM

If you fetch data in C#. that would be something like:


List<ContactInfo> GetFilteredContacts(string searchTerm) {

using(var conn = new DataConnection()) {

  return 
     (from contact in conn.Get<ContactInfo>().AsEnumerable()
      where 
         (field.FirstName != null && (field.FirstName.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) > -1))
      || (field.Lastname != null && (field.Lastname .IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) > -1))
      || (field.Address != null && (field.Address.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) > -1))
      || (field.Telephone != null && (field.Telephone.IndexOf(searchTerm, StringComparison.OrdinalIgnoreCase) > -1))
     select contact).ToList();
 }

}
Note that I used .AsEnumerable() method, to prevent LINQ from trying to translate (and throwing an exception) string.IndexOf() method to a part of SQL statement

If you fetch data in C1 Xslt functions, you should create a custom FieldPredicatesFilter, register in C1 a C# function, that returns Expression<Func<string,bool>>. Something like that

        public static Expression<Func<string,bool>> StringContainsIgnoreCasePredicate(string value)
        {
            return (Expression<Func<string,bool>>) f => f.IndexOf(value, StringComparison.OrdinalIgnoreCase) > -1;
        }


Use compound filter for joining 4 filters (for each field) and that would do it