$recency_bonus, 'cutoff' => $recency_cutoff_date, ); } /** * Introduces the query variables for Relevanssi Premium. * * @param array $qv The WordPress query variable array. */ function relevanssi_premium_query_vars( $qv ) { $qv[] = 'searchblogs'; $qv[] = 'customfield_key'; $qv[] = 'customfield_value'; $qv[] = 'operator'; $qv[] = 'include_attachments'; $qv[] = 'coordinates'; return $qv; } /** * Sets the operator parameter. * * The operator parameter is taken from $query->query_vars['operator'], * or from the implicit operator setting. * * @param object $query The query object. */ function relevanssi_set_operator( $query ) { if ( isset( $query->query_vars['operator'] ) ) { $operator = $query->query_vars['operator']; } else { $operator = get_option( 'relevanssi_implicit_operator' ); } return $operator; } /** * Processes the negative and positive terms (ie. local AND and NOT operators). * * If negative terms are present, will remove them from the $terms array. If negative * or positive terms are present, will return the query restrictions MySQL for them. * * @param array $terms An array of search terms. * @param array $original_terms An array of unstemmed search terms. * @param string $query The search query as a string. * * @return array An array containing the updated terms and the query restrictions. */ function relevanssi_process_terms( $terms, $original_terms, $query ) { $negative_terms = relevanssi_recognize_negatives( $query ); $positive_terms = relevanssi_recognize_positives( $query ); if ( $negative_terms ) { $terms = array_diff( $terms, $negative_terms ); $original_terms = array_diff( $original_terms, $negative_terms ); } // Clean: escaped in the function. $query_restrictions = relevanssi_negatives_positives( $negative_terms, $positive_terms ); return array( 'terms' => $terms, 'original_terms' => $original_terms, 'query_restrictions' => $query_restrictions, ); } /** * Replaces the wildcards (?, *) with strings to let them pass intact. * * The wildcards are only allowed inside words, so they must have a word * character on both sides of them. * * @param string $str The query or content string to modify. * * @return string The parameter string modified. */ function relevanssi_wildcards_pre( $str ) { /** * If true, enables wildcard operators (*, ?). * * @param boolean If true, enable wildcard operator. Default false. */ if ( apply_filters( 'relevanssi_wildcard_search', false ) ) { $str = preg_replace( '/(\w)\?(\w)/', '\1SINGLEWILDCARDSYMBOL\2', $str ); $str = preg_replace( '/(\w)\*(\w)/', '\1MULTIWILDCARDSYMBOL\2', $str ); } return $str; } /** * Replaces the wildcard strings with wildcards (?, *). * * @param string $str The query or content string to modify. * * @return string The parameter string modified. */ function relevanssi_wildcards_post( $str ) { /** * Documented in /premium/search.php. */ if ( apply_filters( 'relevanssi_wildcard_search', false ) ) { $str = preg_replace( '/SINGLEWILDCARDSYMBOL/', '?', $str ); $str = preg_replace( '/MULTIWILDCARDSYMBOL/', '*', $str ); } return $str; } /** * Replaces the wildcards (?, *) with their MySQL equivalents (_, %). * * The ? is converted to _ (single character), while * is converted to % * (zero or more). Hooks to the relevanssi_term_where filter hook to only * apply this to the term WHERE condition part of the query. * * @see relevanssi_term_where * * @param string $query MySQL query to modify. * @param string $term The search term. * * @return string The modified MySQL query. */ function relevanssi_query_wildcards( $query, $term ) { /** * Documented in /premium/search.php. */ if ( apply_filters( 'relevanssi_wildcard_search', false ) ) { $query = str_replace( "= '$term'", "LIKE '$term'", $query ); $query = str_replace( array( '?', '*' ), array( '_', '%' ), $query ); } return $query; }