// the property is not called "id"
@Test
@TestForIssue(jiraKey = "HSEARCH-901")
public void testIdentifierNaming() throws InterruptedException {
//disable automatic indexing, to test manual index creation.
FullTextSessionBuilder ftsb = new FullTextSessionBuilder()
.setProperty( Environment.ANALYZER_CLASS, StandardAnalyzer.class.getName() )
.addAnnotatedClass( Dvd.class )
.addAnnotatedClass( Nation.class )
.addAnnotatedClass( Book.class )
.addAnnotatedClass( WeirdlyIdentifiedEntity.class )
.setProperty( Environment.INDEXING_STRATEGY, "manual" )
.build();
{
//creating the test data in database only:
FullTextSession fullTextSession = ftsb.openFullTextSession();
Transaction transaction = fullTextSession.beginTransaction();
Nation us = new Nation( "United States of America", "US" );
fullTextSession.persist( us );
Dvd dvda = new Dvd();
dvda.setTitle( "Star Trek (episode 96367)" );
dvda.setFirstPublishedIn( us );
fullTextSession.save( dvda );
Dvd dvdb = new Dvd();
dvdb.setTitle( "The Trek" );
dvdb.setFirstPublishedIn( us );
fullTextSession.save( dvdb );
WeirdlyIdentifiedEntity entity = new WeirdlyIdentifiedEntity();
entity.setId( "not an identifier" );
fullTextSession.save( entity );
transaction.commit();
fullTextSession.close();
}
{
//verify index is still empty:
assertEquals( 0, countResults( new Term( "title", "trek" ), ftsb, Dvd.class ) );
assertEquals( 0, countResults( new Term( "id", "not" ), ftsb, WeirdlyIdentifiedEntity.class ) );
}
{
FullTextSession fullTextSession = ftsb.openFullTextSession();
fullTextSession.createIndexer( Dvd.class )
.startAndWait();
fullTextSession.close();
}
{
//verify index is now containing both DVDs:
assertEquals( 2, countResults( new Term( "title", "trek" ), ftsb, Dvd.class ) );
}
{
FullTextSession fullTextSession = ftsb.openFullTextSession();
fullTextSession.createIndexer( WeirdlyIdentifiedEntity.class )
.startAndWait();
fullTextSession.close();
}
{
//verify index is now containing the weirdly identified entity:
assertEquals( 1, countResults( new Term( "id", "identifier" ), ftsb, WeirdlyIdentifiedEntity.class ) );
}
ftsb.close();
}