diff --git a/include/functions_search.inc.php b/include/functions_search.inc.php index 5f1afa414..a86429be3 100644 --- a/include/functions_search.inc.php +++ b/include/functions_search.inc.php @@ -1568,4 +1568,29 @@ function get_search_results($search_id, $super_order_by, $images_where='') } } +function split_allwords($raw_allwords) +{ + $words = null; + + if (!preg_match('/^\s*$/', $raw_allwords)) + { + $drop_char_match = array('-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_','?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*'); + $drop_char_replace = array(' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','', '', ' ',' ',' ',' ','', ' ',' ',' ',' ',' ',' ',' ',' ',' ','' , ' ',' ',' ', ' ',' '); + + // Split words + $words = array_unique( + preg_split( + '/\s+/', + str_replace( + $drop_char_match, + $drop_char_replace, + $raw_allwords + ) + ) + ); + } + + return $words; +} + ?> diff --git a/include/ws_functions/pwg.images.php b/include/ws_functions/pwg.images.php index eae6b13d6..5b9e5b086 100644 --- a/include/ws_functions/pwg.images.php +++ b/include/ws_functions/pwg.images.php @@ -700,6 +700,7 @@ SELECT * function ws_images_filteredSearch_update($params, $service) { // echo json_encode($params); exit(); + include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php'); // * check the search exists $query = ' @@ -746,30 +747,7 @@ SELECT id } $search['fields']['allwords']['fields'] = $params['allwords_fields']; - $search['fields']['allwords']['words'] = null; - if (!preg_match('/^\s*$/', $params['allwords'])) - { - $drop_char_match = array( - '-','^','$',';','#','&','(',')','<','>','`','\'','"','|',',','@','_', - '?','%','~','.','[',']','{','}',':','\\','/','=','\'','!','*' - ); - $drop_char_replace = array( - ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','','',' ',' ',' ',' ','',' ', - ' ',' ',' ',' ',' ',' ',' ',' ','' ,' ',' ',' ',' ',' ' - ); - - // Split words - $search['fields']['allwords']['words'] = array_unique( - preg_split( - '/\s+/', - str_replace( - $drop_char_match, - $drop_char_replace, - $params['allwords'] - ) - ) - ); - } + $search['fields']['allwords']['words'] = split_allwords($params['allwords']); } if (isset($params['tags'])) diff --git a/qsearch.php b/qsearch.php index 0a1ef55bc..785894144 100644 --- a/qsearch.php +++ b/qsearch.php @@ -14,46 +14,10 @@ include_once( PHPWG_ROOT_PATH.'include/common.inc.php' ); // +-----------------------------------------------------------------------+ check_status(ACCESS_GUEST); -if (empty($_GET['q'])) -{ - redirect( make_index_url() ); -} +// if (empty($_GET['q'])) +// { +// redirect( make_index_url() ); +// } -$search = array(); -$search['q']=$_GET['q']; - -$query = ' -SElECT id FROM '.SEARCH_TABLE.' - WHERE rules = \''.addslashes(serialize($search)).'\' -;'; -$search_id = array_from_query( $query, 'id'); -if ( !empty($search_id) ) -{ - $search_id = $search_id[0]; - $query = ' -UPDATE '.SEARCH_TABLE.' - SET last_seen=NOW() - WHERE id='.$search_id; - pwg_query($query); -} -else -{ - $query =' -INSERT INTO '.SEARCH_TABLE.' - (rules, last_seen) - VALUES - (\''.addslashes(serialize($search)).'\', NOW() ) -;'; - pwg_query($query); - $search_id = pwg_db_insert_id(SEARCH_TABLE); -} - -redirect( - make_index_url( - array( - 'section' => 'search', - 'search' => $search_id, - ) - ) - ); +redirect(get_root_url().'search.php?q='.$_GET['q']); ?> \ No newline at end of file diff --git a/search.php b/search.php index c59846b21..35422d3cf 100644 --- a/search.php +++ b/search.php @@ -21,11 +21,18 @@ trigger_notify('loc_begin_search'); // | Create a default search | // +-----------------------------------------------------------------------+ +$words = array(); +if (!empty($_GET['q'])) +{ + include_once(PHPWG_ROOT_PATH.'include/functions_search.inc.php'); + $words = split_allwords($_GET['q']); +} + $search = array( 'mode' => 'AND', 'fields' => array( 'allwords' => array( - 'words' => array(), + 'words' => $words, 'mode' => 'AND', 'fields' => array('file', 'name', 'comment', 'tags', 'cat-title', 'cat-desc'), ),