lior r
lior r

Reputation: 2290

Solr full-text search

I have these entries in the DB:

1:{
  first_name:"david",
  last_name:"cohen"
}

2:{
  first_name:"david king",
  last_name:"cohen"
}

The search logic that is required is a complete-word match:

searching for "david ki" - will return null

searching for "david king" - will return 2

searching for "david cohen" - will return both 1 + 2

In MySQL my query looks like that:

WHERE first_name REGEXP '[[:<:]]{$first_name}[[:>:]]' AND last_name REGEXP '[[:<:]]{$last_name}[[:>:]]'

I have tried building the query like this:

if ( $search_params ) {
    foreach ( $search_params as $search_param_key => $search_params_value ) {
        if ( $search_params_value ) {
            $search_query_fields[] = "{$search_param_key}:\"{$search_params_value}\"";
        }
    }

    $query_string = implode( ' AND ', $search_query_fields );

    $query->setQuery( $query_string );
}

How can I imitate the same MySQL query on SOLR ?

Upvotes: 0

Views: 110

Answers (0)

Related Questions