Skip to content

Commit

Permalink
HSEARCH-436 Implementing metadata interfaces and adding documentation
Browse files Browse the repository at this point in the history
Also reviewing the configuration chapter as whole, restructuring it and fixing typos
  • Loading branch information
hferentschik committed Jul 12, 2013
1 parent aa3f16e commit 527db4f
Show file tree
Hide file tree
Showing 13 changed files with 1,146 additions and 864 deletions.
1,461 changes: 776 additions & 685 deletions documentation/src/main/docbook/en-US/modules/configuration.xml

Large diffs are not rendered by default.

Expand Up @@ -57,6 +57,11 @@
public class TypeMetadata {
private static final Log log = LoggerFactory.make();

/**
* The type for this metadata
*/
private final Class<?> indexedType;

/**
* The class boost for this type (class level @Boost)
*/
Expand Down Expand Up @@ -86,7 +91,7 @@ public class TypeMetadata {
/**
* Metadata for a document field keyed against the field name
*/
private final Map<String, DocumentFieldMetadata> documentFieldNameFieldMetadata;
private final Map<String, DocumentFieldMetadata> documentFieldNameToFieldMetadata;

/**
* Metadata for a Java property (field or getter) keyed the property name
Expand Down Expand Up @@ -153,6 +158,7 @@ public class TypeMetadata {
private final Set<XClass> optimizationBlackList;

protected TypeMetadata(Builder builder) {
this.indexedType = builder.indexedType;
this.boost = builder.boost;
this.scopedAnalyzer = builder.scopedAnalyzer;
this.scopedAnalyzer.setGlobalAnalyzer( builder.analyzer );
Expand All @@ -170,10 +176,14 @@ protected TypeMetadata(Builder builder) {
this.classBridgeFields = Collections.unmodifiableSet( builder.classBridgeFields );
this.propertyMetadataSet = Collections.unmodifiableSet( builder.propertyMetadataList );
this.propertyGetterNameToPropertyMetadata = keyPropertyMetadata( builder.propertyMetadataList );
this.documentFieldNameFieldMetadata = keyFieldMetadata( builder.propertyMetadataList );
this.documentFieldNameToFieldMetadata = keyFieldMetadata( builder.propertyMetadataList );
this.classBridgeFieldNameToDocumentFieldMetadata = copyClassBridgeMetadata( builder.classBridgeFields );
}

public Class<?> getType() {
return indexedType;
}

public Set<PropertyMetadata> getAllPropertyMetadata() {
return propertyMetadataSet;
}
Expand All @@ -191,11 +201,7 @@ public Set<DocumentFieldMetadata> getClassBridgeMetadata() {
}

public DocumentFieldMetadata getDocumentFieldMetadataFor(String fieldName) {
return documentFieldNameFieldMetadata.get( fieldName );
}

public Set<String> getAllFieldNames() {
return documentFieldNameFieldMetadata.keySet();
return documentFieldNameToFieldMetadata.get( fieldName );
}

public Set<EmbeddedTypeMetadata> getEmbeddedTypeMetadata() {
Expand Down Expand Up @@ -278,7 +284,7 @@ public String toString() {
sb.append( ", discriminator=" ).append( discriminator );
sb.append( ", discriminatorGetter=" ).append( discriminatorGetter );
sb.append( ", classBoostStrategy=" ).append( classBoostStrategy );
sb.append( ", documentFieldNameToFieldMetadata=" ).append( documentFieldNameFieldMetadata );
sb.append( ", documentFieldNameToFieldMetadata=" ).append( documentFieldNameToFieldMetadata );
sb.append( ", propertyGetterNameToFieldMetadata=" ).append( propertyGetterNameToPropertyMetadata );
sb.append( ", idPropertyMetadata=" ).append( idPropertyMetadata );
sb.append( ", classBridgeFields=" ).append( classBridgeFieldNameToDocumentFieldMetadata );
Expand Down
Expand Up @@ -448,7 +448,7 @@ public IndexedTypeDescriptor getIndexedTypeDescriptor(Class<?> entityType) {
EntityIndexBinding indexBinder = indexBindingForEntities.get( entityType );
IndexedTypeDescriptor indexedTypeDescriptor;
if ( indexBinder == null ) {
indexedTypeDescriptor = IndexedTypeDescriptorForUnindexedType.INSTANCE;
indexedTypeDescriptor = new IndexedTypeDescriptorForUnindexedType(entityType);
}
else {
indexedTypeDescriptor = new IndexedTypeDescriptorImpl(
Expand Down
Expand Up @@ -27,7 +27,9 @@
import org.hibernate.search.bridge.FieldBridge;

/**
* Metadata related to a single indexed field.
* Metadata related to a single field. It extends @{code FieldSettingsDescriptor} to add Search specific
* information, like {@link #indexNullAs()}. It also contains the analyzer and field bridge used to create the
* actual field for the Lucene {@code Document}.
*
* @author Hardy Ferentschik
*/
Expand All @@ -50,19 +52,6 @@ public interface FieldDescriptor extends FieldSettingsDescriptor {
*/
boolean indexNull();

/**
* @return the numeric precision step in case this field is indexed as a numeric value. If the field is not numeric
* {@code null} is returned.
*/
Integer precisionStep();

/**
* @return {@code true} if this field is indexed as numeric field, {@code false} otherwise
*
* @see #precisionStep()
*/
boolean isNumeric();

/**
* @return the field bridge instance used to convert the property value into a string based field value
*/
Expand All @@ -83,7 +72,7 @@ public static enum Type {
ID,

/**
* A basic field generate by a field bridge
* A basic field generated by a field bridge
*/
BASIC
}
Expand Down
Expand Up @@ -31,7 +31,9 @@
import org.hibernate.search.annotations.TermVector;

/**
* Metadata related to a single indexed field focusing on the Lucene field settings.
* Metadata related to a single Lucene Document field and its options. Some of the values in this interface do not have
* a direct counterpart in the Lucene works, but are an abstraction of Hibernate Search and mapped to the appropriate Lucene
* construct.
*
* @author Hardy Ferentschik
*/
Expand Down Expand Up @@ -72,4 +74,19 @@ public interface FieldSettingsDescriptor {
* @return the boost value for this field. 1 being the default value.
*/
float getBoost();

/**
* @return the numeric precision step in case this field is indexed as a numeric value. If the field is not numeric
* {@code null} is returned.
*/
Integer precisionStep();

/**
* @return {@code true} if this field is indexed as numeric field, {@code false} otherwise
*
* @see #precisionStep()
*/
boolean isNumeric();
}


Expand Up @@ -28,11 +28,17 @@
import org.hibernate.search.engine.BoostStrategy;

/**
* Top level descriptor of the metadata API. Giving access to the indexing information for a single entity.
* Top level descriptor of the metadata API. Giving access to the indexing information for a single type.
*
* @author Hardy Ferentschik
*/
public interface IndexedTypeDescriptor extends FieldContributor {

/**
* @return the type for which this descriptor provides meta information
*/
Class<?> getType();

/**
* @return {@code true} if the type for this descriptor is indexed, {@code false} otherwise
*/
Expand All @@ -43,6 +49,17 @@ public interface IndexedTypeDescriptor extends FieldContributor {
*/
boolean isSharded();

/**
* Returns a set of {@code IndexDescriptor} instances describing Lucene index information, in particular the index name.
* The index name can also be used to retrieve the actual {@code IndexManager} for this index via
* {@link org.hibernate.search.engine.spi.SearchFactoryImplementor#getIndexManagerHolder()#getIndexManager(String)}.
*
* For non sharded indexes there will be only a single {@code IndexDescriptor}. The empty set is returned for an unindexed type
*
* @return a set of {@code IndexDescriptor} instances describing Lucene index information
*/
Set<IndexDescriptor> getIndexDescriptors();

/**
* @return the class boost value, 1 being the default.
*/
Expand All @@ -54,12 +71,6 @@ public interface IndexedTypeDescriptor extends FieldContributor {
*/
BoostStrategy getDynamicBoost();

/**
* @return a set of {@code IndexDescriptor} instances describing Lucene index information. For non sharded indexes
* there will be only a single {@code IndexDescriptor}. The empty set is returned for an unindexed type
*/
Set<IndexDescriptor> getIndexDescriptors();

/**
* @return the set of indexed properties in form of {@code PropertyDescriptor}s
*/
Expand All @@ -80,11 +91,9 @@ public interface IndexedTypeDescriptor extends FieldContributor {
* Returns the set of index descriptors for the indexed field generated by the property with the given name.
*
* @param propertyName the property name
* @param accessTypes Optional specification of the access type (field vs getter). If no explicit accessType is given all
* {@code FieldDescriptor}s for contributed by the specified property are returned, independent of the access type.
*
* @return the set of index descriptors for the indexed field generated by the property with the given name. The empty set
* is returned in case the property does not exist or does not produce any indexed fields.
*/
Set<FieldDescriptor> getFieldsForProperty(String propertyName, PropertyDescriptor.AccessType... accessTypes);
Set<FieldDescriptor> getFieldsForProperty(String propertyName);
}
Expand Up @@ -32,27 +32,9 @@ public interface PropertyDescriptor extends FieldContributor {
*
* @return name of the property
*/
String getPropertyName();
String getName();

/*
* @return the type with which the property will be accessed
*/
AccessType getPropertyAccess();

/**
* Enum defining how a property is accessed
*/
public static enum AccessType {
/**
* Access via the field instance
*/
FIELD,

/**
* Access via the property getter
*/
METHOD
}
}


Expand Up @@ -40,7 +40,6 @@
*/
public class FieldDescriptorImpl implements FieldDescriptor {
private final String name;
private final boolean isId;
private final Index index;
private final Analyze analyze;
private final Store store;
Expand All @@ -52,10 +51,10 @@ public class FieldDescriptorImpl implements FieldDescriptor {
private final FieldBridge fieldBridge;
private final boolean numeric;
private final Integer precisionStep;
private final Type fieldType;

public FieldDescriptorImpl(DocumentFieldMetadata documentFieldMetadata) {
this.name = documentFieldMetadata.getName();
this.isId = documentFieldMetadata.isId();
this.index = determineIndexType( documentFieldMetadata.getIndex() );
this.analyze = determineAnalyzeType( documentFieldMetadata.getIndex() );
this.store = documentFieldMetadata.getStore();
Expand All @@ -67,17 +66,17 @@ public FieldDescriptorImpl(DocumentFieldMetadata documentFieldMetadata) {
this.fieldBridge = documentFieldMetadata.getFieldBridge();
this.numeric = documentFieldMetadata.isNumeric();
this.precisionStep = documentFieldMetadata.isNumeric() ? documentFieldMetadata.getPrecisionStep() : null;
this.fieldType = determineFieldType( documentFieldMetadata );
}

@Override
public String getName() {
return name;
}

// TODO - HSEARCH-436
@Override
public Type getFieldType() {
return null; //To change body of implemented methods use File | Settings | File Templates.
return fieldType;
}

@Override
Expand Down Expand Up @@ -144,7 +143,6 @@ public Analyzer getAnalyzer() {
public String toString() {
final StringBuilder sb = new StringBuilder( "FieldDescriptorImpl{" );
sb.append( "name='" ).append( name ).append( '\'' );
sb.append( ", isId=" ).append( isId );
sb.append( ", index=" ).append( index );
sb.append( ", analyze=" ).append( analyze );
sb.append( ", store=" ).append( store );
Expand All @@ -156,10 +154,20 @@ public String toString() {
sb.append( ", fieldBridge=" ).append( fieldBridge );
sb.append( ", numeric=" ).append( numeric );
sb.append( ", precisionStep=" ).append( precisionStep );
sb.append( ", fieldType=" ).append( fieldType );
sb.append( '}' );
return sb.toString();
}

private Type determineFieldType(DocumentFieldMetadata documentFieldMetadata) {
if ( documentFieldMetadata.isId() ) {
return Type.ID;
}
else {
return Type.BASIC;
}
}

private Index determineIndexType(Field.Index index) {
if ( Field.Index.NO.equals( index ) ) {
return Index.NO;
Expand Down
Expand Up @@ -32,9 +32,8 @@
public class IndexDescriptorImpl implements IndexDescriptor {
private final String indexName;

// TODO - HSEARCH-436 fix constructor arguments
public IndexDescriptorImpl(IndexManager[] indexManagers) {
indexName = indexManagers[0].getIndexName();
public IndexDescriptorImpl(IndexManager indexManager) {
indexName = indexManager.getIndexName();
}

@Override
Expand Down
Expand Up @@ -39,9 +39,15 @@
* @author Hardy Ferentschik
*/
public class IndexedTypeDescriptorForUnindexedType implements IndexedTypeDescriptor {
public static final IndexedTypeDescriptor INSTANCE = new IndexedTypeDescriptorForUnindexedType();
private final Class<?> type;

private IndexedTypeDescriptorForUnindexedType() {
public IndexedTypeDescriptorForUnindexedType(Class<?> type) {
this.type = type;
}

@Override
public Class<?> getType() {
return type;
}

@Override
Expand Down Expand Up @@ -85,9 +91,17 @@ public FieldDescriptor getIndexedField(String fieldName) {
}

@Override
public Set<FieldDescriptor> getFieldsForProperty(String propertyName, PropertyDescriptor.AccessType... accessTypes) {
public Set<FieldDescriptor> getFieldsForProperty(String propertyName) {
return Collections.emptySet();
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder( "IndexedTypeDescriptorForUnindexedType{" );
sb.append( "type=" ).append( type );
sb.append( '}' );
return sb.toString();
}
}


0 comments on commit 527db4f

Please sign in to comment.