diff options
Diffstat (limited to 'tests/test_search.py')
-rw-r--r-- | tests/test_search.py | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/tests/test_search.py b/tests/test_search.py index 7d666cb..6c79041 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -1155,6 +1155,72 @@ def test_index_definition(client): @pytest.mark.redismod +def testExpire(client): + client.ft().create_index((TextField("txt", sortable=True),), temporary=4) + ttl = client.execute_command("ft.debug", "TTL", "idx") + assert ttl > 2 + + while ttl > 2: + ttl = client.execute_command("ft.debug", "TTL", "idx") + time.sleep(0.01) + + # add document - should reset the ttl + client.ft().add_document("doc", txt="foo bar", text="this is a simple test") + ttl = client.execute_command("ft.debug", "TTL", "idx") + assert ttl > 2 + try: + while True: + ttl = client.execute_command("ft.debug", "TTL", "idx") + time.sleep(0.5) + except redis.exceptions.ResponseError: + assert ttl == 0 + + +@pytest.mark.redismod +def testSkipInitialScan(client): + client.hset("doc1", "foo", "bar") + q = Query("@foo:bar") + + client.ft().create_index((TextField("foo"),), skip_initial_scan=True) + assert 0 == client.ft().search(q).total + + +@pytest.mark.redismod +def testSummarizeDisabled_nooffset(client): + client.ft().create_index((TextField("txt"),), no_term_offsets=True) + client.ft().add_document("doc1", txt="foo bar") + with pytest.raises(Exception): + client.ft().search(Query("foo").summarize(fields=["txt"])) + + +@pytest.mark.redismod +def testSummarizeDisabled_nohl(client): + client.ft().create_index((TextField("txt"),), no_highlight=True) + client.ft().add_document("doc1", txt="foo bar") + with pytest.raises(Exception): + client.ft().search(Query("foo").summarize(fields=["txt"])) + + +@pytest.mark.redismod +def testMaxTextFields(client): + # Creating the index definition + client.ft().create_index((TextField("f0"),)) + for x in range(1, 32): + client.ft().alter_schema_add((TextField(f"f{x}"),)) + + # Should be too many indexes + with pytest.raises(redis.ResponseError): + client.ft().alter_schema_add((TextField(f"f{x}"),)) + + client.ft().dropindex("idx") + # Creating the index definition + client.ft().create_index((TextField("f0"),), max_text_fields=True) + # Fill the index with fields + for x in range(1, 50): + client.ft().alter_schema_add((TextField(f"f{x}"),)) + + +@pytest.mark.redismod @skip_ifmodversion_lt("2.0.0", "search") def test_create_client_definition(client): """ |