@@ -321,3 +321,48 @@ def test_search_sort(cleanup_after):
321321 result = query .search ()
322322 assert len (result ["hits" ]["hits" ]) == 2
323323 assert result ["hits" ]["hits" ][0 ]["_id" ] == "event2"
324+
325+
326+ def test_search_tag_filter (cleanup_after ):
327+ # Create entity with tags in context
328+ entity_data = {
329+ "id" : "jane-doe-tagged" ,
330+ "schema" : "Person" ,
331+ "properties" : {"name" : ["Jane Doe" ], "birthDate" : ["1980-01-01" ]},
332+ }
333+ entity = make_entity (entity_data )
334+ entity .context ["tags" ] = ["politician" , "businessman" , "controversial" ]
335+
336+ index_bulk ("test_tagged" , [entity ], sync = True )
337+
338+ # Test search with tag filter
339+ query = _create_query ("/search?filter:dataset=test_tagged&filter:tags=politician" )
340+ result = query .search ()
341+
342+ assert result ["hits" ]["total" ]["value" ] == 1
343+ assert result ["hits" ]["hits" ][0 ]["_id" ] == "jane-doe-tagged"
344+
345+ # Test search with non-existent tag
346+ query = _create_query ("/search?filter:dataset=test_tagged&filter:tags=nonexistent" )
347+ result = query .search ()
348+
349+ assert result ["hits" ]["total" ]["value" ] == 0
350+
351+ # Test search with multiple tag values
352+ query = _create_query ("/search?filter:dataset=test_tagged&filter:tags=businessman" )
353+ result = query .search ()
354+
355+ assert result ["hits" ]["total" ]["value" ] == 1
356+ assert result ["hits" ]["hits" ][0 ]["_id" ] == "jane-doe-tagged"
357+
358+ # Test tags facet aggregation
359+ query = _create_query ("/search?filter:dataset=test_tagged&facet=tags" )
360+ result = query .search ()
361+
362+ assert result ["hits" ]["total" ]["value" ] == 1
363+ assert "aggregations" in result
364+ assert result ["aggregations" ]["tags.values" ]["buckets" ] == [
365+ {"key" : "businessman" , "doc_count" : 1 },
366+ {"key" : "controversial" , "doc_count" : 1 },
367+ {"key" : "politician" , "doc_count" : 1 },
368+ ]
0 commit comments