Improve lnk searching by separating field names from content.
Previously, if you searched for the word target then every lnk matched because "Target: xxx" was literally the text being searched. Now we can use the existing separation between search_text and result_text to show those headers separately.
This commit is contained in:
parent
d108670693
commit
66c26fa31a
1 changed files with 16 additions and 4 deletions
20
search.py
20
search.py
|
@ -25,6 +25,16 @@ if stat.S_ISFIFO(STDIN_MODE):
|
||||||
else:
|
else:
|
||||||
STDIN_MODE = 'terminal'
|
STDIN_MODE = 'terminal'
|
||||||
|
|
||||||
|
class HeaderedText:
|
||||||
|
def __init__(self, header, text):
|
||||||
|
self.header = header
|
||||||
|
self.text = text
|
||||||
|
|
||||||
|
@property
|
||||||
|
def with_header(self):
|
||||||
|
return f'{self.header}: {self.text}'
|
||||||
|
|
||||||
|
|
||||||
def all_terms_match(search_text, terms, match_function):
|
def all_terms_match(search_text, terms, match_function):
|
||||||
matches = (
|
matches = (
|
||||||
(not terms['yes_all'] or all(match_function(search_text, term) for term in terms['yes_all'])) and
|
(not terms['yes_all'] or all(match_function(search_text, term) for term in terms['yes_all'])) and
|
||||||
|
@ -70,11 +80,10 @@ def search_contents_windows_lnk(filepath, content_args):
|
||||||
return
|
return
|
||||||
|
|
||||||
text = [
|
text = [
|
||||||
f'Target: {shortcut.path}',
|
HeaderedText('Target', shortcut.path),
|
||||||
f'Start In: {shortcut.working_directory}',
|
HeaderedText('Start In', shortcut.working_directory),
|
||||||
f'Comment: {shortcut.description}',
|
HeaderedText('Comment', shortcut.description),
|
||||||
]
|
]
|
||||||
text = '\n'.join(text)
|
|
||||||
content_args['text'] = text
|
content_args['text'] = text
|
||||||
|
|
||||||
results = search(**content_args)
|
results = search(**content_args)
|
||||||
|
@ -161,6 +170,9 @@ def search(
|
||||||
if isinstance(search_object, pathclass.Path):
|
if isinstance(search_object, pathclass.Path):
|
||||||
search_text = search_object.basename
|
search_text = search_object.basename
|
||||||
result_text = search_object.absolute_path
|
result_text = search_object.absolute_path
|
||||||
|
elif isinstance(search_object, HeaderedText):
|
||||||
|
search_text = search_object.text
|
||||||
|
result_text = search_object.with_header
|
||||||
else:
|
else:
|
||||||
search_text = search_object
|
search_text = search_object
|
||||||
result_text = search_object
|
result_text = search_object
|
||||||
|
|
Loading…
Reference in a new issue