[geeklog-cvs] geeklog: Added option to search by titles only (feature request ...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Thu Apr 23 18:03:26 EDT 2009
details: http://project.geeklog.net/cgi-bin/hgweb.cgi/rev/b2c7a634bafe
changeset: 6986:b2c7a634bafe
user: Sami Barakat
date: Thu Apr 23 22:58:11 2009 +0100
description:
Added option to search by titles only (feature request #0000840)
diffstat:
8 files changed, 38 insertions(+), 21 deletions(-)
language/english.php | 3 +-
language/english_utf-8.php | 3 +-
plugins/calendar/functions.inc | 4 +-
plugins/links/functions.inc | 2 -
plugins/staticpages/functions.inc | 2 -
public_html/layout/professional/search/searchform.thtml | 15 ++++++----
system/classes/search.class.php | 9 +++---
system/classes/searchcriteria.class.php | 21 +++++++++++----
diffs (168 lines):
diff -r fcd486b533bc -r b2c7a634bafe language/english.php
--- a/language/english.php Wed Apr 22 22:48:06 2009 +0100
+++ b/language/english.php Thu Apr 23 22:58:11 2009 +0100
@@ -528,7 +528,8 @@
65 => 'Story',
66 => 'Comment',
67 => 'Show %d Results',
- 68 => 'Sort By'
+ 68 => 'Sort By',
+ 69 => 'Titles Only'
);
###############################################################################
diff -r fcd486b533bc -r b2c7a634bafe language/english_utf-8.php
--- a/language/english_utf-8.php Wed Apr 22 22:48:06 2009 +0100
+++ b/language/english_utf-8.php Thu Apr 23 22:58:11 2009 +0100
@@ -528,7 +528,8 @@
65 => 'Story',
66 => 'Comment',
67 => 'Show %d Results',
- 68 => 'Sort By'
+ 68 => 'Sort By',
+ 69 => 'Titles Only'
);
###############################################################################
diff -r fcd486b533bc -r b2c7a634bafe plugins/calendar/functions.inc
--- a/plugins/calendar/functions.inc Wed Apr 22 22:48:06 2009 +0100
+++ b/plugins/calendar/functions.inc Thu Apr 23 22:58:11 2009 +0100
@@ -1645,7 +1645,7 @@
// Search the public events
$search_e = new SearchCriteria('calendar', array($LANG_CAL_1[16],$LANG_CAL_1[24]));
- $columns = array('location','description','title');
+ $columns = array('location', 'description', 'title' => 'title');
list($sql_tmp,$ftsql_tmp) = $search_e->buildSearchSQL($keyType, $query, $columns, $sql_e . $sql);
$search_e->setSQL($sql_tmp);
$search_e->setFTSQL($ftsql_tmp);
@@ -1653,7 +1653,7 @@
// Search personal events
$search_p = new SearchCriteria('calendar', array($LANG_CAL_1[16],$LANG_CAL_1[23]));
- $columns = array('location','description','title');
+ $columns = array('location', 'description','title' => 'title');
list($sql_tmp,$ftsql_tmp) = $search_p->buildSearchSQL($keyType, $query, $columns, $sql_p . $sql);
$search_p->setSQL($sql_tmp);
$search_p->setFTSQL($ftsql_tmp);
diff -r fcd486b533bc -r b2c7a634bafe plugins/links/functions.inc
--- a/plugins/links/functions.inc Wed Apr 22 22:48:06 2009 +0100
+++ b/plugins/links/functions.inc Thu Apr 23 22:58:11 2009 +0100
@@ -384,7 +384,7 @@
}
$search = new SearchCriteria('links', $LANG_LINKS[14]);
- $columns = array('description','title');
+ $columns = array('description', 'title' => 'title');
list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
$search->setSQL($sql);
$search->setFTSQL($ftsql);
diff -r fcd486b533bc -r b2c7a634bafe plugins/staticpages/functions.inc
--- a/plugins/staticpages/functions.inc Wed Apr 22 22:48:06 2009 +0100
+++ b/plugins/staticpages/functions.inc Thu Apr 23 22:58:11 2009 +0100
@@ -622,7 +622,7 @@
}
$search = new SearchCriteria('staticpages', $LANG_STATIC['staticpages']);
- $columns = array('sp_content','sp_title');
+ $columns = array('sp_content', 'title' => 'sp_title');
list($sql,$ftsql) = $search->buildSearchSQL($keyType, $query, $columns, $sql);
$search->setSQL($sql);
$search->setFTSQL($ftsql);
diff -r fcd486b533bc -r b2c7a634bafe public_html/layout/professional/search/searchform.thtml
--- a/public_html/layout/professional/search/searchform.thtml Wed Apr 22 22:48:06 2009 +0100
+++ b/public_html/layout/professional/search/searchform.thtml Thu Apr 23 22:58:11 2009 +0100
@@ -3,12 +3,15 @@
<table cellspacing="0" cellpadding="3">
<tr>
<td class="alignright">{lang_keywords}:</td>
- <td><input type="text" name="query" size="35" maxlength="35" value="{query}"{xhtml}>
- <select name="keyType">
- <option value="phrase" {key_phrase_selected}>{lang_exact_phrase}</option>
- <option value="all" {key_all_selected}>{lang_all_words}</option>
- <option value="any" {key_any_selected}>{lang_any_word}</option>
- </select></td>
+ <td>
+ <input type="text" name="query" size="35" maxlength="35" value="{query}"{xhtml}>
+ <select name="keyType">
+ <option value="phrase" {key_phrase_selected}>{lang_exact_phrase}</option>
+ <option value="all" {key_all_selected}>{lang_all_words}</option>
+ <option value="any" {key_any_selected}>{lang_any_word}</option>
+ </select>
+ <input type="checkbox" value="true" name="title"/>{lang_titles}
+ </td>
</tr>
<tr>
<td class="alignright">{lang_date}:</td>
diff -r fcd486b533bc -r b2c7a634bafe system/classes/search.class.php
--- a/system/classes/search.class.php Wed Apr 22 22:48:06 2009 +0100
+++ b/system/classes/search.class.php Thu Apr 23 22:58:11 2009 +0100
@@ -237,6 +237,7 @@
$searchform->set_var('lang_exact_phrase', $LANG09[43]);
$searchform->set_var('lang_all_words', $LANG09[44]);
$searchform->set_var('lang_any_word', $LANG09[45]);
+ $searchform->set_var('lang_titles', $LANG09[69]);
$searchform->set_var ('query', htmlspecialchars ($this->_query));
$searchform->set_var ('datestart', $this->_dateStart);
@@ -374,8 +375,8 @@
}
$search = new SearchCriteria('stories', $LANG09[65]);
- $columns = array('introtext','bodytext','title');
- list( $sql, $ftsql ) = $search->buildSearchSQL( $this->_keyType, $query, $columns, $sql );
+ $columns = array('introtext', 'bodytext', 'title' => 'title');
+ list($sql, $ftsql) = $search->buildSearchSQL($this->_keyType, $query, $columns, $sql);
$search->setSQL($sql);
$search->setFTSQL($ftsql);
$search->setRank(5);
@@ -434,8 +435,8 @@
}
$search = new SearchCriteria('comments', $LANG09[66]);
- $columns = array('comment','c.title');
- list( $sql, $ftsql ) = $search->buildSearchSQL( $this->_keyType, $query, $columns, $sql );
+ $columns = array('comment', 'title' => 'c.title');
+ list($sql, $ftsql) = $search->buildSearchSQL($this->_keyType, $query, $columns, $sql);
$search->setSQL($sql);
$search->setFTSQL($ftsql);
$search->setRank(2);
diff -r fcd486b533bc -r b2c7a634bafe system/classes/searchcriteria.class.php
--- a/system/classes/searchcriteria.class.php Wed Apr 22 22:48:06 2009 +0100
+++ b/system/classes/searchcriteria.class.php Thu Apr 23 22:58:11 2009 +0100
@@ -139,7 +139,14 @@
$ftwords['mssql'] = '"' . $query . '"';
}
- $strcol = implode(',',$columns);
+ $titles = (isset($_GET['title']) && isset($columns['title'])) ? true : false;
+
+ if ($titles) {
+ $strcol = $columns['title'];
+ } else {
+ $strcol = implode(',', $columns);
+ }
+
$ftsql['mysql'] = $sql . "AND MATCH($strcol) AGAINST ('{$ftwords['mysql']}' IN BOOLEAN MODE)";
$ftsql['mssql'] = $sql . "AND CONTAINS(($strcol), '{$ftwords['mssql']}')";
@@ -148,11 +155,15 @@
{
$word = trim($word);
$tmp .= '(';
- foreach ($columns AS $col) {
- $tmp .= "$col LIKE '%$word%' OR ";
+
+ if ($titles) {
+ $tmp .= $columns['title'] . " LIKE '%$word%' OR ";
+ } else {
+ foreach ($columns AS $col) {
+ $tmp .= "$col LIKE '%$word%' OR ";
+ }
}
-
- $tmp = substr($tmp,0,-4) . ") $sep ";
+ $tmp = substr($tmp, 0, -4) . ") $sep ";
}
$sql .= substr($tmp, 0, -5) . ') ';
More information about the geeklog-cvs
mailing list