On the whole, the Lucene patient search is awesome and greatly increased the performance of our patient searches.
However, one side effect is that the getPatients(name, identifier, identifierTypes, matchIdentifierExactly) API method is broken: the “identifierTypes” and “matchIdentifiersExactly” parameters are ignored.
Ignoring the identifierTypes parameter seems particularly problematic. Our Pacs Integration module imports radiology reports from an outside system and uses this API method to match on identifier type. We recently ran into an error when an import failed because matching on primary identifier returned two patients, because another patient had a different identifier with the same value. In this case it just resulted in an error, but in other case it could have led to the report being linked to the wrong patient!
I’ve ticketed what I’ve found here. It feels like the first ticket at least should be a community priority:
I think the reason for this is, that inside the LuceneQuery.java file (LuceneQuery.java#L243) there exits a if clause that checks if the object is of type PersonIdentifier. If it is, which is the case for the getPatients calls, it will automatically set the analyser to EXACT_Match. In my opinion this is the reason why this parameter is ignored.
It would be great if someone could verify my hypothesis. Perhaps @raff is able to confirm my idea?
Idea for fix: I am not so well with Lucene. Is there a ways to tell Lucence to use the field that is part of query ? basically like: fields.contains(identifierAnywhere) => use analyzer `
I think think makes sense @fruether… unfortunately I’m a newbie at Lucene as well, so can’t really weigh in… does anyone else out there have Lucene experience?
@fruether, the analyzer is applied when indexing, but also when querying. The query time analyzer can be different from the indexing one in rare cases as in here. We do it so, because we use different analyzers for different fields at the indexing time and we do not want to apply the default analyzer to the whole query for all fields.
I was also discussing this in the Jira ticket but I think maybe it is more convenient to talk about it here:
My concern is regarding https://issues.openmrs.org/browse/TRUNK-53963 and the behaviour that is defined by the matchExactly parameter. Or to be more concrete: If the matchExactly parameter is set to false how should the matching behave. Should it match on start, anywhere or is there a third option?
To make the matter more concrete I created the following test case lines. Should the call return 0 or 1?
I would say “anywhere”, but I don’t have a strong preference between that and “on start”.
I would think that both “on start” and “anywhere” would return 1 in your example, though, since “1234” starts with “123”… or am I misinterpreting somthing?
I would think that both “on start” and “anywhere” would return 1 in your example, though, since “1234” starts with “123”… or am I misinterpreting somthing?
The issue is that in my solution right now it returns 0. This is probably because neither onStart nor Anywhere is set as global property. Since 0 seems to be the worst option we have to go either for onstart or anywhere.
Since you prefer “anywhere” I will go for it if there is no other strong opinion on it.
More Details:
Code in question:
else if (OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_START.equals(matchMode)) { fields.add("identifierStart");}
else if (!matchExactly || OpenmrsConstants.GLOBAL_PROPERTY_PATIENT_SEARCH_MATCH_ANYWHERE.equals(matchMode)) {
Raf correctly mentioned that matchExactly can never be true at this point. This is true. But since no Global Property is set neither identifierStart not identifierAnywhere is assigned. As a result, 0 will be returned for the described test case. In my opinion 0 matches is the worst value to return especially since then a change of matchExactly would have almost no effect.
Therefore, I would like to have a defaul value to be set in case of no valid global property and matchExactly = false
@raff I think the issue with my last pull request regarding this should be solved now. The current new version of the PR with the adapted changed can be found her: