@@ -304,7 +304,7 @@ def test_services_search_indexers_batches_pass_only_batch_accesses(
304
304
access = factories .UserDocumentAccessFactory (document = document )
305
305
expected_user_subs [str (document .id )] = str (access .user .sub )
306
306
307
- FindDocumentIndexer ().index ()
307
+ assert FindDocumentIndexer ().index () == 5
308
308
309
309
# Should be 3 batches: 2 + 2 + 1
310
310
assert mock_push .call_count == 3
@@ -327,6 +327,34 @@ def test_services_search_indexers_batches_pass_only_batch_accesses(
327
327
assert seen_doc_ids == {str (d .id ) for d in documents }
328
328
329
329
330
+ @patch .object (FindDocumentIndexer , "push" )
331
+ @pytest .mark .usefixtures ("indexer_settings" )
332
+ def test_services_search_indexers_ignore_empty_documents (mock_push ):
333
+ """
334
+ Documents indexing should be processed in batches,
335
+ and only the access data relevant to each batch should be used.
336
+ """
337
+ document = factories .DocumentFactory ()
338
+ factories .DocumentFactory (content = "" , title = "" )
339
+ empty_title = factories .DocumentFactory (title = "" )
340
+ empty_content = factories .DocumentFactory (content = "" )
341
+
342
+ assert FindDocumentIndexer ().index () == 3
343
+
344
+ assert mock_push .call_count == 1
345
+
346
+ # Make sure only not eempty documents are indexed
347
+ results = {doc ["id" ] for doc in mock_push .call_args [0 ][0 ]}
348
+ assert results == {
349
+ str (d .id )
350
+ for d in (
351
+ document ,
352
+ empty_content ,
353
+ empty_title ,
354
+ )
355
+ }
356
+
357
+
330
358
@patch .object (FindDocumentIndexer , "push" )
331
359
@pytest .mark .usefixtures ("indexer_settings" )
332
360
def test_services_search_indexers_ancestors_link_reach (mock_push ):
@@ -338,7 +366,7 @@ def test_services_search_indexers_ancestors_link_reach(mock_push):
338
366
parent = factories .DocumentFactory (parent = grand_parent , link_reach = "public" )
339
367
document = factories .DocumentFactory (parent = parent , link_reach = "restricted" )
340
368
341
- FindDocumentIndexer ().index ()
369
+ assert FindDocumentIndexer ().index () == 4
342
370
343
371
results = {doc ["id" ]: doc for doc in mock_push .call_args [0 ][0 ]}
344
372
assert len (results ) == 4
@@ -358,7 +386,7 @@ def test_services_search_indexers_ancestors_users(mock_push):
358
386
parent = factories .DocumentFactory (parent = grand_parent , users = [user_p ])
359
387
document = factories .DocumentFactory (parent = parent , users = [user_d ])
360
388
361
- FindDocumentIndexer ().index ()
389
+ assert FindDocumentIndexer ().index () == 3
362
390
363
391
results = {doc ["id" ]: doc for doc in mock_push .call_args [0 ][0 ]}
364
392
assert len (results ) == 3
@@ -379,7 +407,7 @@ def test_services_search_indexers_ancestors_teams(mock_push):
379
407
parent = factories .DocumentFactory (parent = grand_parent , teams = ["team_p" ])
380
408
document = factories .DocumentFactory (parent = parent , teams = ["team_d" ])
381
409
382
- FindDocumentIndexer ().index ()
410
+ assert FindDocumentIndexer ().index () == 3
383
411
384
412
results = {doc ["id" ]: doc for doc in mock_push .call_args [0 ][0 ]}
385
413
assert len (results ) == 3
0 commit comments