@Override
 public Query prefixQuery(
     Object value,
     @Nullable MultiTermQuery.RewriteMethod method,
     @Nullable QueryParseContext context) {
   if (fieldType.indexOptions() != IndexOptions.NONE || context == null) {
     return super.prefixQuery(value, method, context);
   }
   Collection<String> queryTypes = context.queryTypes();
   if (queryTypes.size() == 1) {
     PrefixQuery prefixQuery =
         new PrefixQuery(
             new Term(
                 UidFieldMapper.NAME,
                 Uid.createUidAsBytes(
                     Iterables.getFirst(queryTypes, null), BytesRefs.toBytesRef(value))));
     if (method != null) {
       prefixQuery.setRewriteMethod(method);
     }
     return prefixQuery;
   }
   BooleanQuery query = new BooleanQuery();
   for (String queryType : queryTypes) {
     PrefixQuery prefixQuery =
         new PrefixQuery(
             new Term(
                 UidFieldMapper.NAME,
                 Uid.createUidAsBytes(queryType, BytesRefs.toBytesRef(value))));
     if (method != null) {
       prefixQuery.setRewriteMethod(method);
     }
     query.add(prefixQuery, BooleanClause.Occur.SHOULD);
   }
   return query;
 }
 @Override
 public Filter regexpFilter(
     Object value, int flags, int maxDeterminizedStates, @Nullable QueryParseContext context) {
   if (fieldType.indexOptions() != IndexOptions.NONE || context == null) {
     return super.regexpFilter(value, flags, maxDeterminizedStates, context);
   }
   Collection<String> queryTypes = context.queryTypes();
   if (queryTypes.size() == 1) {
     return new RegexpFilter(
         new Term(
             UidFieldMapper.NAME,
             Uid.createUidAsBytes(
                 Iterables.getFirst(queryTypes, null), BytesRefs.toBytesRef(value))),
         flags,
         maxDeterminizedStates);
   }
   XBooleanFilter filter = new XBooleanFilter();
   for (String queryType : queryTypes) {
     filter.add(
         new RegexpFilter(
             new Term(
                 UidFieldMapper.NAME,
                 Uid.createUidAsBytes(queryType, BytesRefs.toBytesRef(value))),
             flags,
             maxDeterminizedStates),
         BooleanClause.Occur.SHOULD);
   }
   return filter;
 }
 @Override
 public Filter termsFilter(List values, @Nullable QueryParseContext context) {
   if (fieldType.indexOptions() != IndexOptions.NONE || context == null) {
     return super.termsFilter(values, context);
   }
   return new TermsFilter(UidFieldMapper.NAME, Uid.createTypeUids(context.queryTypes(), values));
 }
示例#4
0
 @Override
 public Query termsQuery(List values, @Nullable QueryParseContext context) {
   if (indexOptions() != IndexOptions.NONE || context == null) {
     return super.termsQuery(values, context);
   }
   return new TermsQuery(
       UidFieldMapper.NAME, Uid.createUidsForTypesAndIds(context.queryTypes(), values));
 }
示例#5
0
 @Override
 public Query termQuery(Object value, @Nullable QueryParseContext context) {
   if (indexOptions() != IndexOptions.NONE || context == null) {
     return super.termQuery(value, context);
   }
   final BytesRef[] uids = Uid.createUidsForTypesAndId(context.queryTypes(), value);
   return new TermsQuery(UidFieldMapper.NAME, uids);
 }
示例#6
0
 @Override
 public Query regexpQuery(
     String value,
     int flags,
     int maxDeterminizedStates,
     @Nullable MultiTermQuery.RewriteMethod method,
     @Nullable QueryParseContext context) {
   if (indexOptions() != IndexOptions.NONE || context == null) {
     return super.regexpQuery(value, flags, maxDeterminizedStates, 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), BytesRefs.toBytesRef(value))),
             flags,
             maxDeterminizedStates);
     if (method != null) {
       regexpQuery.setRewriteMethod(method);
     }
     return regexpQuery;
   }
   BooleanQuery.Builder query = new BooleanQuery.Builder();
   for (String queryType : queryTypes) {
     RegexpQuery regexpQuery =
         new RegexpQuery(
             new Term(
                 UidFieldMapper.NAME,
                 Uid.createUidAsBytes(queryType, BytesRefs.toBytesRef(value))),
             flags,
             maxDeterminizedStates);
     if (method != null) {
       regexpQuery.setRewriteMethod(method);
     }
     query.add(regexpQuery, BooleanClause.Occur.SHOULD);
   }
   return query.build();
 }
示例#7
0
 @Override
 public Query prefixQuery(
     String value,
     @Nullable MultiTermQuery.RewriteMethod method,
     @Nullable QueryParseContext context) {
   if (indexOptions() != IndexOptions.NONE || context == null) {
     return super.prefixQuery(value, method, context);
   }
   Collection<String> queryTypes = context.queryTypes();
   BooleanQuery.Builder query = new BooleanQuery.Builder();
   for (String queryType : queryTypes) {
     PrefixQuery prefixQuery =
         new PrefixQuery(
             new Term(
                 UidFieldMapper.NAME,
                 Uid.createUidAsBytes(queryType, BytesRefs.toBytesRef(value))));
     if (method != null) {
       prefixQuery.setRewriteMethod(method);
     }
     query.add(prefixQuery, BooleanClause.Occur.SHOULD);
   }
   return query.build();
 }