move regex to use Object as paramater as well
This commit is contained in:
parent
f8a08a46ac
commit
22077d1c5f
|
@ -183,9 +183,9 @@ public interface FieldMapper<T> {
|
|||
|
||||
Filter prefixFilter(Object value, @Nullable QueryParseContext context);
|
||||
|
||||
Query regexpQuery(String value, int flags, @Nullable MultiTermQuery.RewriteMethod method, @Nullable QueryParseContext context);
|
||||
Query regexpQuery(Object value, int flags, @Nullable MultiTermQuery.RewriteMethod method, @Nullable QueryParseContext context);
|
||||
|
||||
Filter regexpFilter(String value, int flags, @Nullable QueryParseContext parseContext);
|
||||
Filter regexpFilter(Object value, int flags, @Nullable QueryParseContext parseContext);
|
||||
|
||||
/**
|
||||
* A term query to use when parsing a query string. Can return <tt>null</tt>.
|
||||
|
|
|
@ -462,7 +462,7 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Query regexpQuery(String value, int flags, @Nullable MultiTermQuery.RewriteMethod method, @Nullable QueryParseContext context) {
|
||||
public Query regexpQuery(Object value, int flags, @Nullable MultiTermQuery.RewriteMethod method, @Nullable QueryParseContext context) {
|
||||
RegexpQuery query = new RegexpQuery(names().createIndexNameTerm(indexedValueForSearch(value)), flags);
|
||||
if (method != null) {
|
||||
query.setRewriteMethod(method);
|
||||
|
@ -471,7 +471,7 @@ public abstract class AbstractFieldMapper<T> implements FieldMapper<T>, Mapper {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Filter regexpFilter(String value, int flags, @Nullable QueryParseContext parseContext) {
|
||||
public Filter regexpFilter(Object value, int flags, @Nullable QueryParseContext parseContext) {
|
||||
return new RegexpFilter(names().createIndexNameTerm(indexedValueForSearch(value)), flags);
|
||||
}
|
||||
|
||||
|
|
|
@ -225,13 +225,13 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
}
|
||||
|
||||
@Override
|
||||
public Query regexpQuery(String value, int flags, @Nullable MultiTermQuery.RewriteMethod method, @Nullable QueryParseContext context) {
|
||||
public Query regexpQuery(Object value, int flags, @Nullable MultiTermQuery.RewriteMethod method, @Nullable QueryParseContext context) {
|
||||
if (fieldType.indexed() || context == null) {
|
||||
return super.regexpQuery(value, flags, method, context);
|
||||
}
|
||||
Collection<String> queryTypes = context.queryTypes();
|
||||
if (queryTypes.size() == 1) {
|
||||
RegexpQuery regexpQuery = new RegexpQuery(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(Iterables.getFirst(queryTypes, null), value)), flags);
|
||||
RegexpQuery regexpQuery = new RegexpQuery(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(Iterables.getFirst(queryTypes, null), BytesRefs.toBytesRef(value))), flags);
|
||||
if (method != null) {
|
||||
regexpQuery.setRewriteMethod(method);
|
||||
}
|
||||
|
@ -239,7 +239,7 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
}
|
||||
BooleanQuery query = new BooleanQuery();
|
||||
for (String queryType : queryTypes) {
|
||||
RegexpQuery regexpQuery = new RegexpQuery(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(queryType, value)), flags);
|
||||
RegexpQuery regexpQuery = new RegexpQuery(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(queryType, BytesRefs.toBytesRef(value))), flags);
|
||||
if (method != null) {
|
||||
regexpQuery.setRewriteMethod(method);
|
||||
}
|
||||
|
@ -248,17 +248,17 @@ public class IdFieldMapper extends AbstractFieldMapper<String> implements Intern
|
|||
return query;
|
||||
}
|
||||
|
||||
public Filter regexpFilter(String value, int flags, @Nullable QueryParseContext context) {
|
||||
public Filter regexpFilter(Object value, int flags, @Nullable QueryParseContext context) {
|
||||
if (fieldType.indexed() || context == null) {
|
||||
return super.regexpFilter(value, flags, context);
|
||||
}
|
||||
Collection<String> queryTypes = context.queryTypes();
|
||||
if (queryTypes.size() == 1) {
|
||||
return new RegexpFilter(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(Iterables.getFirst(queryTypes, null), value)), flags);
|
||||
return new RegexpFilter(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(Iterables.getFirst(queryTypes, null), BytesRefs.toBytesRef(value))), flags);
|
||||
}
|
||||
XBooleanFilter filter = new XBooleanFilter();
|
||||
for (String queryType : queryTypes) {
|
||||
filter.add(new RegexpFilter(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(queryType, value)), flags), BooleanClause.Occur.SHOULD);
|
||||
filter.add(new RegexpFilter(new Term(UidFieldMapper.NAME, Uid.createUidAsBytes(queryType, BytesRefs.toBytesRef(value))), flags), BooleanClause.Occur.SHOULD);
|
||||
}
|
||||
return filter;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,7 @@ package org.elasticsearch.index.query;
|
|||
import org.apache.lucene.index.Term;
|
||||
import org.apache.lucene.search.Filter;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.lucene.BytesRefs;
|
||||
import org.elasticsearch.common.lucene.search.RegexpFilter;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.cache.filter.support.CacheKeyFilter;
|
||||
|
@ -44,7 +45,7 @@ public class RegexpFilterParser implements FilterParser {
|
|||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{ NAME };
|
||||
return new String[]{NAME};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -55,8 +56,8 @@ public class RegexpFilterParser implements FilterParser {
|
|||
CacheKeyFilter.Key cacheKey = null;
|
||||
String fieldName = null;
|
||||
String secondaryFieldName = null;
|
||||
String value = null;
|
||||
String secondaryValue = null;
|
||||
Object value = null;
|
||||
Object secondaryValue = null;
|
||||
int flagsValue = -1;
|
||||
|
||||
String filterName = null;
|
||||
|
@ -72,7 +73,7 @@ public class RegexpFilterParser implements FilterParser {
|
|||
currentFieldName = parser.currentName();
|
||||
} else {
|
||||
if ("value".equals(currentFieldName)) {
|
||||
value = parser.text();
|
||||
value = parser.objectBytes();
|
||||
} else if ("flags".equals(currentFieldName)) {
|
||||
String flags = parser.textOrNull();
|
||||
flagsValue = RegexpFlag.resolveValue(flags);
|
||||
|
@ -92,7 +93,7 @@ public class RegexpFilterParser implements FilterParser {
|
|||
cacheKey = new CacheKeyFilter.Key(parser.text());
|
||||
} else {
|
||||
secondaryFieldName = currentFieldName;
|
||||
secondaryValue = parser.text();
|
||||
secondaryValue = parser.objectBytes();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -122,7 +123,7 @@ public class RegexpFilterParser implements FilterParser {
|
|||
}
|
||||
}
|
||||
if (filter == null) {
|
||||
filter = new RegexpFilter(new Term(fieldName, value), flagsValue);
|
||||
filter = new RegexpFilter(new Term(fieldName, BytesRefs.toBytesRef(value)), flagsValue);
|
||||
}
|
||||
|
||||
if (cache) {
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.apache.lucene.search.Query;
|
|||
import org.apache.lucene.search.RegexpQuery;
|
||||
import org.apache.lucene.util.automaton.RegExp;
|
||||
import org.elasticsearch.common.inject.Inject;
|
||||
import org.elasticsearch.common.lucene.BytesRefs;
|
||||
import org.elasticsearch.common.xcontent.XContentParser;
|
||||
import org.elasticsearch.index.mapper.MapperService;
|
||||
import org.elasticsearch.index.query.support.QueryParsers;
|
||||
|
@ -46,7 +47,7 @@ public class RegexpQueryParser implements QueryParser {
|
|||
|
||||
@Override
|
||||
public String[] names() {
|
||||
return new String[]{ NAME };
|
||||
return new String[]{NAME};
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -60,7 +61,7 @@ public class RegexpQueryParser implements QueryParser {
|
|||
String fieldName = parser.currentName();
|
||||
String rewriteMethod = null;
|
||||
|
||||
String value = null;
|
||||
Object value = null;
|
||||
float boost = 1.0f;
|
||||
int flagsValue = -1;
|
||||
token = parser.nextToken();
|
||||
|
@ -71,7 +72,7 @@ public class RegexpQueryParser implements QueryParser {
|
|||
currentFieldName = parser.currentName();
|
||||
} else if (token.isValue()) {
|
||||
if ("value".equals(currentFieldName)) {
|
||||
value = parser.text();
|
||||
value = parser.objectBytes();
|
||||
} else if ("boost".equals(currentFieldName)) {
|
||||
boost = parser.floatValue();
|
||||
} else if ("rewrite".equals(currentFieldName)) {
|
||||
|
@ -91,7 +92,7 @@ public class RegexpQueryParser implements QueryParser {
|
|||
}
|
||||
parser.nextToken();
|
||||
} else {
|
||||
value = parser.text();
|
||||
value = parser.objectBytes();
|
||||
parser.nextToken();
|
||||
}
|
||||
|
||||
|
@ -116,7 +117,7 @@ public class RegexpQueryParser implements QueryParser {
|
|||
}
|
||||
}
|
||||
if (query == null) {
|
||||
RegexpQuery regexpQuery = new RegexpQuery(new Term(fieldName, value), flagsValue);
|
||||
RegexpQuery regexpQuery = new RegexpQuery(new Term(fieldName, BytesRefs.toBytesRef(value)), flagsValue);
|
||||
if (method != null) {
|
||||
regexpQuery.setRewriteMethod(method);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue