fxy
November 19, 2019, 8:55am
1
I need search these entity which has a field type is timeStamp and value is null,
so I add indexed like this:
@Field(analyze = Analyze.NO, indexNullAs = "0")
private Timestamp time;
and I search like this:
QueryBuilder queryBuilder = session.getSearchFactory().buildQueryBuilder().forEntity( MyEntity.class ).get();
Query luceneQuery = queryBuilder.keyword()
.onField( "time" )
.matching(0)
.createQuery();
result = session.createFullTextQuery( luceneQuery, MyEntity.class ).list();
but I cannot find things I need and can’t get any response.
what problem with my solution?what should I do to find things I need?Who can help me ?Thanks a lot.
You are looking for nulls
, and you made sure that null
values are indexed. Just pass null
to matching
, it will take care of converting it to the correct value:
QueryBuilder queryBuilder = session.getSearchFactory().buildQueryBuilder().forEntity( MyEntity.class ).get();
Query luceneQuery = queryBuilder.keyword()
.onField( "time" )
.matching(null)
.createQuery();
result = session.createFullTextQuery( luceneQuery, MyEntity.class ).list();
Alternatively, ask Hibernate to ignore the field bridge. You will need to call an additional method, and probably also to pass a Long
instead of an Integer
(since timestamps are indexed as longs):
QueryBuilder queryBuilder = session.getSearchFactory().buildQueryBuilder().forEntity( MyEntity.class ).get();
Query luceneQuery = queryBuilder.keyword()
.onField( "time" )
.ignoreFieldBridge()
.matching(0L)
.createQuery();
result = session.createFullTextQuery( luceneQuery, MyEntity.class ).list();
fxy
November 19, 2019, 9:49am
3
SO What annotations should I add at entity time?
QueryBuilder queryBuilder = session.getSearchFactory().buildQueryBuilder().forEntity( MyEntity.class ).get();
Query luceneQuery = queryBuilder.keyword()
.onField( "time" )
.matching(null)
.createQuery();
result = session.createFullTextQuery( luceneQuery, MyEntity.class ).list();
I tried this but can’t find things I need,so I think the annotations I add above it is wrong.
The annotations in your example should work fine.
Did you reindex your data?