Commit ce2ecbe3bec63a950b6434d79ae6474c6e54f72d
1 parent
8cfec2f1
KTS-3754
"Doing a search for anything via the Search text box at the top of the browser page results in a DB error." Fixed. Committed By: Conrad Vermeulen Reviewed By: Megan Watson git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@9466 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
2 changed files
with
19 additions
and
9 deletions
search2/indexing/indexerCore.inc.php
| ... | ... | @@ -1069,13 +1069,13 @@ abstract class Indexer |
| 1069 | 1069 | $docsInIndex = $index->getDocumentsInIndex(); |
| 1070 | 1070 | |
| 1071 | 1071 | // we are only interested in documents that are active |
| 1072 | - $sql = "SELECT count(*) as docsInQueue FROM index_files"; | |
| 1072 | + $sql = "SELECT count(*) as docsInQueue FROM index_files i inner join documents d on i.document_id = d.id where d.status_id=1"; | |
| 1073 | 1073 | $docsInQueue = DBUtil::getOneResultKey($sql, 'docsInQueue'); |
| 1074 | 1074 | |
| 1075 | - $sql = "SELECT count(*) as errorsInQueue FROM index_files where status_msg is not null or status_msg <> ''"; | |
| 1075 | + $sql = "SELECT count(*) as errorsInQueue FROM index_files i inner join documents d on i.document_id = d.id where (i.status_msg is not null or i.status_msg <> '') and d.status_id=1"; | |
| 1076 | 1076 | $errorsInQueue = DBUtil::getOneResultKey($sql, 'errorsInQueue'); |
| 1077 | 1077 | |
| 1078 | - $sql = "SELECT count(*) as docsInRepository FROM documents"; | |
| 1078 | + $sql = "SELECT count(*) as docsInRepository FROM documents where status_id=1"; | |
| 1079 | 1079 | $docsInRepository = DBUtil::getOneResultKey($sql, 'docsInRepository'); |
| 1080 | 1080 | |
| 1081 | 1081 | if ($docsInRepository == 0) | ... | ... |
search2/search/expr.inc.php
| ... | ... | @@ -1176,7 +1176,7 @@ class SQLQueryBuilder implements QueryBuilder |
| 1176 | 1176 | if (count($this->metadata) + count($this->db) == 0) |
| 1177 | 1177 | { |
| 1178 | 1178 | // return empty result set |
| 1179 | - return 'select 1 from documents where false'; | |
| 1179 | + return ''; | |
| 1180 | 1180 | } |
| 1181 | 1181 | |
| 1182 | 1182 | $sql = |
| ... | ... | @@ -1361,13 +1361,14 @@ class SQLQueryBuilder implements QueryBuilder |
| 1361 | 1361 | $this->exploreExprs($expr); |
| 1362 | 1362 | |
| 1363 | 1363 | $sql = $this->buildCoreSQL(); |
| 1364 | - | |
| 1365 | - $expr = $this->buildCoreSQLExpr($expr); | |
| 1366 | - if ($expr != 'false') | |
| 1364 | + if (empty($sql)) | |
| 1367 | 1365 | { |
| 1368 | - $sql .= $expr; | |
| 1366 | + return ''; | |
| 1369 | 1367 | } |
| 1370 | 1368 | |
| 1369 | + $expr = $this->buildCoreSQLExpr($expr); | |
| 1370 | + $sql .= $expr; | |
| 1371 | + | |
| 1371 | 1372 | return $sql; |
| 1372 | 1373 | } |
| 1373 | 1374 | |
| ... | ... | @@ -2142,8 +2143,12 @@ class OpExpr extends Expr |
| 2142 | 2143 | $sql = $exprbuilder->buildSimpleQuery($op, $group); |
| 2143 | 2144 | } |
| 2144 | 2145 | |
| 2145 | - $results = array(); | |
| 2146 | + if (empty($sql)) | |
| 2147 | + { | |
| 2148 | + return array(); | |
| 2149 | + } | |
| 2146 | 2150 | |
| 2151 | + $results = array(); | |
| 2147 | 2152 | global $default; |
| 2148 | 2153 | $default->log->debug("SEARCH SQL: $sql"); |
| 2149 | 2154 | $rs = DBUtil::getResultArray($sql); |
| ... | ... | @@ -2192,6 +2197,11 @@ class OpExpr extends Expr |
| 2192 | 2197 | $query = $exprbuilder->buildSimpleQuery($op, $group); |
| 2193 | 2198 | } |
| 2194 | 2199 | |
| 2200 | + if (empty($query)) | |
| 2201 | + { | |
| 2202 | + return array(); | |
| 2203 | + } | |
| 2204 | + | |
| 2195 | 2205 | $indexer = Indexer::get(); |
| 2196 | 2206 | global $default; |
| 2197 | 2207 | $default->log->debug("SEARCH LUCENE: $query"); | ... | ... |