Skip to content

Commit

Permalink
Update test_actions.py
Browse files Browse the repository at this point in the history
  • Loading branch information
saimedhi authored Mar 14, 2024
1 parent c3d2a9b commit a55b46c
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test_opensearchpy/test_server/test_helpers/test_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,51 @@ def test_forcemerge_verify_shards(self) -> None:
assert 1 == 2
assert response['_shards']['total'] == 2

def test_plain_highlighter_without_offsets_succeed(self) -> None:
# Create index with specified settings and mappings
self.client.indices.create(
index='test1',
body={
"settings": {
"number_of_shards": 1,
"index.highlight.max_analyzed_offset": 10
},
"mappings": {
"properties": {
"field1": {"type": "text"},
"field2": {"type": "text", "index_options": "offsets"}
}
}
}
)

# Index a document with specified ID and fields
self.client.index(
index='test1',
id=1,
body={
"field1": "The quick brown fox went to the forest and saw another fox.",
"field2": "The quick brown fox went to the forest and saw another fox."
}
)

# Refresh indices to make changes visible
self.client.indices.refresh(index='test1')

# Perform search with plain highlighter and verify result
response = self.client.search(
index='test1',
body={
"query": {"match": {"field1": "quick"}},
"highlight": {"type": "plain", "fields": {"field1": {"max_analyzer_offset": 10}}}
},
rest_total_hits_as_int=True
)

# Assert the highlighted text matches the expected result
assert response['hits']['hits'][0]['highlight']['field1'][0] == "The <em>quick</em> "


class TestStreamingBulk(OpenSearchTestCase):
def test_actions_remain_unchanged(self) -> None:
actions = [{"_id": 1}, {"_id": 2}]
Expand Down

0 comments on commit a55b46c

Please sign in to comment.