With the default Elgg search engine, both title and description are searched. I'm wondering if there's a way I can only search the keyword in title ? Thanks.
info@elgg.org
Security issues should be reported to security@elgg.org!
©2014 the Elgg Foundation
Elgg is a registered trademark of Thematic Networks.
Cover image by RaĆ¼l Utrera is used under Creative Commons license.
Icons by Flaticon and FontAwesome.
- Steve Clay@steve_clay
Steve Clay - 0 likes
- Liang Cheng@lcheng61
Liang Cheng - 0 likes
- Nikolai Shcherbin@rivervanrain
Nikolai Shcherbin - 0 likes
- Liang Cheng@lcheng61
Liang Cheng - 0 likes
- Vextah@Vextah_3598
Vextah - 0 likes
- Liang Cheng@lcheng61
Liang Cheng - 0 likes
You must log in to post replies.Look at the search hooks. Specifically you could unregister search_objects_hook (from hook search, object) and register your own function in its place. In your function, remove "description" from $fields.
Hi Steve,
I directly change the code inside /mod/search/search_hooks.php.
// $fields = array('title', 'description');
$fields = array('title');
However, I got this error when I search it at elgg webpage. Anything that I missed ?
Can't find FULLTEXT index matching the column list
QUERY: SELECT count(DISTINCT e.guid) as total FROM entities e JOIN objects_entity oe ON e.guid = oe.guid WHERE (MATCH (oe.title) AGAINST ('bonita' )) AND ((e.type = 'object' AND e.subtype IN (4))) AND (e.site_guid IN (1)) AND ( (1 = 1) and e.enabled='yes')
@Liang Cheng Don’t Modify Core
Use in your own plugin:
@RvR, thank you. But still I have the issues I reported earlier. I can't get search result by either "title" and "description" individually. I can only get search result when I have both defined in "$fields". What I did is I copied your code to my plugin, then I deactivate my plugin and activate it again. Did I miss anything ?
Did you upgrade to initiate the code changes?
Yes I did the upgrade. Still I got the same errors. Here I copied more text from my screen.
Fatal Error.
Can't find FULLTEXT index matching the column list
QUERY: SELECT count(DISTINCT e.guid) as total FROM entities e JOIN objects_entity oe ON e.guid = oe.guid WHERE (MATCH (oe.title) AGAINST ('test' )) AND ((e.type = 'object' AND e.subtype IN (4))) AND (e.site_guid IN (1)) AND ( (1 = 1) and e.enabled='yes')
DatabaseException Object
(
[message:protected] => Can't find FULLTEXT index matching the column list
QUERY: SELECT count(DISTINCT e.guid) as total FROM entities e JOIN objects_entity oe ON e.guid = oe.guid WHERE (MATCH (oe.title) AGAINST ('test' )) AND ((e.type = 'object' AND e.subtype IN (4))) AND (e.site_guid IN (1)) AND ( (1 = 1) and e.enabled='yes')
[string:Exception:private] => exception 'DatabaseException' with message 'Can't find FULLTEXT index matching the column list
QUERY: SELECT count(DISTINCT e.guid) as total FROM entities e JOIN objects_entity oe ON e.guid = oe.guid WHERE (MATCH (oe.title) AGAINST ('test' )) AND ((e.type = 'object' AND e.subtype IN (4))) AND (e.site_guid IN (1)) AND ( (1 = 1) and e.enabled='yes')' in /var/www/html/engine/lib/database.php:274
Stack trace:
#0 /var/www/html/engine/lib/database.php(416): execute_query('SELECT count(DI...', Resource id #3)
#1 /var/www/html/engine/lib/database.php(379): elgg_query_runner('SELECT count(DI...', '', true)
#2 /var/www/html/engine/lib/entities.php(1090): get_data_row('SELECT count(DI...')
#3 /var/www/html/mod/web_services/start.php(23): elgg_get_entities(Array)
#4 [internal function]: search_objects_my_hook('search', 'object', Array, Array)
#5 /var/www/html/engine/lib/elgglib.php(989): call_user_func_array('search_objects_...', Array)
#6 /var/www/html/mod/search/pages/search/index.php(186): elgg_trigger_plugin_hook('search', 'object', Array, Array)
#7 /var/www/html/mod/search/start.php(74): include_once('/var/www/html/m...')
#8 [internal function]: search_page_handler(Array, 'search')
#9 /var/www/html/engine/lib/pagehandler.php(53): call_user_func('search_page_han...', Array, 'search')
#10 /var/www/html/engine/handlers/page_handler.php(46): page_handler('search', NULL)
#11 {main}
[code:protected] => 0
[file:protected] => /var/www/html/engine/lib/database.php
[line:protected] => 274