Hello,
Im using spring 4.1.2.Final,
Hibernate-search 4.2.0.Final
I have a strange behavior in my code.
I send an update request to change the string value of a field in a class.
With Luke I can see that the index has been updated with the new value I have set on the field.
Searching for the new field value in Luke will return a successful result, this is correct.
Searching for the old value in Luke will not return any value, this is correct.
Sending a request in my implemented code to retrive the value will only work with the old value...?
It seems like the old value is cached somewhere..
After restarting the application I do get a search result for the new value.
The index is rebuild when staring the application.
My entity class
Code:
@Entity
@DynamicUpdate(value = true)
@Indexed
public class DAvtal extends DomanObjekt {
@DocumentId
@Id
@Column(name = "AVTAL_ID")
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "AVTAL_SEQ_GEN")
@GenericGenerator(name = "AVTAL_SEQ_GEN", strategy = "sequence", parameters = {@Parameter(name = "sequence", value = "SEQ_AVTAL")})
private Long avtalId;
@Field(index = Index.YES, analyze = Analyze.YES, store = Store.NO)
@Analyzer(definition = "customanalyzer")
@Column(name = "ALTERNATIVT_NAMN")
private String alternativtNamn;
}
This is specified in the superclass
Code:
@AnalyzerDef(name = "customanalyzer",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = {@Parameter(name = "language", value = "Swedish")})
})
The query should not really be relevant since it works but it looks like this.
Code:
public List<DUtforandeVerksamhet> sokUtforandeverksamhetFritext(String fritext, int sidnummer, int sidstorlek) {
FullTextEntityManager fullTextEntityManager = Search.getFullTextEntityManager(this.getEntityManager());
QueryBuilder queryBuilder = fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(DUtforandeVerksamhet.class).get();
Date today = new Date();
BooleanJunction booleanJunction = queryBuilder
.bool()
.must(queryBuilder
.range()
.onField("avtal.avtalsperiodsStart")
.below(today).createQuery())
.must(queryBuilder
.range()
.onField("avtal.avtalsperiodsSlut")
.above(today).createQuery())
.must(queryBuilder
.keyword()
.fuzzy()
.withThreshold(.5f)
.withPrefixLength(0)
.onFields("namn",
"avtal.alternativtNamn")
.matching(fritext).createQuery());
org.hibernate.search.jpa.FullTextQuery fullTextQuery = fullTextEntityManager.createFullTextQuery(booleanJunction.createQuery(), DUtforandeVerksamhet.class);
fullTextQuery.setSort(new Sort(new SortField("namn", SortField.STRING)));
fullTextQuery.setFirstResult((sidnummer - 1) * sidstorlek);
fullTextQuery.setMaxResults(sidstorlek);
return fullTextQuery.getResultList();
}
/Micke
EDIT!!
Just discovered that I need to set the @ContainedIn on the child-side of the association. Problem solved !!