-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Set analyzer to regex query string search #3967
Merged
nknize
merged 11 commits into
opensearch-project:main
from
yyyogev:default-analyzer-regex-search
Aug 15, 2022
+32
−7
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
d2e6e08
set analyzer to regex query string search
yyyogev 036029a
pr changes
yyyogev 64e6098
remove comments
yyyogev f5351fa
Merge branch 'main' of github.com:/opensearch-project/OpenSearch into…
yyyogev 04fb97f
small fix
yyyogev b3a4cec
lint
yyyogev 105f68d
small change
yyyogev f28e335
undo change in wildcard queries to preserve pipeline
yyyogev 930cbd8
Merge branch 'main' of github.com:/opensearch-project/OpenSearch into…
yyyogev c2ed7a2
Merge branch 'main' of github.com:/opensearch-project/OpenSearch into…
yyyogev 5d40287
spotless
yyyogev File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,7 +56,6 @@ | |
import org.apache.lucene.search.SynonymQuery; | ||
import org.apache.lucene.search.WildcardQuery; | ||
import org.apache.lucene.util.BytesRef; | ||
import org.apache.lucene.util.automaton.RegExp; | ||
import org.opensearch.common.lucene.search.Queries; | ||
import org.opensearch.common.regex.Regex; | ||
import org.opensearch.common.unit.Fuzziness; | ||
|
@@ -717,20 +716,25 @@ private Query getWildcardQuerySingle(String field, String termStr) throws ParseE | |
// effectively, we check if a field exists or not | ||
return existsQuery(field); | ||
} | ||
String indexedNameField = field; | ||
Analyzer oldAnalyzer = getAnalyzer(); | ||
try { | ||
MappedFieldType currentFieldType = queryBuilder.context.fieldMapper(field); | ||
if (currentFieldType == null) { | ||
return newUnmappedFieldQuery(field); | ||
} | ||
if (forceAnalyzer != null && (analyzeWildcard || currentFieldType.getTextSearchInfo().isTokenized())) { | ||
setAnalyzer(forceAnalyzer); | ||
return super.getWildcardQuery(currentFieldType.name(), termStr); | ||
if (currentFieldType != null) { | ||
// return newUnmappedFieldQuery(field); | ||
setAnalyzer(forceAnalyzer == null ? queryBuilder.context.getSearchAnalyzer(currentFieldType) : forceAnalyzer); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we do this in multiple places maybe add a private if/else would probably look cleaner There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
indexedNameField = currentFieldType.name(); | ||
} | ||
|
||
// if (forceAnalyzer != null && (analyzeWildcard || currentFieldType.getTextSearchInfo().isTokenized())) { | ||
// setAnalyzer(forceAnalyzer); | ||
// return super.getWildcardQuery(currentFieldType.name(), termStr); | ||
// } | ||
yyyogev marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (getAllowLeadingWildcard() == false && (termStr.startsWith("*") || termStr.startsWith("?"))) { | ||
throw new ParseException("'*' or '?' not allowed as first character in WildcardQuery"); | ||
} | ||
return currentFieldType.wildcardQuery(termStr, getMultiTermRewriteMethod(), context); | ||
return super.getWildcardQuery(indexedNameField, termStr); | ||
// return currentFieldType.wildcardQuery(termStr, getMultiTermRewriteMethod(), context); | ||
} catch (RuntimeException e) { | ||
if (lenient) { | ||
return newLenientFieldQuery(field, e); | ||
|
@@ -781,11 +785,13 @@ private Query getRegexpQuerySingle(String field, String termStr) throws ParseExc | |
if (currentFieldType == null) { | ||
return newUnmappedFieldQuery(field); | ||
} | ||
if (forceAnalyzer != null) { | ||
setAnalyzer(forceAnalyzer); | ||
return super.getRegexpQuery(field, termStr); | ||
} | ||
return currentFieldType.regexpQuery(termStr, RegExp.ALL, 0, getDeterminizeWorkLimit(), getMultiTermRewriteMethod(), context); | ||
setAnalyzer(forceAnalyzer == null ? queryBuilder.context.getSearchAnalyzer(currentFieldType) : forceAnalyzer); | ||
return super.getRegexpQuery(field, termStr); | ||
// if (forceAnalyzer != null) { | ||
// setAnalyzer(forceAnalyzer); | ||
// return super.getRegexpQuery(field, termStr); | ||
// } | ||
// return currentFieldType.regexpQuery(termStr, RegExp.ALL, 0, getDeterminizeWorkLimit(), getMultiTermRewriteMethod(), context); | ||
} catch (RuntimeException e) { | ||
if (lenient) { | ||
return newLenientFieldQuery(field, e); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hm ... did we lost
if (currentFieldType == null) {
condition?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I figured it will be cleaner to check
if (currentFieldType != null)
now that we always set the analyzerThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But this is unmapped field case, we probably should return
newUnmappedFieldQuery
?