[ 
https://issues.apache.org/jira/browse/METAMODEL-136?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14518989#comment-14518989
 ] 

ASF GitHub Bot commented on METAMODEL-136:
------------------------------------------

Github user LosD commented on a diff in the pull request:

    https://github.com/apache/metamodel/pull/21#discussion_r29319785
  
    --- Diff: 
mongodb/src/main/java/org/apache/metamodel/mongodb/MongoDbDataContext.java ---
    @@ -435,6 +442,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);
    +    }
    --- End diff --
    
    Isn't this missing the ```LIKE '%xxxxxx'``` case? I'd imagine a regex with 
$ in the end in that case, so that ```xxxxxxy``` wouldn't match, while 
```yxxxxxx``` would.
    
    But do we even need all these special cases? I would guess that always 
adding ^ and $ would always make it work? A few examples:
    ```LIKE 'xxxxxx'``` would become ```/^xxxxxxx$/``` which would only match 
```xxxxxx```.
    ```LIKE '%xxxxxx'``` would become ```/^.*xxxxxx$/``` which would match 
anything ending with ```xxxxxx```.
    ```LIKE 'xxxxxx%'``` would become ```/^xxxxxx.*$/``` which would match 
anything starting with ```xxxxxx```.


> LIKE operator not supported in MongoDB module
> ---------------------------------------------
>
>                 Key: METAMODEL-136
>                 URL: https://issues.apache.org/jira/browse/METAMODEL-136
>             Project: Apache MetaModel
>          Issue Type: Bug
>    Affects Versions: 4.3.2
>            Reporter: Alberto
>
> The LIKE operator has not been included in the list of available operators.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to