paperless_api/document_query.rs
1//! Query for Documents using the [`DocumentQueryBuilder`]
2
3use crate::{
4 document::ArchiveSerialNumber,
5 id::{CorrespondentId, TagId},
6};
7
8#[derive(Default)]
9pub struct DocumentQueryBuilder {
10 archive_serial_number: Option<ArchiveSerialNumber>,
11 correspondent_id_in: Option<Vec<CorrespondentId>>,
12 correspondent_name_icontains: Option<String>,
13 content_icontains: Option<String>,
14 tags_id_in: Option<Vec<TagId>>,
15 pub(crate) full_content: bool,
16 full_permissions: bool,
17}
18
19pub struct DocumentQuery {
20 pub(crate) query: Vec<(&'static str, String)>,
21}
22
23const QUERY_PARAM_FULL_PERMISSIONS: &str = "full_perms";
24const QUERY_PARAM_TRUNCATE_CONTENT: &str = "truncate_content";
25const QUERY_PARAM_TAGS_ID_IN: &str = "tags__id__in";
26const QUERY_PARAM_ARCHIVE_SERIAL_NUMBER: &str = "archive_serial_number";
27const QUERY_PARAM_CORRESPONDENT_ID_IN: &str = "correspondent__id__in";
28const QUERY_PARAM_CORRESPONDENT_NAME_ICONTAINS: &str = "correspondent__name__icontains";
29const QUERY_PARAM_CONTENT_ICONTAINS: &str = "content__icontains";
30
31impl DocumentQueryBuilder {
32 /// Filters documents which have the given archive serial number.
33 #[must_use]
34 pub fn archive_serial_number(mut self, archive_serial_number: ArchiveSerialNumber) -> Self {
35 self.archive_serial_number = Some(archive_serial_number);
36 self
37 }
38
39 /// Filters documents which have any of the given correspondents.
40 #[must_use]
41 pub fn correspondent_id_in(mut self, correspondent_id_in: Vec<CorrespondentId>) -> Self {
42 self.correspondent_id_in = Some(correspondent_id_in);
43 self
44 }
45
46 /// Filters documents which have a correspondent name containing the given string.
47 #[must_use]
48 pub fn correspondent_name_icontains(mut self, correspondent_name_icontains: String) -> Self {
49 self.correspondent_name_icontains = Some(correspondent_name_icontains);
50 self
51 }
52
53 /// Filters documents which have content containing the given string.
54 #[must_use]
55 pub fn content_icontains(mut self, content_icontains: String) -> Self {
56 self.content_icontains = Some(content_icontains);
57 self
58 }
59
60 /// Filters documents which have any of the given tags.
61 #[must_use]
62 pub fn tags_id_in(mut self, tags_id_in: Vec<TagId>) -> Self {
63 self.tags_id_in = Some(tags_id_in);
64 self
65 }
66
67 /// Returns documents with full content (truncated by default to save bandwidth).
68 #[must_use]
69 pub fn full_content(mut self, full_content: bool) -> Self {
70 self.full_content = full_content;
71 self
72 }
73
74 /// Returns documents with full permissions data.
75 #[must_use]
76 pub fn full_permissions(mut self) -> Self {
77 self.full_permissions = true;
78 self
79 }
80
81 #[must_use]
82 pub fn build(self) -> DocumentQuery {
83 let mut query = vec![];
84
85 if let Some(archive_serial_number) = self.archive_serial_number {
86 query.push((
87 QUERY_PARAM_ARCHIVE_SERIAL_NUMBER,
88 archive_serial_number.0.to_string(),
89 ));
90 }
91 if let Some(correspondent_id_in) = self.correspondent_id_in {
92 query.push((
93 QUERY_PARAM_CORRESPONDENT_ID_IN,
94 correspondent_id_in
95 .iter()
96 .map(|id| id.0.to_string())
97 .collect::<Vec<_>>()
98 .join(","),
99 ));
100 }
101 if let Some(correspondent_name_icontains) = self.correspondent_name_icontains {
102 query.push((
103 QUERY_PARAM_CORRESPONDENT_NAME_ICONTAINS,
104 correspondent_name_icontains,
105 ));
106 }
107 if let Some(content_icontains) = self.content_icontains {
108 query.push((QUERY_PARAM_CONTENT_ICONTAINS, content_icontains));
109 }
110 if let Some(tags_id_in) = self.tags_id_in {
111 query.push((
112 QUERY_PARAM_TAGS_ID_IN,
113 tags_id_in
114 .iter()
115 .map(|id| id.0.to_string())
116 .collect::<Vec<_>>()
117 .join(","),
118 ));
119 }
120 if !self.full_content {
121 query.push((QUERY_PARAM_TRUNCATE_CONTENT, "false".to_string()));
122 }
123
124 if self.full_content {
125 query.push((QUERY_PARAM_FULL_PERMISSIONS, "true".to_string()));
126 }
127
128 DocumentQuery { query }
129 }
130}
131/*
132added__date__gt
133string($date)
134(query)
135
136added__date__gte
137string($date)
138(query)
139
140added__date__lt
141string($date)
142(query)
143
144added__date__lte
145string($date)
146(query)
147
148added__day
149number
150(query)
151
152added__gt
153string($date-time)
154(query)
155
156added__gte
157string($date-time)
158(query)
159
160added__lt
161string($date-time)
162(query)
163
164added__lte
165string($date-time)
166(query)
167
168added__month
169number
170(query)
171
172added__year
173number
174(query)
175
176content__icontains
177string
178(query)
179
180content__iendswith
181string
182(query)
183
184content__iexact
185string
186(query)
187
188content__istartswith
189string
190(query)
191
192correspondent__id
193integer
194(query)
195
196correspondent__id__in
197array<integer>
198(query)
199Mehrere Werte können durch Kommas getrennt sein.
200Add integer item
201correspondent__id__none
202integer
203(query)
204
205correspondent__isnull
206boolean
207(query)
208
209correspondent__name__icontains
210string
211(query)
212
213correspondent__name__iendswith
214string
215(query)
216
217correspondent__name__iexact
218string
219(query)
220
221correspondent__name__istartswith
222string
223(query)
224
225created__date__gt
226string($date)
227(query)
228
229created__date__gte
230string($date)
231(query)
232
233created__date__lt
234string($date)
235(query)
236
237created__date__lte
238string($date)
239(query)
240
241created__day
242number
243(query)
244
245created__gt
246string($date)
247(query)
248
249created__gte
250string($date)
251(query)
252
253created__lt
254string($date)
255(query)
256
257created__lte
258string($date)
259(query)
260
261created__month
262number
263(query)
264
265created__year
266number
267(query)
268
269custom_field_query
270string
271(query)
272
273custom_fields__icontains
274string
275(query)
276
277custom_fields__id__all
278integer
279(query)
280
281custom_fields__id__in
282integer
283(query)
284
285custom_fields__id__none
286integer
287(query)
288
289document_type__id
290integer
291(query)
292
293document_type__id__in
294array<integer>
295(query)
296Mehrere Werte können durch Kommas getrennt sein.
297Add integer item
298document_type__id__none
299integer
300(query)
301
302document_type__isnull
303boolean
304(query)
305
306document_type__name__icontains
307string
308(query)
309
310document_type__name__iendswith
311string
312(query)
313
314document_type__name__iexact
315string
316(query)
317
318document_type__name__istartswith
319string
320(query)
321
322fields
323array<string>
324(query)
325Add string item
326full_perms
327boolean
328(query)
329
330has_custom_fields
331boolean
332(query)
333Has custom field
334
335id
336integer
337(query)
338
339id__in
340array<integer>
341(query)
342Mehrere Werte können durch Kommas getrennt sein.
343Add integer item
344is_in_inbox
345boolean
346(query)
347
348is_tagged
349boolean
350(query)
351Is tagged
352
353mime_type
354string
355(query)
356
357modified__date__gt
358string($date)
359(query)
360
361modified__date__gte
362string($date)
363(query)
364
365modified__date__lt
366string($date)
367(query)
368
369modified__date__lte
370string($date)
371(query)
372
373modified__day
374number
375(query)
376
377modified__gt
378string($date-time)
379(query)
380
381modified__gte
382string($date-time)
383(query)
384
385modified__lt
386string($date-time)
387(query)
388
389modified__lte
390string($date-time)
391(query)
392
393modified__month
394number
395(query)
396
397modified__year
398number
399(query)
400
401ordering
402string
403(query)
404Feld, das zum Sortieren der Ergebnisse verwendet werden soll.
405
406original_filename__icontains
407string
408(query)
409
410original_filename__iendswith
411string
412(query)
413
414original_filename__iexact
415string
416(query)
417
418original_filename__istartswith
419string
420(query)
421
422owner__id
423integer
424(query)
425
426owner__id__in
427array<integer>
428(query)
429Mehrere Werte können durch Kommas getrennt sein.
430Add integer item
431owner__id__none
432integer
433(query)
434
435owner__isnull
436boolean
437(query)
438
439page
440integer
441(query)
442Eine Seitenzahl in der paginierten Ergebnismenge.
443
444page_size
445integer
446(query)
447Anzahl der pro Seite zurückzugebenden Ergebnisse.
448
449query
450string
451(query)
452Advanced search query string
453
454search
455string
456(query)
457Ein Suchbegriff.
458
459shared_by__id
460boolean
461(query)
462
463storage_path__id
464integer
465(query)
466
467storage_path__id__in
468array<integer>
469(query)
470Mehrere Werte können durch Kommas getrennt sein.
471Add integer item
472storage_path__id__none
473integer
474(query)
475
476storage_path__isnull
477boolean
478(query)
479
480storage_path__name__icontains
481string
482(query)
483
484storage_path__name__iendswith
485string
486(query)
487
488storage_path__name__iexact
489string
490(query)
491
492storage_path__name__istartswith
493string
494(query)
495
496tags__id
497integer
498(query)
499
500tags__id__all
501integer
502(query)
503
504tags__id__in
505integer
506(query)
507
508tags__id__none
509integer
510(query)
511
512tags__name__icontains
513string
514(query)
515
516tags__name__iendswith
517string
518(query)
519
520tags__name__iexact
521string
522(query)
523
524tags__name__istartswith
525string
526(query)
527
528title__icontains
529string
530(query)
531
532title__iendswith
533string
534(query)
535
536title__iexact
537string
538(query)
539
540title__istartswith
541string
542(query)
543
544title_content
545string
546(query)
547 */