Ejemplo n.º 1
0
 protected Analyzer getAnalyzer(MappedFieldType fieldType) {
   if (this.analyzer == null) {
     if (fieldType != null) {
       return context.getSearchAnalyzer(fieldType);
     }
     return context.getMapperService().searchAnalyzer();
   } else {
     Analyzer analyzer = context.getMapperService().analysisService().analyzer(this.analyzer);
     if (analyzer == null) {
       throw new IllegalArgumentException("No analyzer found for [" + this.analyzer + "]");
     }
     return analyzer;
   }
 }
    @Override
    public Query termsQuery(List values, @Nullable QueryShardContext context) {
      if (context == null) {
        return super.termsQuery(values, context);
      }

      List<String> types = new ArrayList<>(context.getMapperService().types().size());
      for (DocumentMapper documentMapper : context.getMapperService().docMappers(false)) {
        if (!documentMapper.parentFieldMapper().active()) {
          types.add(documentMapper.type());
        }
      }

      List<BytesRef> bValues = new ArrayList<>(values.size());
      for (Object value : values) {
        BytesRef bValue = BytesRefs.toBytesRef(value);
        if (Uid.hasDelimiter(bValue)) {
          bValues.add(bValue);
        } else {
          // we use all non child types, cause we don't know if its exact or not...
          for (String type : types) {
            bValues.add(Uid.createUidAsBytes(type, bValue));
          }
        }
      }
      return new TermsQuery(name(), bValues);
    }
 @Override
 public SuggestionContext build(QueryShardContext context) throws IOException {
   TermSuggestionContext suggestionContext = new TermSuggestionContext(context);
   // copy over common settings to each suggestion builder
   populateCommonFields(context.getMapperService(), suggestionContext);
   // Transfers the builder settings to the target TermSuggestionContext
   DirectSpellcheckerSettings settings = suggestionContext.getDirectSpellCheckerSettings();
   settings.accuracy(accuracy);
   settings.maxEdits(maxEdits);
   settings.maxInspections(maxInspections);
   settings.maxTermFreq(maxTermFreq);
   settings.minDocFreq(minDocFreq);
   settings.minWordLength(minWordLength);
   settings.prefixLength(prefixLength);
   settings.sort(sort);
   settings.stringDistance(stringDistance.toLucene());
   settings.suggestMode(suggestMode.toLucene());
   settings.exactMatch(exactMatch);
   return suggestionContext;
 }