Skip to content

Commit

Permalink
Apply range query to regex queries as well. Fixes bug where regex que…
Browse files Browse the repository at this point in the history
…ries would always search the whole bible.
  • Loading branch information
JJK96 committed Oct 14, 2024
1 parent 89d6f45 commit 9e6da6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ private void generateSearchIndexImpl(Progress job, List<Key> errors, IndexWriter
addField(doc, bodyStemField, canonicalText);
}
//osis.getValue() differs from getCanonicalText in that special characters are not separated from words by whitespace.
//If regex search should be case sensitive, remove toLowerCase here.
addField(doc, fullText, osis.getValue().toLowerCase());

if (includeStrongs) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,6 @@ public Query parse(String aSearch) {

int i = 0;

Matcher regexMatcher = REGEX_PATTERN.matcher(sought);
if (regexMatcher.find()) {
// The regex needs to match the whole string, so we add parts that always match the start and end of the string.
return new RegexpQuery("/.*?" + regexMatcher.group(1) + ".*/");
}

Query range = null;
String rangeModifier = "";
// Look for a range +[...], -[...], or [...]
Expand All @@ -85,10 +79,10 @@ public Query parse(String aSearch) {
blurFactor = Integer.parseInt(blur);
}
Query left = new BaseQuery(sought.substring(i, blurMatcher.start()));
Query right = new BaseQuery(sought.substring(blurMatcher.end()));
Query right = parseRest(sought.substring(blurMatcher.end()));
query = new BlurQuery(left, right, blurFactor);
} else if (sought.length() > 0) {
query = new BaseQuery(sought);
} else if (!sought.isEmpty()) {
query = parseRest(sought);
}

if (range != null && !NULL_QUERY.equals(query)) {
Expand All @@ -103,6 +97,19 @@ public Query parse(String aSearch) {
return query;
}

/**
* Parse the rest of the query, after range and BlurQuery processing is done.
*/
private Query parseRest(String aSearch) {
Matcher regexMatcher = REGEX_PATTERN.matcher(aSearch);
if (regexMatcher.find()) {
// The regex needs to match the whole string, so we add parts that always match the start and end of the string.
return new RegexpQuery("/.*?" + regexMatcher.group(1) + ".*/");
} else {
return new BaseQuery(aSearch);
}
}

/**
* The pattern of a regex query. Currently does not allow "/" characters in the regex string.
* Probably, "/" characters in text searches are not necessary, later the query can always be improved.
Expand Down

0 comments on commit 9e6da6d

Please sign in to comment.