Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for search_regex_function #94

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

anishsane
Copy link

This can be used to generate regex to limit the search query to a substring within the menu entries.
e.g.
Menu entries may be defined as

[
" 1 : menu A : 2024/09/18",
" 2 : menu B : 2024/09/17",
" 3 : menu C : 2024/09/19",
...
"10 : menu J : 2023/09/10"
]

If I want to limit the search to just the serial number, I can change the search string '2' to regex '^2', so that it does not match 2024.

For this, I can provide an optional parameter search_regex_function defined as:

def my_search_regex_function(text):
    if re.match('[0-9][0-9]*$', text) and int(text) < len(menu_items):
        text = f'^ *{text}(?= : )'
    return re.compile(text, flags=re.IGNORECASE)

With the above function, 2 will only match menu B. 2024 will match all menu entries. The function itself can be customized for individual requirements.

This can be used to generate regex to limit the search query to
substring within the menu entries.
e.g.
A menu entries may be defined as
[
" 1 : menu A : 2024/09/18",
" 2 : menu B : 2024/09/17",
" 3 : menu C : 2024/09/19",
...
"10 : menu J : 2023/09/10"
]

If I want to limit the search to just the serial number, I can change
the search string '2' to regex '^2', so that it does not match '2'024.

For this, I can provide an optional parameter search_regex_function
defined as:

def my_search_regex_function(text):
    if re.match('[0-9][0-9]*$', text) and int(text) < len(menu_items):
        text = f'^ *{text}(?= : )'
    return re.compile(text, flags=re.IGNORECASE)

With above function, 2 will only match menu B. 2024 will match all menu entries.
The function itself can be customized for individual requirements.
The search regex functionality had a logic to highlight the pattern.
With the search_regex_function logic the highlight functionality was
getting lost, because we used additional anchors like
^/$/lookahead/lookbehind, etc.

So, this change limits the custom function to filtering logic, while
keeping the original logic for highlighting.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant