thomasmueller commented on a change in pull request #311:
URL: https://github.com/apache/jackrabbit-oak/pull/311#discussion_r665395725
##########
File path:
oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
##########
@@ -290,13 +292,31 @@ public static void setUseActualEntryCount(boolean
useActualEntryCount) {
IndexPlan.Builder plan = defaultPlan();
+ if (plan == null) {
+ return null;
+ }
+
if
(filter.getQueryLimits().getStrictPathRestriction().equals(StrictPathRestriction.WARN.name())
&& !isPlanWithValidPathFilter()) {
plan.setLogWarningForPathFilterMismatch(true);
}
- if (plan == null) {
- return null;
+ Pattern queryFilterPattern = definition.getQueryFilterRegex() !=
null ? definition.getQueryFilterRegex() :
+ definition.getPropertyRegex();
+
+ if (queryFilterPattern != null) {
+ if (ft != null &&
!queryFilterPattern.matcher(ft.toString()).find()) {
+ plan.addAdditionalMessage(Level.WARN, "Potentially
improper use of index " + definition.getIndexPath() + " with valueRegex "
Review comment:
It would use " with queryFilterRegex "
##########
File path:
oak-search/src/main/java/org/apache/jackrabbit/oak/plugins/index/search/spi/query/FulltextIndexPlanner.java
##########
@@ -290,13 +292,31 @@ public static void setUseActualEntryCount(boolean
useActualEntryCount) {
IndexPlan.Builder plan = defaultPlan();
+ if (plan == null) {
+ return null;
+ }
+
if
(filter.getQueryLimits().getStrictPathRestriction().equals(StrictPathRestriction.WARN.name())
&& !isPlanWithValidPathFilter()) {
plan.setLogWarningForPathFilterMismatch(true);
}
- if (plan == null) {
- return null;
+ Pattern queryFilterPattern = definition.getQueryFilterRegex() !=
null ? definition.getQueryFilterRegex() :
+ definition.getPropertyRegex();
+
+ if (queryFilterPattern != null) {
+ if (ft != null &&
!queryFilterPattern.matcher(ft.toString()).find()) {
+ plan.addAdditionalMessage(Level.WARN, "Potentially
improper use of index " + definition.getIndexPath() + " with valueRegex "
+ + queryFilterPattern + " to search for value " +
ft.toString());
+ }
+ for (PropertyRestriction pr :
filter.getPropertyRestrictions()) {
+ if (!queryFilterPattern.matcher(pr.toString()).find()) {
+ plan.addAdditionalMessage(Level.WARN, "Potentially
improper use of index " + definition.getIndexPath() + " with valueRegex "
Review comment:
It would use " with queryFilterRegex "
##########
File path:
oak-query-spi/src/main/java/org/apache/jackrabbit/oak/spi/query/QueryIndex.java
##########
@@ -491,6 +510,17 @@ public IndexPlan build() {
private final boolean deprecated =
Builder.this.deprecated;
private final boolean logWarningForPathFilterMismatch =
Builder.this.logWarningForPathFilterMismatch;
+ private final Map<Level, List<String>> additionalMessages
= Builder.this.additionalMessages;
+
+ private String getAdditionalMessageString() {
+ StringBuilder stringBuilder = new StringBuilder();
+ for (Map.Entry<Level, List<String>> messages :
additionalMessages.entrySet()) {
+ stringBuilder.append(messages.getKey()).append(" :
").append(messages.getValue()).append(", ");
Review comment:
Fabrizios approach is fine... if you want to use a loop, it would have
to be like this (I didn't test):
StringBuilder buff = new StringBuilder();
for (Map.Entry<Level, List<String>> messages :
additionalMessages.entrySet()) {
if (!buff.isEmpty()) {
buff.append(", ");
}
buff.append(messages.getKey() + " : " + messages.getValue());
}
return buff.toString();
I'm not saying it's better that Fabrizios approach... just that this would
be the "common" approach when using a loop.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]