Skip to content

Commit

Permalink
Add RankFeatures field
Browse files Browse the repository at this point in the history
  • Loading branch information
sethmlarson committed Dec 3, 2020
1 parent 16304df commit e7f8a90
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
2 changes: 2 additions & 0 deletions elasticsearch_dsl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
Percolator,
RangeField,
RankFeature,
RankFeatures,
ScaledFloat,
SearchAsYouType,
Short,
Expand Down Expand Up @@ -139,6 +140,7 @@
"RangeFacet",
"RangeField",
"RankFeature",
"RankFeatures",
"SF",
"ScaledFloat",
"Search",
Expand Down
4 changes: 4 additions & 0 deletions elasticsearch_dsl/field.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,10 @@ class RankFeature(Float):
name = "rank_feature"


class RankFeatures(Field):
name = "rank_features"


class Integer(Field):
name = "integer"
_coerce = True
Expand Down
5 changes: 5 additions & 0 deletions tests/test_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def test_constant_keyword():
assert f.to_dict() == {"type": "constant_keyword"}


def test_rank_features():
f = field.RankFeatures()
assert f.to_dict() == {"type": "rank_features"}


def test_object_dynamic_values():
for dynamic in True, False, "strict":
f = field.Object(dynamic=dynamic)
Expand Down
10 changes: 9 additions & 1 deletion tests/test_integration/test_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
Nested,
Object,
Q,
RankFeatures,
Text,
analyzer,
)
Expand All @@ -52,6 +53,7 @@ class User(InnerDoc):
class Wiki(Document):
owner = Object(User)
views = Long()
ranked = RankFeatures()

class Index:
name = "test-wiki"
Expand Down Expand Up @@ -204,7 +206,11 @@ def test_nested_top_hits_are_wrapped_properly(pull_request):

def test_update_object_field(write_client):
Wiki.init()
w = Wiki(owner=User(name="Honza Kral"), _id="elasticsearch-py")
w = Wiki(
owner=User(name="Honza Kral"),
_id="elasticsearch-py",
ranked={"test1": 0.1, "topic2": 0.2},
)
w.save()

assert "updated" == w.update(owner=[{"name": "Honza"}, {"name": "Nick"}])
Expand All @@ -215,6 +221,8 @@ def test_update_object_field(write_client):
assert w.owner[0].name == "Honza"
assert w.owner[1].name == "Nick"

assert w.ranked == {"test1": 0.1, "topic2": 0.2}


def test_update_script(write_client):
Wiki.init()
Expand Down

0 comments on commit e7f8a90

Please sign in to comment.