mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-02 21:19:12 +00:00
Add method to extract filter terms from query to all filters
- Test the get_filter_term method in all 3 word, file, date filters - Make the existing can_filter method by default in base filter abstract class
This commit is contained in:
@@ -158,3 +158,23 @@ def test_date_filter_regex():
|
||||
|
||||
dtrange_match = re.findall(DateFilter().date_regex, "head tail")
|
||||
assert dtrange_match == []
|
||||
|
||||
|
||||
def test_get_file_filter_terms():
|
||||
dtrange_match = DateFilter().get_filter_terms('multi word head dt>"today" dt:"1984-01-01"')
|
||||
assert dtrange_match == ["dt>'today'", "dt:'1984-01-01'"]
|
||||
|
||||
dtrange_match = DateFilter().get_filter_terms('head dt>"today" dt:"1984-01-01" multi word tail')
|
||||
assert dtrange_match == ["dt>'today'", "dt:'1984-01-01'"]
|
||||
|
||||
dtrange_match = DateFilter().get_filter_terms('multi word head dt>="today" dt="1984-01-01"')
|
||||
assert dtrange_match == ["dt>='today'", "dt='1984-01-01'"]
|
||||
|
||||
dtrange_match = DateFilter().get_filter_terms('dt<"multi word date" multi word tail')
|
||||
assert dtrange_match == ["dt<'multi word date'"]
|
||||
|
||||
dtrange_match = DateFilter().get_filter_terms('head dt<="multi word date"')
|
||||
assert dtrange_match == ["dt<='multi word date'"]
|
||||
|
||||
dtrange_match = DateFilter().get_filter_terms("head tail")
|
||||
assert dtrange_match == []
|
||||
|
||||
@@ -99,6 +99,18 @@ def test_multiple_file_filter():
|
||||
assert entry_indices == {0, 1, 2, 3}
|
||||
|
||||
|
||||
def test_get_file_filter_terms():
|
||||
# Arrange
|
||||
file_filter = FileFilter()
|
||||
q_with_filter_terms = 'head tail file:"file 1.org" file:"/path/to/dir/*.org"'
|
||||
|
||||
# Act
|
||||
filter_terms = file_filter.get_filter_terms(q_with_filter_terms)
|
||||
|
||||
# Assert
|
||||
assert filter_terms == ['file:"file 1.org"', 'file:"/path/to/dir/*.org"']
|
||||
|
||||
|
||||
def arrange_content():
|
||||
entries = [
|
||||
Entry(compiled="", raw="First Entry", file="file 1.org"),
|
||||
|
||||
@@ -67,6 +67,18 @@ def test_word_include_and_exclude_filter():
|
||||
assert entry_indices == {2}
|
||||
|
||||
|
||||
def test_get_word_filter_terms():
|
||||
# Arrange
|
||||
word_filter = WordFilter()
|
||||
query_with_include_and_exclude_filter = 'head +"include_word" -"exclude_word" tail'
|
||||
|
||||
# Act
|
||||
filter_terms = word_filter.get_filter_terms(query_with_include_and_exclude_filter)
|
||||
|
||||
# Assert
|
||||
assert filter_terms == ["+include_word", "-exclude_word"]
|
||||
|
||||
|
||||
def arrange_content():
|
||||
entries = [
|
||||
Entry(compiled="", raw="Minimal Entry"),
|
||||
|
||||
Reference in New Issue
Block a user