Skip to content

Commit

Permalink
HSEARCH-3039 Register a pass through analyzer for the id field
Browse files Browse the repository at this point in the history
  • Loading branch information
gsmet authored and yrodiere committed Apr 10, 2018
1 parent 4e83f7d commit 2ef4c8a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
Expand Up @@ -385,6 +385,11 @@ private void createIdPropertyMetadata(XProperty member,

Field.TermVector termVector = AnnotationProcessingHelper.getTermVector( TermVector.NO );

if ( !parseContext.skipAnalyzers() ) {
// Register a pass through analyzer for the document id
typeMetadataBuilder.addToScopedAnalyzerReference( fieldPath, null, Field.Index.NOT_ANALYZED );
}

PropertyMetadata.Builder propertyMetadataBuilder = new PropertyMetadata.Builder(
typeMetadataBuilder.getResultReference(), member,
reflectionManager.toClass( member.getType() ) );
Expand Down
Expand Up @@ -603,14 +603,14 @@ public void disableStateInspectionOptimization() {

@SuppressWarnings( "deprecation" )
public AnalyzerReference addToScopedAnalyzerReference(DocumentFieldPath fieldPath, AnalyzerReference analyzerReference, Field.Index index) {
if ( analyzerReference == null ) {
analyzerReference = scopedAnalyzerReferenceBuilder.getGlobalAnalyzerReference();
}

if ( !index.isAnalyzed() ) {
// no analyzer is used, add a pass-through (i.e. no-op) analyzer for queries
analyzerReference = analyzerRegistry.getPassThroughAnalyzerReference();
}
else if ( analyzerReference == null ) {
// no analyzer set, we use the default analyzer
analyzerReference = scopedAnalyzerReferenceBuilder.getGlobalAnalyzerReference();
}

scopedAnalyzerReferenceBuilder.addAnalyzerReference( fieldPath.getAbsoluteName(), analyzerReference );

Expand Down
Expand Up @@ -221,6 +221,20 @@ public void testBlankQueryString() {
.matchesNone();
}

@Test
@TestForIssue(jiraKey = "HSEARCH-3039")
public void testSearchOnDocumentId() {
QueryBuilder qb = getCoffeeQueryBuilder();

Query query = qb.simpleQueryString()
.onFields( "id" )
.matching( "Caramelito" )
.createQuery();

helper.assertThat( query ).from( Coffee.class )
.matchesExactlyIds( "Caramelito" );
}

private QueryBuilder getCoffeeQueryBuilder() {
return helper.queryBuilder( Coffee.class );
}
Expand Down

0 comments on commit 2ef4c8a

Please sign in to comment.