Skip to content

Commit

Permalink
added split_wildcards
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgarel committed Jun 25, 2018
1 parent 90eca61 commit 61dd13d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Added
-----

- handling `special characters escaping`_
- added iter_wildcards to have a finer grained search of wildcard in terms
- added `iter_wildcards` and `split_wildcards` to have a finer grained search of wildcard in terms

.. _`special characters escaping`: https://lucene.apache.org/core/3_6_0/queryparsersyntax.html#Escaping%20Special%20Characters

Expand Down
10 changes: 10 additions & 0 deletions luqum/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,16 @@ def test_term_iter_wildcard(self):
[((2, 3), "*"), ((5, 6), "*")],
)

def test_term_split_wildcard(self):
self.assertListEqual(
Term(r"a??b\*or*and\?").split_wildcards(),
["a", "?", "", "?", r"b\*or", "*", r"and\?"],
)
self.assertListEqual(
Term(r"\**\**").split_wildcards(),
[r"\*", "*", r"\*", "*", ""],
)

def test_equality_approx(self):
"""
Regression test for a bug on approx equalities.
Expand Down
5 changes: 5 additions & 0 deletions luqum/tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,11 @@ def iter_wildcards(self):
for matched in self.WILDCARDS_PATTERN.finditer(self.value):
yield matched.span(), matched.group()

def split_wildcards(self):
"""split term on wildcards
"""
return self.WILDCARDS_PATTERN.split(self.value)

def has_wildcard(self):
""":return bool: True if value contains a wildcards
"""
Expand Down

0 comments on commit 61dd13d

Please sign in to comment.