Thanks for the info. I’d prefer not to hack anything, as that seems what may have been done with our v12 code and now causing problems. I’d rather find a “supported” way to rework the code.
If I run the v12 code as is, the query being executed is:
//element(*,myapp:package)[(@hippo:paths='c8266467-a207-44f4-b879-49b0179342a8') and not(@jcr:primaryType='nt:frozenNode') and ((@hippostd:state = 'published') and (@hippo:availability != 'live' or (@myapp:expiry_date____day <= xs:dateTime('2019-12-03T00:00:00.000+02:00'))))] order by @jcr:score descending
This brings back many results, as expected.
If I however remove setting null on ModifiableRequestContextProvider before executing, the query being executed is:
//element(*,myapp:package)[(@hippo:paths='c8266467-a207-44f4-b879-49b0179342a8') and (@hippo:availability='preview') and not(@jcr:primaryType='nt:frozenNode') and ((@hippostd:state = 'published') and (@hippo:availability != 'live' or (@myapp:expiry_date____day <= xs:dateTime('2019-12-03T00:00:00.000+02:00'))))] order by @jcr:score descending
This now returns no results, which is wrong. I believe this is as a result of and (@hippo:availability='preview')
that is now part of the query, possibly because this is done inside the Channel Manager, as that is the only difference I can spot? Honestly though, I don’t really understand how availability=‘preview’ is affecting the results.
((@hippostd:state = 'published') and (@hippo:availability != 'live' or (@myapp:expiry_date____day <= xs:dateTime('2019-12-03T00:00:00.000+02:00'))))
are the filters we apply, since we are looking for a list of all documents of type “package”, that are published (state) and either not live (availability) or with an “expiry_date” document property value that is in the past.
Would rewriting our code from Legacy search to Fluent search make any difference to the issue?
Perhaps the full method might help point to a better way to achieve our goal?
protected void processReportQuery(HstRequest request, HstResponse response, EssentialsListComponentInfo paramInfo) {
final ComponentManager mngr = HstServices.getComponentManager();
final Credentials configCred = mngr.getComponent(Credentials.class.getName() + ".hstconfigreader");
final Repository repository = mngr.getComponent(Repository.class.getName());
final ContentBeansTool cbt = mngr.getComponent(ContentBeansTool.class.getName());
try {
final Session mySession = repository.login(configCred);
final Node rootNode = mySession.getNode("/content/documents/myapp");
final HstQueryManager queryManager = cbt.createQueryManager(mySession);
final HstQuery hstQuery = queryManager.createQuery(rootNode, (Class<? extends HippoBean>) Package.class, true);
final Filter finalFilter = hstQuery.createFilter();
final Filter filter = hstQuery.createFilter();
hstQuery.setFilter(finalFilter);
filter.addNotEqualTo("hippo:availability", "live");
final Filter subFilter = hstQuery.createFilter();
subFilter.addLessOrEqualThan("myapp:expiry_date", Calendar.getInstance(), DateTools.Resolution.DAY);
filter.addOrFilter(subFilter);
final Filter stateFilter = hstQuery.createFilter();
stateFilter.addEqualTo("hippostd:state", "published");
finalFilter.addAndFilter(stateFilter);
finalFilter.addAndFilter(filter);
// final HstRequestContext ctx = RequestContextProvider.get();
// ModifiableRequestContextProvider.set(null);
log.debug("Query String: {}", hstQuery.getQueryAsString(false));
final HstQueryResult result = hstQuery.execute();
// ModifiableRequestContextProvider.set(ctx);
request.setAttribute("result", result);
dumpResults(result);
final Pageable<? extends HippoBean> pageable;
pageable = getPageableFactory().createPageable(
result.getHippoBeans(),
result.getTotalSize(),
result.getTotalSize(),
0);
populateRequest(request, paramInfo, pageable);
} catch (LoginException e1) {
log.error("Failed to log into repository with credentials {}",configCred,e1);
} catch (RepositoryException e1) {
log.error("Failed to get repository session ",e1);
} catch (IllegalStateException e) {
log.error("State is all wrong ",e);
} catch (QueryException e) {
log.error("Query issue ",e);
}
}