コード例 #1
0
 public SmartNameFieldMappers smartName(String smartName, @Nullable String[] types) {
   if (types == null || types.length == 0) {
     return smartName(smartName);
   }
   if (types.length == 1 && types[0].equals("_all")) {
     return smartName(smartName);
   }
   for (String type : types) {
     DocumentMapper documentMapper = mappers.get(type);
     // we found a mapper
     if (documentMapper != null) {
       // see if we find a field for it
       FieldMappers mappers = documentMapper.mappers().smartName(smartName);
       if (mappers != null) {
         return new SmartNameFieldMappers(this, mappers, documentMapper, false);
       }
     }
   }
   // did not find explicit field in the type provided, see if its prefixed with type
   int dotIndex = smartName.indexOf('.');
   if (dotIndex != -1) {
     String possibleType = smartName.substring(0, dotIndex);
     DocumentMapper possibleDocMapper = mappers.get(possibleType);
     if (possibleDocMapper != null) {
       String possibleName = smartName.substring(dotIndex + 1);
       FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
       if (mappers != null) {
         return new SmartNameFieldMappers(this, mappers, possibleDocMapper, true);
       }
     }
   }
   // we did not find the field mapping in any of the types, so don't go and try to find
   // it in other types...
   return null;
 }
コード例 #2
0
 /**
  * Returns smart field mappers based on a smart name. A smart name is one that can optioannly be
  * prefixed with a type (and then a '.'). If it is, then the {@link
  * MapperService.SmartNameFieldMappers} will have the doc mapper set.
  *
  * <p>
  *
  * <p>It also (without the optional type prefix) try and find the {@link FieldMappers} for the
  * specific name. It will first try to find it based on the full name (with the dots if its a
  * compound name). If it is not found, will try and find it based on the indexName (which can be
  * controlled in the mapping), and last, will try it based no the name itself.
  *
  * <p>
  *
  * <p>If nothing is found, returns null.
  */
 public SmartNameFieldMappers smartName(String smartName) {
   int dotIndex = smartName.indexOf('.');
   if (dotIndex != -1) {
     String possibleType = smartName.substring(0, dotIndex);
     DocumentMapper possibleDocMapper = mappers.get(possibleType);
     if (possibleDocMapper != null) {
       String possibleName = smartName.substring(dotIndex + 1);
       FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
       if (mappers != null) {
         return new SmartNameFieldMappers(this, mappers, possibleDocMapper, true);
       }
     }
   }
   FieldMappers fieldMappers = fullName(smartName);
   if (fieldMappers != null) {
     return new SmartNameFieldMappers(this, fieldMappers, null, false);
   }
   fieldMappers = indexName(smartName);
   if (fieldMappers != null) {
     return new SmartNameFieldMappers(this, fieldMappers, null, false);
   }
   fieldMappers = name(smartName);
   if (fieldMappers != null) {
     return new SmartNameFieldMappers(this, fieldMappers, null, false);
   }
   return null;
 }
コード例 #3
0
    @Override
    protected Analyzer getWrappedAnalyzer(String fieldName) {
      int dotIndex = fieldName.indexOf('.');
      if (dotIndex != -1) {
        String possibleType = fieldName.substring(0, dotIndex);
        DocumentMapper possibleDocMapper = mappers.get(possibleType);
        if (possibleDocMapper != null) {
          return possibleDocMapper.mappers().searchQuoteAnalyzer();
        }
      }
      FieldMappers mappers = fieldMappers.fullName(fieldName);
      if (mappers != null
          && mappers.mapper() != null
          && mappers.mapper().searchQuoteAnalyzer() != null) {
        return mappers.mapper().searchQuoteAnalyzer();
      }

      mappers = fieldMappers.indexName(fieldName);
      if (mappers != null
          && mappers.mapper() != null
          && mappers.mapper().searchQuoteAnalyzer() != null) {
        return mappers.mapper().searchQuoteAnalyzer();
      }
      return defaultAnalyzer;
    }
コード例 #4
0
 /**
  * Returns all the fields that match the given pattern. If the pattern is prefixed with a type
  * then the fields will be returned with a type prefix.
  */
 public Set<String> simpleMatchToIndexNames(String pattern) {
   if (!Regex.isSimpleMatchPattern(pattern)) {
     return ImmutableSet.of(pattern);
   }
   int dotIndex = pattern.indexOf('.');
   if (dotIndex != -1) {
     String possibleType = pattern.substring(0, dotIndex);
     DocumentMapper possibleDocMapper = mappers.get(possibleType);
     if (possibleDocMapper != null) {
       Set<String> typedFields = Sets.newHashSet();
       for (String indexName : possibleDocMapper.mappers().simpleMatchToIndexNames(pattern)) {
         typedFields.add(possibleType + "." + indexName);
       }
       return typedFields;
     }
   }
   return fieldMappers.simpleMatchToIndexNames(pattern);
 }
コード例 #5
0
 /**
  * Returns all the fields that match the given pattern, with an optional narrowing based on a list
  * of types.
  */
 public Set<String> simpleMatchToIndexNames(String pattern, @Nullable String[] types) {
   if (types == null || types.length == 0) {
     return simpleMatchToIndexNames(pattern);
   }
   if (types.length == 1 && types[0].equals("_all")) {
     return simpleMatchToIndexNames(pattern);
   }
   if (!Regex.isSimpleMatchPattern(pattern)) {
     return ImmutableSet.of(pattern);
   }
   Set<String> fields = Sets.newHashSet();
   for (String type : types) {
     DocumentMapper possibleDocMapper = mappers.get(type);
     if (possibleDocMapper != null) {
       for (String indexName : possibleDocMapper.mappers().simpleMatchToIndexNames(pattern)) {
         fields.add(indexName);
       }
     }
   }
   return fields;
 }
コード例 #6
0
  private void removeObjectAndFieldMappers(DocumentMapper docMapper) {
    synchronized (mappersMutex) {
      fieldMappers.removeMappers(docMapper.mappers());

      ImmutableOpenMap.Builder<String, ObjectMappers> fullPathObjectMappers =
          ImmutableOpenMap.builder(this.fullPathObjectMappers);
      for (ObjectMapper mapper : docMapper.objectMappers().values()) {
        ObjectMappers mappers = fullPathObjectMappers.get(mapper.fullPath());
        if (mappers != null) {
          mappers = mappers.remove(mapper);
          if (mappers.isEmpty()) {
            fullPathObjectMappers.remove(mapper.fullPath());
          } else {
            fullPathObjectMappers.put(mapper.fullPath(), mappers);
          }
        }
      }

      this.fullPathObjectMappers = fullPathObjectMappers.build();
    }
  }
コード例 #7
0
 /** Same as {@link #smartName(String)}, except it returns just the field mappers. */
 public FieldMappers smartNameFieldMappers(String smartName) {
   int dotIndex = smartName.indexOf('.');
   if (dotIndex != -1) {
     String possibleType = smartName.substring(0, dotIndex);
     DocumentMapper possibleDocMapper = mappers.get(possibleType);
     if (possibleDocMapper != null) {
       String possibleName = smartName.substring(dotIndex + 1);
       FieldMappers mappers = possibleDocMapper.mappers().smartName(possibleName);
       if (mappers != null) {
         return mappers;
       }
     }
   }
   FieldMappers mappers = fullName(smartName);
   if (mappers != null) {
     return mappers;
   }
   mappers = indexName(smartName);
   if (mappers != null) {
     return mappers;
   }
   return name(smartName);
 }