@@ -183,6 +183,40 @@ We may also include related objects in the search results::
183183 visitId = "1.1-N"
184184 }]
185185
186+ python-icat supports the use of some JPQL functions when specifying
187+ which attribute a condition should be applied to. Consider the
188+ following query::
189+
190+ >>> query = Query(client, "Investigation", conditions={"LENGTH(title)": "= 18"})
191+ >>> print(query)
192+ SELECT o FROM Investigation o WHERE LENGTH(o.title) = 18
193+ >>> client.search(query)
194+ [(investigation){
195+ createId = "simple/root"
196+ createTime = 2021-10-05 14:09:57+00:00
197+ id = 430
198+ modId = "simple/root"
199+ modTime = 2021-10-05 14:09:57+00:00
200+ doi = "00.0815/inv-00601"
201+ endDate = 2010-10-12 15:00:00+00:00
202+ name = "10100601-ST"
203+ startDate = 2010-09-30 10:27:24+00:00
204+ title = "Ni-Mn-Ga flat cone"
205+ visitId = "1.1-N"
206+ }, (investigation){
207+ createId = "simple/root"
208+ createTime = 2021-10-05 14:09:58+00:00
209+ id = 431
210+ modId = "simple/root"
211+ modTime = 2021-10-05 14:09:58+00:00
212+ doi = "00.0815/inv-00409"
213+ endDate = 2012-08-06 01:10:08+00:00
214+ name = "12100409-ST"
215+ startDate = 2012-07-26 15:44:24+00:00
216+ title = "NiO SC OF1 JUH HHL"
217+ visitId = "1.1-P"
218+ }]
219+
186220The conditions in a query may also be put on the attributes of related
187221objects. This allows rather complex queries. Let us search for the
188222datasets in this investigation that have been measured in a magnetic
@@ -668,6 +702,27 @@ dataset parameter, ordered by parameter type name (ascending), units
668702 }
669703 }]
670704
705+ In a similar way as for `conditions `, we may use JPQL functions also
706+ in the `order ` argument to :class: `~icat.query.Query `. Let's search
707+ for user sorted by the length of their name, from longest to
708+ shortest::
709+
710+ >>> query = Query(client, "User", conditions={"fullName": "IS NOT NULL"}, order=[("LENGTH(fullName)", "DESC")])
711+ >>> print(query)
712+ SELECT o FROM User o WHERE o.fullName IS NOT NULL ORDER BY LENGTH(o.fullName) DESC
713+ >>> for user in client.search(query):
714+ ... print("%d: %s" % (len(user.fullName), user.fullName))
715+ ...
716+ 19: Rudolph Beck-Dülmen
717+ 19: Jean-Baptiste Botul
718+ 16: Nicolas Bourbaki
719+ 13: Aelius Cordus
720+ 11: User Office
721+ 10: Arnold Hau
722+ 10: IDS reader
723+ 8: John Doe
724+ 4: Root
725+
671726We may limit the number of returned items. Search for the second to
672727last dataset to have been finished::
673728
0 commit comments