Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MODE-2683 Fixes the behavior of Regex queries for the Lucene Index Pr…
…ovider Note that since Lucene 6, the old Jakarta-based RegexQuery is no longer present and therefore the previous code used Lucene's RegexpQuery which does not support case insensitive searching. This commit fixes the issue by using a custom query.
- Loading branch information
Horia Chiorean
committed
Apr 6, 2017
1 parent
7432510
commit cb5fbb9
Showing
4 changed files
with
46 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...-lucene-index-provider/src/main/java/org/modeshape/jcr/index/lucene/query/RegexQuery.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* ModeShape (http://www.modeshape.org) | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.modeshape.jcr.index.lucene.query; | ||
|
||
import java.util.function.Function; | ||
import java.util.regex.Pattern; | ||
|
||
/** | ||
* Lucene query which uses Java Regex syntax and flags to match the content stored in the indexes against a {@link Pattern} | ||
* | ||
* @author Horia Chiorean (hchiorea@redhat.com) | ||
*/ | ||
public final class RegexQuery extends CompareQuery<String> { | ||
|
||
public RegexQuery(String fieldName, | ||
Pattern pattern, | ||
Function<String, String> caseOperation) { | ||
super(fieldName, pattern.pattern(), (storedValue, regexp) -> pattern.matcher(storedValue).matches(), caseOperation); | ||
} | ||
|
||
@Override | ||
protected String convertValue(String casedValue) { | ||
return casedValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters