changeset 6473:73e3599971da

journal: make "repository:" filtering condition work as expected (Issue #261) Before this revision, journal filtering conditions like as below never match against any entry, even if there are corresponded repositories. - repository:foo/bar - repository:foo-bar Whoosh library, which is used to parse filtering condition, does: - treat almost all non-alphanumeric characters as delimiter at parsing condition - join each conditions at filtering by "AND", by default For example, filtering condition "repository:foo/bar" is translated as "repository:foo AND repository:bar". This combined condition never matches against any entry, because it is impossible that "repository" field in DBMS table "user_logs" has both "foo" and "bar" values at same time. Using TEXT for "repository" of JOURNAL_SCHEMA causes this issue, because TEXT assumes tokenization at parsing. In addition to it, using TEXT also causes unintentional ignorance of "stop words" in filtering conditions. For example, "this", "a", "you", and so on are ignored at parsing, because these are too generic words (from point of view of generic "text search"). To make "repository:" filtering condition work as expected, this revision uses ID instead of TEST for "repository" of JOURNAL_COLUMN. ID avoids both tokenization and removing "stop words". This replacement should be safe with already existing DBMS instance, because: - JOURNAL_SCHEMA is used only to parse filtering condition - DBMS table "user_logs" itself is defined by UserLog class (in kallithea/model/db.py) BTW, using ID also avoids normalization by lowercase-ing. But this doesn't violate current case-insensitive search policy, because LOWER-ing in actual SQL query is achieved by get_filterion() or so in kallithea/controllers/admin/admin.py.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Mon, 23 Jan 2017 02:17:38 +0900
parents e6224a7c3d4e
children 2ff913970025
files kallithea/lib/indexers/__init__.py kallithea/tests/functional/test_admin.py
diffstat 2 files changed, 5 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/indexers/__init__.py	Mon Jan 23 02:17:38 2017 +0900
+++ b/kallithea/lib/indexers/__init__.py	Mon Jan 23 02:17:38 2017 +0900
@@ -82,7 +82,7 @@
     username=TEXT(),
     date=DATETIME(),
     action=TEXT(),
-    repository=TEXT(),
+    repository=ID(),
     ip=TEXT(),
 )
 
--- a/kallithea/tests/functional/test_admin.py	Mon Jan 23 02:17:38 2017 +0900
+++ b/kallithea/tests/functional/test_admin.py	Mon Jan 23 02:17:38 2017 +0900
@@ -151,12 +151,12 @@
     @parametrize('filter,hit', [
         #### "repository:" filtering
         # "/" is used for grouping
-        ('repository:group/test', 0),
+        ('repository:group/test', 4),
         # "-" is often used for "-fork"
-        ('repository:fork-test1', 0),
+        ('repository:fork-test1', 5),
         # using "stop words"
-        ('repository:this', 2036),
-        ('repository:this/is-it', 2036),
+        ('repository:this', 1),
+        ('repository:this/is-it', 1),
 
         ## additional tests to quickly find out regression in the future
         ## (and check case-insensitive search, too)