Mappers: also use `name` as a smart lookup for field/property on top of indexName and fullName, closes #309.

This commit is contained in:
kimchy 2010-08-10 16:14:15 +03:00
parent 879191c435
commit 61bb9d0ff9
3 changed files with 19 additions and 4 deletions

View File

@ -26,6 +26,7 @@
<w>cloudservers</w>
<w>commitable</w>
<w>committable</w>
<w>concat</w>
<w>conf</w>
<w>configurator</w>
<w>coord</w>

View File

@ -112,14 +112,19 @@ public class DocumentFieldMappers implements Iterable<FieldMapper> {
}
/**
* Tries to find first based on {@link #fullName(String)}, then by {@link #indexName(String)}.
* Tries to find first based on {@link #fullName(String)}, then by {@link #indexName(String)}, and last
* by {@link #name(String)}.
*/
public FieldMappers smartName(String name) {
FieldMappers fieldMappers = fullName(name);
if (fieldMappers != null) {
return fieldMappers;
}
return indexName(name);
fieldMappers = indexName(name);
if (fieldMappers != null) {
return fieldMappers;
}
return name(name);
}
public FieldMapper smartNameFieldMapper(String name) {

View File

@ -259,7 +259,11 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
if (mappers != null) {
return mappers;
}
return indexName(smartName);
mappers = indexName(smartName);
if (mappers != null) {
return mappers;
}
return name(smartName);
}
/**
@ -269,7 +273,8 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
*
* <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).
* 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>If nothing is found, returns null.
*/
@ -294,6 +299,10 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
if (fieldMappers != null) {
return new SmartNameFieldMappers(fieldMappers, null);
}
fieldMappers = name(smartName);
if (fieldMappers != null) {
return new SmartNameFieldMappers(fieldMappers, null);
}
return null;
}