trying to create custom where clause

I am trying to create a custom search form on a loop. I have the form submitting to the page and then am testing, before the loop of posts, if the form was submitted. If submitted, I am adding a posts_where filter to call a function that creates a custom where clause. Here is the code that executes before the loop:

if ($_POST["keywords"] or $_POST["ticker"]) {
add_filter( 'posts_where', 'keywordaction', 10, 2 );
$query = new WP_Query( array ( 'orderby' => 'created', 'order' => 'ASC', 'category_name' => 'Latest Research', '_keywords' => $_POST["keywords"]) );
} else {
$query = new WP_Query( array ( 'orderby' => 'created', 'order' => 'DESC', 'category_name' => 'Latest Research') );

Here is the filter code:

function keywordaction( $sql, &$wp_query ){
global $wpdb;

$keyword = get_query_var( '_keywords' );
$keyword = ( $keyword ) ? $keyword : $wp_query->get( '_keywords' );

if( $startswith ){
$sql .= $wpdb->prepare( " AND $wpdb->posts.post_title LIKE %s ", '%'.$keyword.'%' );

return $sql;

It is altering the results, but in the way I want. What am i doing wrong.