CodeSmith Community
Your Code. Your Way. Faster!

Strongly typed filter problems

Latest post 05-02-2008 9:48 AM by CitizenBane. 5 replies.
  • 02-15-2007 7:28 AM

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Strongly typed filter problems

    There seems to be a an issue with the strongly typed filters.

    When doing a "Contains" search with more than one value i.e. "for the" the SQL command  gets a WHERE clause like the following:

    "where  (CompanyName LIKE @Param0 AND CompanyName LIKE @Param1) "  - this is ok, but @Param0 contains "%for" and @Param1 contains "the%" - which means no rows are matched.  Both the params need to be wrapped in "%" i.e "%for%" and "%the%" for it to work as expected.

    swin 

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 35
  • 02-26-2007 10:17 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: Strongly typed filter problems

    Any thoughts on this one?
    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 5
  • 02-26-2007 1:45 PM In reply to

    • bgjohnso
    • Top 10 Contributor
    • Joined on 09-15-2005
    • Spokane, WA
    • Posts 764
    • Points 22,530

    RE: Strongly typed filter problems

    Hey swin,

     

    Well, here’s my thoughts…  My feeling is that if you if you search for the words “for the” then it should search on “%for the%” and not “%for%” and “%the%”.  To me, this is intuitively what it should do.  To make it work this way, it’s simply a matter of enclosing the search string in quotes.  This would be done in SqlParameter.GetFilterValue:

     

    String format = "\"{0}\"";

     

    if ( ComparisionType == SqlComparisonType.Contains )

    {

          format = "\"%{0}%\"";

    }

    else if ( ComparisionType == SqlComparisonType.StartsWith )

    {

          format = "\"{0}%\"";

    }

    else if ( ComparisionType == SqlComparisonType.EndsWith )

    {

          format = "\"%{0}\"";

    }

     


    Notice the escaped quote in each format value.  When the parser sees a value enclosed in quotes, it treats the value as a single value and does not try and parse it into different search values.  I would commit this change, but I would like to get feedback from you and anyone else as to whether or not this should be the expected behavior.  At least this works whereas the current implementation does not…

     

    Let me know.

    Ben Johnson
    ------------------------------
     Member of the .NetTiers team
     Visit http://www.nettiers.com
    ------------------------------

    • Post Points: 65
  • 02-27-2007 3:47 AM In reply to

    • swin
    • Top 10 Contributor
    • Joined on 06-14-2006
    • London, UK
    • Posts 922
    • Points 34,710

    Re: RE: Strongly typed filter problems

    Hi Ben,

    My current search requirements were fairly straightforward and your changes work fine for me, so thanks for that.

    However, you could argue that the search should work like the main search engines i.e Google, Windows Live, which do a word search by default and if you want an exact phrase you have to include the quotes (see http://www.google.co.uk/help/basics.html).  Although I imagine creating similar features to Google may well be out of scope of this class!Indifferent

    So I'm happy with what you've done, but maybe a future enhancement would be to allow you to specify which kind of filter to use i.e. phrase (default) or word?

    Thanks again

    swin 

     

     

    ------------------------------------------------- Member of the .NetTiers team -------------------------------------------------
    • Post Points: 5
  • 05-02-2008 7:57 AM In reply to

    • CitizenBane
    • Top 50 Contributor
    • Joined on 10-30-2007
    • Grand Rapids, MI
    • Posts 94
    • Points 1,740

    Re: RE: Strongly typed filter problems

    BigJ:

    I love the idea, and I'd like to implement it.  However, I'd also love the option to exclude the quotes, if necessary.  Or, heck, add another option to include BOTH types of searches.  Search by combining the words and separating them as well.

    Also, I'm noticing that the contains parameters in the WHERE clause are filtered with AND.  How about an option to do with OR and AND/OR?

    ... just throwing some ideas out...

     

    Here's a sample of the new SqlFilterType Enum (if the name is appropriate...)

    /// <summary>
    /// Enumeration of SQL Filter Types.
    /// </summary>
    public enum SqlFilterType
    {
        /// <summary>
        /// Represents an Individual Word filter
        /// </summary>
        /// <example>(if using SqlComparisonType.Contains) CompanyName LIKE "%Acme" AND CompanyName LIKE "Company%"</example>
        Word,
        /// <summary>
        /// Represents a Phrase filter
        /// </summary>
        /// <example>(if using SqlComparisonType.Contains) CompanyName LIKE "%Acme Company%"</example>
        Phrase
    }

    I'm outside ur box, shiftin' ur paradigm.
    • Post Points: 5
  • 05-02-2008 9:48 AM In reply to

    • CitizenBane
    • Top 50 Contributor
    • Joined on 10-30-2007
    • Grand Rapids, MI
    • Posts 94
    • Points 1,740

    Re: RE: Strongly typed filter problems

    I've submitted a patch for this here:

    http://community.codesmithtools.com/forums/p/8376/30771.aspx#30771

     

    By default, the filter will use an SqlFilterType of Word, as it did before the change.

     

    I'm outside ur box, shiftin' ur paradigm.
    • Post Points: 5
Page 1 of 1 (6 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems