@@ -42,6 +42,12 @@ class fulltext_mysql extends \phpbb\search\base
4242 */
4343 protected $ db ;
4444
45+ /**
46+ * phpBB event dispatcher object
47+ * @var \phpbb\event\dispatcher_interface
48+ */
49+ protected $ phpbb_dispatcher ;
50+
4551 /**
4652 * User object
4753 * @var \phpbb\user
@@ -79,11 +85,13 @@ class fulltext_mysql extends \phpbb\search\base
7985 * @param \phpbb\config\config $config Config object
8086 * @param \phpbb\db\driver\driver_interface Database object
8187 * @param \phpbb\user $user User object
88+ * @param \phpbb\event\dispatcher_interface $phpbb_dispatcher Event dispatcher object
8289 */
83- public function __construct (&$ error , $ phpbb_root_path , $ phpEx , $ auth , $ config , $ db , $ user )
90+ public function __construct (&$ error , $ phpbb_root_path , $ phpEx , $ auth , $ config , $ db , $ user, $ phpbb_dispatcher )
8491 {
8592 $ this ->config = $ config ;
8693 $ this ->db = $ db ;
94+ $ this ->phpbb_dispatcher = $ phpbb_dispatcher ;
8795 $ this ->user = $ user ;
8896
8997 $ this ->word_length = array ('min ' => $ this ->config ['fulltext_mysql_min_word_len ' ], 'max ' => $ this ->config ['fulltext_mysql_max_word_len ' ]);
@@ -447,6 +455,55 @@ public function keyword_search($type, $fields, $terms, $sort_by_sql, $sort_key,
447455 break ;
448456 }
449457
458+ $ search_query = $ this ->search_query ;
459+
460+ /**
461+ * Allow changing the query used to search for posts using fulltext_mysql
462+ *
463+ * @event core.search_mysql_keywords_main_query_before
464+ * @var string search_query The parsed keywords used for this search
465+ * @var int result_count The previous result count for the format of the query.
466+ * Set to 0 to force a re-count
467+ * @var bool join_topic Weather or not TOPICS_TABLE should be CROSS JOIN'ED
468+ * @var array author_ary Array of user_id containing the users to filter the results to
469+ * @var string author_name An extra username to search on (!empty(author_ary) must be true, to be relevant)
470+ * @var array ex_fid_ary Which forums not to search on
471+ * @var int topic_id Limit the search to this topic_id only
472+ * @var string sql_sort_table Extra tables to include in the SQL query.
473+ * Used in conjunction with sql_sort_join
474+ * @var string sql_sort_join SQL conditions to join all the tables used together.
475+ * Used in conjunction with sql_sort_table
476+ * @var int sort_days Time, in days, of the oldest possible post to list
477+ * @var string sql_match Which columns to do the search on.
478+ * @var string sql_match_where Extra conditions to use to properly filter the matching process
479+ * @var string sort_by_sql The possible predefined sort types
480+ * @var string sort_key The sort type used from the possible sort types
481+ * @var string sort_dir "a" for ASC or "d" dor DESC for the sort order used
482+ * @var string sql_sort The result SQL when processing sort_by_sql + sort_key + sort_dir
483+ * @var int start How many posts to skip in the search results (used for pagination)
484+ * @since 3.1.5-RC1
485+ */
486+ $ vars = array (
487+ 'search_query ' ,
488+ 'result_count ' ,
489+ 'join_topic ' ,
490+ 'author_ary ' ,
491+ 'author_name ' ,
492+ 'ex_fid_ary ' ,
493+ 'topic_id ' ,
494+ 'sql_sort_table ' ,
495+ 'sql_sort_join ' ,
496+ 'sort_days ' ,
497+ 'sql_match ' ,
498+ 'sql_match_where ' ,
499+ 'sort_by_sql ' ,
500+ 'sort_key ' ,
501+ 'sort_dir ' ,
502+ 'sql_sort ' ,
503+ 'start ' ,
504+ );
505+ extract ($ this ->phpbb_dispatcher ->trigger_event ('core.search_mysql_keywords_main_query_before ' , compact ($ vars )));
506+
450507 $ sql_select = (!$ result_count ) ? 'SQL_CALC_FOUND_ROWS ' : '' ;
451508 $ sql_select = ($ type == 'posts ' ) ? $ sql_select . 'p.post_id ' : 'DISTINCT ' . $ sql_select . 't.topic_id ' ;
452509 $ sql_from = ($ join_topic ) ? TOPICS_TABLE . ' t, ' : '' ;
0 commit comments