Browse Source

fall back to substring search when fts fails, instead of just throwing an error

Byron Jones 6 years ago
parent
commit
1e0259a1c0
1 changed files with 4 additions and 5 deletions
  1. 4 5
      lib/LogBot/Web/Search.pm

+ 4 - 5
lib/LogBot/Web/Search.pm

@@ -111,19 +111,18 @@ sub render {
                     $dbh->selectrow_array('SELECT COUNT(*) FROM logs_fts WHERE logs_fts MATCH ?', undef, $quoted_q);
             }
             catch {
+                # an error here means that fts failed somehow (there's some odd
+                # syntax).  log so we can investigate later, and drop back to
+                # substring.
                 $c->app->log->error($_);
                 $count = -1;
             };
-            if ($count == -1) {
-                $c->stash(error => 'Internal error while executing search, please try a different query.');
-                return $c->render('search');
-            }
 
             # fts is _fast_, however if it returns a massive number of rows,
             # sqlite can be slow at ordering.  if there are more than an
             # arbitrary amount of hits, switch to a substring search, which
             # will execute much faster.
-            if ($count > $SEARCH_FTS_LIMIT) {
+            if ($count == -1 || $count > $SEARCH_FTS_LIMIT) {
                 push @where,  'text LIKE ?';
                 push @values, like_value($q);