]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.db.layer0/src/org/simantics/db/layer0/genericrelation/IndexQueries.java
Improvements to Lucene indexing
[simantics/platform.git] / bundles / org.simantics.db.layer0 / src / org / simantics / db / layer0 / genericrelation / IndexQueries.java
index 135c5ebc2a107b02d20923db0cdd0eda52f082a8..212da3830a1decfaac2ef541ba0f0d5155070252 100644 (file)
@@ -52,7 +52,7 @@ public class IndexQueries {
                        // These characters are part of the query syntax and must be escaped
                        if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
                                        || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
-                                       || c == '|' || c == '&' || c == '/' || (escapeWildcards && (c == '*' || c == '?'))) {
+                                       || c == '|' || c == '&' || c == '/' || c == ' ' || (escapeWildcards && (c == '*' || c == '?'))) {
                                sb.append('\\');
                                sb.append(c);
                                lastWhitespace = false;
@@ -95,7 +95,7 @@ public class IndexQueries {
                        // These characters are part of the query syntax and must be escaped
                        if (c == '\\' || c == '+' || c == '-' || c == '!' || c == '(' || c == ')' || c == ':'
                                        || c == '^' || c == '[' || c == ']' || c == '\"' || c == '{' || c == '}' || c == '~'
-                                       || c == '|' || c == '&' || c == '/' || (escapeWildcards && (c == '*' || c == '?'))) {
+                                       || c == '|' || c == '&' || c == '/' || c == ' ' || (escapeWildcards && (c == '*' || c == '?'))) {
                                return true;
                        } else if (Character.isWhitespace(c)) {
                                lastWhitespace = true;
@@ -113,8 +113,9 @@ public class IndexQueries {
        }
 
        private static final String[] RESERVED_WORDS = {
-               "AND", "and",
-               "OR", "or"
+               "AND", "\\AND",
+               "OR", "\\OR",
+               "NOT", "\\NOT",
        };
 
        /**
@@ -161,6 +162,14 @@ public class IndexQueries {
                StringBuilder sb = new StringBuilder();
                return escapeTerm(field, term, escapeWildcards, sb).toString();
        }
+       
+       public static String quoteTerm(String term) {
+               StringBuilder sb = new StringBuilder();
+               sb.append("\"");
+               sb.append(term.replaceAll("(\"|\\\\)", "\\\\$0"));
+               sb.append("\"");
+               return sb.toString();
+       }
 
 //     public static void main(String[] args) {
 //             System.out.println("esc: " + escape("AND01", true, true));