From 1599b591398f4c1d47ccb38ce24cba06cb34d79f Mon Sep 17 00:00:00 2001 From: YUKI Kaoru Date: Thu, 2 Jan 2020 03:46:58 +0900 Subject: [PATCH] implement prefix operator --- csrestructuredquery/query.py | 5 ++++- tests/test_query.py | 9 ++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/csrestructuredquery/query.py b/csrestructuredquery/query.py index 9c27582..9c7a5a8 100644 --- a/csrestructuredquery/query.py +++ b/csrestructuredquery/query.py @@ -113,9 +113,12 @@ class Phrase(SpecializedOperator): value: CsValue boost: int = dataclasses.field(default=0) + +@dataclasses.dataclass(frozen=True) +class Prefix(SpecializedOperator): @property def name(self) -> str: - return "phrase" + return "prefix" def query(self) -> str: q = f"({self.name} field={self.field}" diff --git a/tests/test_query.py b/tests/test_query.py index 5b97454..03b451a 100644 --- a/tests/test_query.py +++ b/tests/test_query.py @@ -1,6 +1,6 @@ from datetime import datetime -from csrestructuredquery.query import Query, And, Or, Not, Near, Phrase +from csrestructuredquery.query import Query, And, Or, Not, Near, Phrase, Prefix def test_文字列型と日時型は引用符で括られる(): @@ -40,3 +40,10 @@ def test_phrase演算子(): assert operator.query() == "(phrase field=foo 'hoge')" operator = Phrase(field="foo", value="hoge", boost=4) assert operator.query() == "(phrase field=foo boost=4 'hoge')" + + +def test_prefix演算子(): + operator = Prefix(field="foo", value="hoge") + assert operator.query() == "(prefix field=foo 'hoge')" + operator = Prefix(field="foo", value="hoge", boost=4) + assert operator.query() == "(prefix field=foo boost=4 'hoge')"