Post search: Search other fields too

This commit is contained in:
Michael Foster 2013-07-29 20:20:07 -04:00
parent d44b4f19a8
commit 1759ac2ea3
2 changed files with 15 additions and 3 deletions

View File

@ -174,6 +174,11 @@ function mod_search_redirect() {
$query = str_replace('_', '%5F', $query); $query = str_replace('_', '%5F', $query);
$query = str_replace('+', '_', $query); $query = str_replace('+', '_', $query);
if ($query === '') {
header('Location: ?/', true, $config['redirect_http']);
return;
}
header('Location: ?/search/' . $_POST['type'] . '/' . $query, true, $config['redirect_http']); header('Location: ?/search/' . $_POST['type'] . '/' . $query, true, $config['redirect_http']);
} else { } else {
header('Location: ?/', true, $config['redirect_http']); header('Location: ?/', true, $config['redirect_http']);
@ -225,7 +230,7 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
// Which `field` to search? // Which `field` to search?
if ($type == 'posts') if ($type == 'posts')
$sql_field = 'body_nomarkup'; $sql_field = array('body_nomarkup', 'filename', 'subject', 'filehash', 'ip', 'name', 'trip');
if ($type == 'IP_notes') if ($type == 'IP_notes')
$sql_field = 'body'; $sql_field = 'body';
if ($type == 'bans') if ($type == 'bans')
@ -239,8 +244,15 @@ function mod_search($type, $search_query_escaped, $page_no = 1) {
if (!empty($sql_like)) if (!empty($sql_like))
$sql_like .= ' AND '; $sql_like .= ' AND ';
$phrase = preg_replace('/^\'(.+)\'$/', '\'%$1%\'', $phrase); $phrase = preg_replace('/^\'(.+)\'$/', '\'%$1%\'', $phrase);
if (is_array($sql_field)) {
foreach ($sql_field as $field) {
$sql_like .= '`' . $field . '` LIKE ' . $phrase . ' ESCAPE \'!\' OR';
}
$sql_like = preg_replace('/ OR$/', '', $sql_like);
} else {
$sql_like .= '`' . $sql_field . '` LIKE ' . $phrase . ' ESCAPE \'!\''; $sql_like .= '`' . $sql_field . '` LIKE ' . $phrase . ' ESCAPE \'!\'';
} }
}
// Compile SQL query // Compile SQL query

View File

@ -246,7 +246,7 @@
</td> </td>
<td style="max-width:200px"> <td style="max-width:200px">
{% if post.file %} {% if post.file %}
<small>{{ post.file }} ({{ post.filesize | filesize }})</small> <small>{{ post.filename }} ({{ post.filesize | filesize }})</small>
{% else %} {% else %}
&ndash; &ndash;
{% endif %} {% endif %}