From 448dcbab46e3744bff867443f1e50799cba82f06 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 27 Apr 2023 08:06:55 -0700 Subject: [PATCH 1/2] Include multi object queries in whoosh searcher --- src/documents/index.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/documents/index.py b/src/documents/index.py index 403282403..973c99f4d 100644 --- a/src/documents/index.py +++ b/src/documents/index.py @@ -172,6 +172,14 @@ class DelayedQuery: for k, v in self.query_params.items(): if k == "correspondent__id": criterias.append(query.Term("correspondent_id", v)) + elif k == "correspondent__id__in": + for correspondent_id in v.split(","): + criterias.append(query.Term("correspondent_id", correspondent_id)) + elif k == "correspondent__id__none": + for correspondent_id in v.split(","): + criterias.append( + query.Not(query.Term("correspondent_id", correspondent_id)), + ) elif k == "tags__id__all": for tag_id in v.split(","): criterias.append(query.Term("tag_id", tag_id)) @@ -180,6 +188,12 @@ class DelayedQuery: criterias.append(query.Not(query.Term("tag_id", tag_id))) elif k == "document_type__id": criterias.append(query.Term("type_id", v)) + elif k == "document_type__id__in": + for document_type_id in v.split(","): + criterias.append(query.Term("type_id", document_type_id)) + elif k == "document_type__id__none": + for document_type_id in v.split(","): + criterias.append(query.Not(query.Term("type_id", document_type_id))) elif k == "correspondent__isnull": criterias.append(query.Term("has_correspondent", v == "false")) elif k == "is_tagged": @@ -200,6 +214,12 @@ class DelayedQuery: criterias.append(query.DateRange("added", start=None, end=isoparse(v))) elif k == "storage_path__id": criterias.append(query.Term("path_id", v)) + elif k == "storage_path__id__in": + for storage_path_id in v.split(","): + criterias.append(query.Term("path_id", storage_path_id)) + elif k == "storage_path__id__none": + for storage_path_id in v.split(","): + criterias.append(query.Not(query.Term("path_id", storage_path_id))) elif k == "storage_path__isnull": criterias.append(query.Term("has_path", v == "false")) From 1a1cf49c67e1d64142b0e307695f45dad1785407 Mon Sep 17 00:00:00 2001 From: shamoon <4887959+shamoon@users.noreply.github.com> Date: Thu, 27 Apr 2023 08:47:36 -0700 Subject: [PATCH 2/2] Testing for whoosh support for multi-object query vars --- src/documents/tests/test_api.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/documents/tests/test_api.py b/src/documents/tests/test_api.py index a6307e2d5..d6158cd7d 100644 --- a/src/documents/tests/test_api.py +++ b/src/documents/tests/test_api.py @@ -955,8 +955,32 @@ class TestDocumentApi(DirectoriesMixin, DocumentConsumeDelayMixin, APITestCase): [d1.id, d2.id, d5.id, d7.id], ) self.assertCountEqual(search_query("&correspondent__id=" + str(c.id)), [d1.id]) + self.assertCountEqual( + search_query("&correspondent__id__in=" + str(c.id)), + [d1.id], + ) + self.assertCountEqual( + search_query("&correspondent__id__none=" + str(c.id)), + [d2.id, d3.id, d4.id, d5.id, d7.id], + ) self.assertCountEqual(search_query("&document_type__id=" + str(dt.id)), [d2.id]) + self.assertCountEqual( + search_query("&document_type__id__in=" + str(dt.id)), + [d2.id], + ) + self.assertCountEqual( + search_query("&document_type__id__none=" + str(dt.id)), + [d1.id, d3.id, d4.id, d5.id, d7.id], + ) self.assertCountEqual(search_query("&storage_path__id=" + str(sp.id)), [d7.id]) + self.assertCountEqual( + search_query("&storage_path__id__in=" + str(sp.id)), + [d7.id], + ) + self.assertCountEqual( + search_query("&storage_path__id__none=" + str(sp.id)), + [d1.id, d2.id, d3.id, d4.id, d5.id], + ) self.assertCountEqual( search_query("&storage_path__isnull"),