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 2 weeks 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():
95 95
                 | is_term
96 96
                 | status_term
97 97
                 | file_term
98
+                | path_term
98 99
                 | limit_term
99 100
                 | op_term'''
100 101
         p[0] = p[1]
@@ -318,6 +319,18 @@ def SearchParser():
318 319
 
319 320
     def p_file_term(p):
320 321
         '''file_term : OP_FILE string'''
322
+        if p[2].startswith('^'):
323
+            p[0] = and_(or_(func.matches(p[2], gertty.db.file_table.c.path),
324
+                            func.matches(p[2], gertty.db.file_table.c.old_path)),
325
+                        gertty.db.file_table.c.status is not None)
326
+        else:
327
+            file_re = '(^|.*/)%s(/.*|$)' % re.escape(p[2])
328
+            p[0] = and_(or_(func.matches(file_re, gertty.db.file_table.c.path),
329
+                            func.matches(file_re, gertty.db.file_table.c.old_path)),
330
+                        gertty.db.file_table.c.status is not None)
331
+
332
+    def p_path_term(p):
333
+        '''path_term : OP_PATH string'''
321 334
         if p[2].startswith('^'):
322 335
             p[0] = and_(or_(func.matches(p[2], gertty.db.file_table.c.path),
323 336
                             func.matches(p[2], gertty.db.file_table.c.old_path)),

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

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

Loading…
Cancel
Save