Skip to content

Commit

Permalink
Make F() nad Q() neutral elements
Browse files Browse the repository at this point in the history
Fixes #166 Thanks mdj2 for the report!
  • Loading branch information
honzakral committed May 27, 2015
1 parent 3c8af33 commit edfdbc8
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion elasticsearch_dsl/filter.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from .utils import DslBase, BoolMixin, _make_dsl_class

def F(name_or_filter, filters=None, **params):
def F(name_or_filter='match_all', filters=None, **params):
# 'and/or', [F(), F()]
if filters is not None:
# someone passed in positional argument to F outside of and/or or query
Expand Down
2 changes: 1 addition & 1 deletion elasticsearch_dsl/query.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from .utils import DslBase, BoolMixin, _make_dsl_class
from .function import SF, ScoreFunction

def Q(name_or_query, **params):
def Q(name_or_query='match_all', **params):
# {"match": {"title": "python"}}
if isinstance(name_or_query, dict):
if params:
Expand Down
6 changes: 6 additions & 0 deletions test_elasticsearch_dsl/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

from pytest import raises

def test_empty_F_is_match_all():
f = filter.F()

assert isinstance(f, filter.MatchAll)
assert filter.MatchAll() == f

def test_and_can_be_created_with_a_list():
f = filter.F('and', [filter.F('term', field='value')])

Expand Down
6 changes: 6 additions & 0 deletions test_elasticsearch_dsl/test_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

from pytest import raises

def test_empty_Q_is_match_all():
q = query.Q()

assert isinstance(q, query.MatchAll)
assert query.MatchAll() == q

def test_match_to_dict():
assert {"match": {"f": "value"}} == query.Match(f='value').to_dict()

Expand Down

0 comments on commit edfdbc8

Please sign in to comment.