|
43 | 43 | import org.apache.lucene.search.spans.SpanOrQuery; |
44 | 44 | import org.apache.lucene.search.spans.SpanQuery; |
45 | 45 | import org.apache.lucene.util.BytesRef; |
| 46 | +import org.apache.lucene.util.automaton.RegExp; |
46 | 47 | import org.elasticsearch.common.lucene.search.Queries; |
47 | 48 | import org.elasticsearch.common.regex.Regex; |
48 | 49 | import org.elasticsearch.common.unit.Fuzziness; |
@@ -669,15 +670,19 @@ private Query getWildcardQuerySingle(String field, String termStr) throws ParseE |
669 | 670 | // effectively, we check if a field exists or not |
670 | 671 | return existsQuery(field); |
671 | 672 | } |
672 | | - String indexedNameField = field; |
673 | 673 | Analyzer oldAnalyzer = getAnalyzer(); |
674 | 674 | try { |
675 | 675 | MappedFieldType currentFieldType = queryBuilder.context.fieldMapper(field); |
676 | | - if (currentFieldType != null) { |
677 | | - setAnalyzer(forceAnalyzer == null ? queryBuilder.context.getSearchAnalyzer(currentFieldType) : forceAnalyzer); |
678 | | - indexedNameField = currentFieldType.name(); |
| 676 | + if (currentFieldType == null) { |
| 677 | + return newUnmappedFieldQuery(field); |
| 678 | + } |
| 679 | + if (forceAnalyzer != null && |
| 680 | + (analyzeWildcard || currentFieldType.getTextSearchInfo().isTokenized())) { |
| 681 | + setAnalyzer(forceAnalyzer); |
| 682 | + return super.getWildcardQuery(currentFieldType.name(), termStr); |
679 | 683 | } |
680 | | - return super.getWildcardQuery(indexedNameField, termStr); |
| 684 | + |
| 685 | + return currentFieldType.wildcardQuery(termStr, getMultiTermRewriteMethod(), context); |
681 | 686 | } catch (RuntimeException e) { |
682 | 687 | if (lenient) { |
683 | 688 | return newLenientFieldQuery(field, e); |
@@ -722,9 +727,12 @@ private Query getRegexpQuerySingle(String field, String termStr) throws ParseExc |
722 | 727 | if (currentFieldType == null) { |
723 | 728 | return newUnmappedFieldQuery(field); |
724 | 729 | } |
725 | | - setAnalyzer(forceAnalyzer == null ? queryBuilder.context.getSearchAnalyzer(currentFieldType) : forceAnalyzer); |
726 | | - Query query = super.getRegexpQuery(field, termStr); |
727 | | - return query; |
| 730 | + if (forceAnalyzer != null) { |
| 731 | + setAnalyzer(forceAnalyzer); |
| 732 | + return super.getRegexpQuery(field, termStr); |
| 733 | + } |
| 734 | + return currentFieldType.regexpQuery(termStr, RegExp.ALL, getMaxDeterminizedStates(), |
| 735 | + getMultiTermRewriteMethod(), context); |
728 | 736 | } catch (RuntimeException e) { |
729 | 737 | if (lenient) { |
730 | 738 | return newLenientFieldQuery(field, e); |
|
0 commit comments