Hi @jwnasambu!
So when I upgrade the Lucene version to 8.5.0 and run mvn clean package
I get compiler errors like this:
[ERROR] /Users/ibacher/Documents/openmrs/openmrs-core/api/src/main/java/org/openmrs/api/db/hibernate/search/LuceneQuery.java:[21,32] error: cannot find symbol
[ERROR] package org.apache.lucene.queries
/Users/ibacher/Documents/openmrs/openmrs-core/api/src/main/java/org/openmrs/api/db/hibernate/search/LuceneQuery.java:[49,9] error: cannot find symbol
[ERROR]
T extends Object declared in class LuceneQuery
/Users/ibacher/Documents/openmrs/openmrs-core/api/src/main/java/org/openmrs/api/db/hibernate/search/TermsFilterFactory.java:[18,31] error: cannot find symbol
[ERROR] package org.apache.lucene.search
/Users/ibacher/Documents/openmrs/openmrs-core/api/src/main/java/org/openmrs/api/db/hibernate/search/TermsFilterFactory.java:[20,31] error: cannot find symbol
[ERROR] package org.apache.lucene.search
/Users/ibacher/Documents/openmrs/openmrs-core/api/src/main/java/org/openmrs/api/db/hibernate/search/TermsFilterFactory.java:[51,8] error: cannot find symbol
These actually seem to be errors related to the new Lucene version and API changes (OpenMRS was previously using Lucene 4.x, so leaping to 8.5.0 is quite the leap!). Fortunately, these changes are confined to two classes: TermsFilterFactory
and LuceneQuery
.
The actual change causing this error seems to have been made in Lucene 6 where we find:
Removal of Filter and FilteredQuery (LUCENE-6301,LUCENE-6583)
Filter and FilteredQuery have been removed. Regular queries can be used instead of filters as they have been optimized for the filtering case. And you can construct a BooleanQuery with one MUST clause for the query, and one FILTER clause for the filter in order to have similar behaviour to FilteredQuery.
And, indeed the part that’s misbehaving is the TermFilter
class, which we should replace with the corresponding Query
.
Now we hit a snag: If we look at the LuceneQuery
class, we see that it’s using a FullTextQuery
to query Lucene. This FullTextQuery
isn’t part of the Lucene library, but of the Hibernate Search library. So we’ll need to update that too. However, when I look at the latest stable release of Hibernate Search, I see it only supports Hibernate 5.4. Since we’ve only upgraded to Hibernate 5.0, we should pick a version that supports that. The latest version that supports Hibernate 5.0 is Hibernate Search 5.6, which only supports Lucene 5.5. So let’s update to those versions.
When I do that locally, I end up with a compilation error in the DelegatingFullTextSession
class, because it needs a new method, which can look something like this:
@Override
public FullTextQuery createFullTextQuery(QueryDescriptor descriptor, Class<?>... entities) {
if (entities.length > 1) {
throw new DAOException("Can't create FullTextQuery for multiple persistent classes");
}
if (log.isDebugEnabled()) {
log.debug("Creating new FullTextQuery instance");
}
Class<?> entityClass = entities[0];
FullTextQuery query = delegate.createFullTextQuery(descriptor, entityClass);
if (log.isDebugEnabled()) {
log.debug("Notifying FullTextQueryCreated listeners...");
}
//Notify listeners, note that we intentionally don't catch any exception from a listener
//so that failure should just halt the entire creation operation, this is possible because
//the default ApplicationEventMulticaster in spring fires events serially in the same thread
//but has the downside of where a rogue listener can block the entire application.
FullTextQueryAndEntityClass queryAndClass = new FullTextQueryAndEntityClass(query, entityClass);
eventPublisher.publishEvent(new FullTextQueryCreatedEvent(queryAndClass));
return query;
}
At this point, things compile, so we should hopefully be good. Let me know if you have any questions or if you come across any more issues with this. If not, you should open some tickets to get rid of our dependence on the deprecated TermFilter
class.