DatabaseService Query returning unexpected results
I seem to be running into an issue with the DatabaseService pluginutilities returning unexpected results. I am working on a plugin that takes an import from a CSV file containing a list of DNA molecule names within the local database and performs an action on those documents. The action works fine in all cases but the DatabaseService does not always return the correct AnnottatedPluginDocument.
So if the CSV contains the following molecule names:
1. HIS-TMV-XYZ1(1-159)-abc
2. HIS-TMV-XYZ1(1-159)-cde
3. HIS-TMV-XYZ1(1-159)-fgh
4. HIS-TMV-XYZ1(1-159)-bhi
And molName = the first molecule name in the list.
and my query is:
Query[] searchValues1 = new Query[] {Query.Factory.createFieldQuery(DocumentField.ALL, Condition.CONTAINS, molName)
DatabaseService service = (DatabaseService)PluginUtilities.getGeneiousService("LocalDocuments");
List<AnnotatedPluginDocument> documents1;
documents1 = service.retrieve(totalQuery,listening);
documents1 List returns the following hits:
2. HIS-TMV-XYZ1(1-159)-cde
3. HIS-TMV-XYZ1(1-159)-fgh
4. HIS-TMV-XYZ1(1-159)-bhi
If I change molName to the second molecule, documents1 List contains:
1. HIS-TMV-XYZ1(1-159)-abc
3. HIS-TMV-XYZ1(1-159)-fgh
4. HIS-TMV-XYZ1(1-159)-bhi
There does seem to be an association with occurring based on the length of the molecule name. Roughly names that are less than 35 characters give the expected results while longer names give the incorrect results. If I try trimming the molecule names down I will occasionally get thrown an error depending on if the last trimmed character is a special character.
Any ideas would be greatly appreciated.
Brian
-
Problem Solved.
It appears that how the molName is handled within the Query was causing the problem. The molecule name needs to be within double quotes to be handled correctly otherwise the Lucene queryParser has issues.
So
Query[] searchValues1 = new Query[] {Query.Factory.createFieldQuery(DocumentField.ALL, Condition.CONTAINS, "\"" + molName + "\"")
0 -
Hi Brian,
Great to hear you found and solved the problem :)
0
Please sign in to leave a comment.
Comments
2 comments