Skip to content

Commit

Permalink
HSEARCH-2451 Add relative field names to the internal metadata
Browse files Browse the repository at this point in the history
Preliminary work for HSEARCH-2451.
  • Loading branch information
yrodiere authored and gsmet committed Nov 23, 2016
1 parent aaa9e6b commit cce869f
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 19 deletions.
Expand Up @@ -275,7 +275,7 @@ private void createPropertyMetadataForEmbeddedId(XProperty member, TypeMetadata.
new DocumentFieldMetadata.Builder(
typeMetadataBuilder.getResultReference(),
propertyMetadataBuilder.getResultReference(),
absoluteFieldName, Store.YES, index, termVector
absoluteFieldName, relativeFieldName, Store.YES, index, termVector
)
.boost( AnnotationProcessingHelper.getBoost( member, null ) )
.fieldBridge( fieldBridge )
Expand Down Expand Up @@ -359,7 +359,7 @@ private void createIdPropertyMetadata(XProperty member,
DocumentFieldMetadata.Builder idMetadataBuilder = new DocumentFieldMetadata.Builder(
typeMetadataBuilder.getResultReference(),
propertyMetadataBuilder.getResultReference(),
absoluteFieldName,
absoluteFieldName, relativeFieldName,
Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS,
termVector
Expand Down Expand Up @@ -467,7 +467,7 @@ private void initializeProvidedIdMetadata(String prefix, ProvidedId providedId,
new DocumentFieldMetadata.Builder(
typeMetadataBuilder.getResultReference(),
propertyMetadataBuilder.getResultReference(),
absoluteFieldName,
absoluteFieldName, relativeFieldName,
Store.YES,
Field.Index.NOT_ANALYZED_NO_NORMS,
Field.TermVector.NO
Expand Down Expand Up @@ -742,7 +742,7 @@ private void bindClassBridgeAnnotation(String prefix,
new DocumentFieldMetadata.Builder(
typeMetadataBuilder.getResultReference(),
BackReference.<PropertyMetadata>empty(), // Class bridge, there's no related property
absoluteFieldName, store, index, termVector
absoluteFieldName, relativeFieldName, store, index, termVector
)
.boost( classBridgeAnnotation.boost().value() )
.fieldBridge( fieldBridge );
Expand Down Expand Up @@ -793,7 +793,7 @@ private void bindSpatialAnnotation(Spatial spatialAnnotation,
new DocumentFieldMetadata.Builder(
typeMetadataBuilder.getResultReference(),
propertyMetadataBuilder.getResultReference(),
absoluteFieldName, store, index, termVector
absoluteFieldName, relativeFieldName, store, index, termVector
)
.boost( AnnotationProcessingHelper.getBoost( member, spatialAnnotation ) )
.fieldBridge( fieldBridge )
Expand Down Expand Up @@ -840,7 +840,7 @@ private void bindSpatialAnnotation(Spatial spatialAnnotation,
new DocumentFieldMetadata.Builder(
typeMetadataBuilder.getResultReference(),
BackReference.<PropertyMetadata>empty(), // Class-level spatial annotation, there's no related property
absoluteFieldName, store, index, termVector
absoluteFieldName, relativeFieldName, store, index, termVector
)
.boost( spatialAnnotation.boost().value() )
.fieldBridge( spatialBridge )
Expand Down Expand Up @@ -1289,7 +1289,7 @@ private void bindFieldAnnotation(
fieldMetadataBuilder = new DocumentFieldMetadata.Builder(
typeMetadataBuilder.getResultReference(),
propertyMetadataBuilder.getResultReference(),
absoluteFieldName,
absoluteFieldName, relativeFieldName,
store,
Field.Index.NO.equals( index ) ? index : Field.Index.NOT_ANALYZED_NO_NORMS,
termVector
Expand All @@ -1305,7 +1305,7 @@ private void bindFieldAnnotation(
fieldMetadataBuilder = new DocumentFieldMetadata.Builder(
typeMetadataBuilder.getResultReference(),
propertyMetadataBuilder.getResultReference(),
absoluteFieldName,
absoluteFieldName, relativeFieldName,
store,
index,
termVector
Expand All @@ -1323,14 +1323,13 @@ private void bindFieldAnnotation(
throw log.attemptToFacetOnAnalyzedField( absoluteFieldName, member.getDeclaringClass().getName() );
}
String relativeFacetFieldName = facetAnnotation.name();
String absoluteFacetFieldName;
if ( facetAnnotation.name().isEmpty() ) {
absoluteFacetFieldName = absoluteFieldName; // if not explicitly set the facet name is the same as the field name
if ( relativeFacetFieldName.isEmpty() ) {
relativeFacetFieldName = relativeFieldName; // if not explicitly set the facet name is the same as the field name
}
else {
absoluteFacetFieldName = prefix + relativeFacetFieldName;
}
FacetMetadata.Builder facetMetadataBuilder = new FacetMetadata.Builder( absoluteFacetFieldName );
String absoluteFacetFieldName = prefix + relativeFacetFieldName;
FacetMetadata.Builder facetMetadataBuilder = new FacetMetadata.Builder(
absoluteFacetFieldName, relativeFacetFieldName
);
FacetEncodingType facetEncodingType = determineFacetEncodingType( member, facetAnnotation );
facetMetadataBuilder.setFacetEncoding( facetEncodingType );
fieldMetadataBuilder.addFacetMetadata( facetMetadataBuilder.build() );
Expand Down
Expand Up @@ -33,6 +33,7 @@ public class DocumentFieldMetadata {
private final BackReference<PropertyMetadata> sourceProperty;

private final String absoluteName;
private final String relativeName;
private final Store store;
private final Field.Index index;
private final Field.TermVector termVector;
Expand Down Expand Up @@ -61,6 +62,7 @@ private DocumentFieldMetadata(Builder builder) {
this.sourceProperty = builder.sourceProperty;

this.absoluteName = builder.absoluteName;
this.relativeName = builder.relativeName;
this.store = builder.store;
this.index = builder.index;
this.termVector = builder.termVector;
Expand Down Expand Up @@ -102,6 +104,13 @@ public String getAbsoluteName() {
return absoluteName;
}

/**
* @return The name of this field excluding any indexed-embedded prefix.
*/
public String getRelativeName() {
return relativeName;
}

public boolean isId() {
return isId;
}
Expand Down Expand Up @@ -196,6 +205,7 @@ public static class Builder {
private final BackReference<TypeMetadata> sourceType;
private final BackReference<PropertyMetadata> sourceProperty;
private final String absoluteName;
private final String relativeName;
private final Store store;
private final Field.Index index;
private final Field.TermVector termVector;
Expand All @@ -216,13 +226,14 @@ public static class Builder {

public Builder(BackReference<TypeMetadata> sourceType,
BackReference<PropertyMetadata> sourceProperty,
String absoluteName,
String absoluteName, String relativeName,
Store store,
Field.Index index,
Field.TermVector termVector) {
this.sourceType = sourceType;
this.sourceProperty = sourceProperty;
this.absoluteName = absoluteName;
this.relativeName = relativeName;
this.store = store;
this.index = index;
this.termVector = termVector;
Expand All @@ -234,6 +245,10 @@ public String getAbsoluteName() {
return absoluteName;
}

public String getRelativeName() {
return relativeName;
}

public Builder fieldBridge(FieldBridge fieldBridge) {
this.fieldBridge = fieldBridge;
return this;
Expand Down
Expand Up @@ -17,10 +17,13 @@ public class FacetMetadata {

private final String absoluteName;

private final String relativeName;

private final FacetEncodingType encoding;

private FacetMetadata(Builder builder) {
this.absoluteName = builder.absoluteName;
this.relativeName = builder.relativeName;
this.encoding = builder.encoding;
}

Expand All @@ -31,19 +34,28 @@ public String getAbsoluteName() {
return absoluteName;
}

/**
* @return The name of the facet field excluding any indexed-embedded prefix.
*/
public String getRelativeName() {
return relativeName;
}

public FacetEncodingType getEncoding() {
return encoding;
}

public static class Builder {
// required parameters
private final String absoluteName;
private final String relativeName;

// optional parameters
private FacetEncodingType encoding = FacetEncodingType.AUTO;

public Builder(String absoluteName) {
public Builder(String absoluteName, String relativeName) {
this.absoluteName = absoluteName;
this.relativeName = relativeName;
}

public void setFacetEncoding(FacetEncodingType encoding) {
Expand All @@ -59,6 +71,7 @@ public FacetMetadata build() {
public String toString() {
return "FacetMetadata{" +
"absoluteName='" + absoluteName + '\'' +
"relativeName='" + relativeName + '\'' +
", encoding=" + encoding +
'}';
}
Expand Down
Expand Up @@ -102,7 +102,7 @@ public class DocumentBuilderIndexedEntity extends AbstractDocumentBuilder {
new DocumentFieldMetadata.Builder(
BackReference.<TypeMetadata>empty(),
BackReference.<PropertyMetadata>empty(),
null,
null, null, // No field name
Store.NO,
Field.Index.NOT_ANALYZED_NO_NORMS,
Field.TermVector.NO
Expand Down
Expand Up @@ -55,7 +55,8 @@ public void setUp() {
new DocumentFieldMetadata.Builder(
new BackReference<TypeMetadata>(),
new BackReference<PropertyMetadata>(),
null, Store.YES, Field.Index.ANALYZED, Field.TermVector.NO
null, null, // No field name
Store.YES, Field.Index.ANALYZED, Field.TermVector.NO
)
.boost( 0F )
.build();
Expand Down

0 comments on commit cce869f

Please sign in to comment.