Skip to content

Commit

Permalink
implement prefix operator
Browse files Browse the repository at this point in the history
  • Loading branch information
yukikaoru committed Jan 1, 2020
1 parent d1addb8 commit 1599b59
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
5 changes: 4 additions & 1 deletion csrestructuredquery/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}"
Expand Down
9 changes: 8 additions & 1 deletion tests/test_query.py
Original file line number Diff line number Diff line change
@@ -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_文字列型と日時型は引用符で括られる():
Expand Down Expand Up @@ -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')"

0 comments on commit 1599b59

Please sign in to comment.