metamodel-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From albertostratio <...@git.apache.org>
Subject [GitHub] metamodel pull request: Add LIKE operator support. Fixes #METAMODE...
Date Tue, 28 Apr 2015 14:15:35 GMT
Github user albertostratio commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/21#discussion_r29246239
  
    --- Diff: mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataContext.java ---
    @@ -435,6 +441,19 @@ private String getOperatorName(FilterItem item) {
             return operatorName;
         }
     
    +    private Pattern turnOperandIntoRegExp(Object operand) {
    +        String operandAsString = operand.toString();
    +        StringBuilder operandAsRegExp = new StringBuilder(replaceWildCardLikeChars(operandAsString));
    +        if (!operandAsString.startsWith("%") && operandAsString.contains("%"))
{
    +            operandAsRegExp = operandAsRegExp.insert(0, "^");
    +        }
    +        return Pattern.compile(operandAsRegExp.toString(), Pattern.CASE_INSENSITIVE);
    +    }
    +
    +    private String replaceWildCardLikeChars(String operand) {
    +        return operand.replace("%","");
    --- End diff --
    
    Yes, you are right, is just removing the %. I think we don't need to add more complexity
to the regular expression, when we'd receive a string like '%MALE%' we just need to create
a pattern like this (removing the %):
    ```
    Pattern j = Pattern.compile("MALE", Pattern.CASE_INSENSITIVE);
    ```
    Whereas when we'd receive a string like 'MALE%' the pattern should be (removing % and
prepend ^):
    ```
    Pattern j = Pattern.compile("^MALE", Pattern.CASE_INSENSITIVE);
    ```
    I think these are the only cases we should care about. Both are working fine as tested
in the test I've added.
    
    What do you think?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message