Browse Source

Correct file search implementation

The behavior for searching "file" more closely matches the documented
behavior for "path".  Implement "path" the same as "file", then update
"file" so that the non-regex form matches path components.

Change-Id: I03bf6d5232472069ea288b1ce0fe955469791af1
changes/71/673371/2
James E. Blair 4 months ago
parent
commit
9105cbb232
2 changed files with 14 additions and 0 deletions
  1. +13
    -0
      gertty/search/parser.py
  2. +1
    -0
      gertty/search/tokenizer.py

+ 13
- 0
gertty/search/parser.py View File

@@ -95,6 +95,7 @@ def SearchParser():
| is_term
| status_term
| file_term
| path_term
| limit_term
| op_term'''
p[0] = p[1]
@@ -318,6 +319,18 @@ def SearchParser():

def p_file_term(p):
'''file_term : OP_FILE string'''
if p[2].startswith('^'):
p[0] = and_(or_(func.matches(p[2], gertty.db.file_table.c.path),
func.matches(p[2], gertty.db.file_table.c.old_path)),
gertty.db.file_table.c.status is not None)
else:
file_re = '(^|.*/)%s(/.*|$)' % re.escape(p[2])
p[0] = and_(or_(func.matches(file_re, gertty.db.file_table.c.path),
func.matches(file_re, gertty.db.file_table.c.old_path)),
gertty.db.file_table.c.status is not None)

def p_path_term(p):
'''path_term : OP_PATH string'''
if p[2].startswith('^'):
p[0] = and_(or_(func.matches(p[2], gertty.db.file_table.c.path),
func.matches(p[2], gertty.db.file_table.c.old_path)),

+ 1
- 0
gertty/search/tokenizer.py View File

@@ -36,6 +36,7 @@ operators = {
'message': 'OP_MESSAGE',
'comment': 'OP_COMMENT',
'file': 'OP_FILE',
'path': 'OP_PATH',
'has': 'OP_HAS',
'is': 'OP_IS',
'status': 'OP_STATUS',

Loading…
Cancel
Save