0

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 ?

lior r
  • 2,220
  • 7
  • 43
  • 80
  • why david king" - will return 2 should return 2 results?... – Abhijit Bashetti Mar 04 '21 at 12:37
  • 1
    Would `defType=edismax&q=david cohen&qf=first_name last_name&mm=100%` work? i.e. require all terms in the query to match in `first_name` or `last_name`. – MatsLindh Mar 04 '21 at 12:47
  • @MatsLindh: It doesn't work this is the query as you suggested right ? :{ "mm":"100%", "defType":"edismax", "q.alt":"david cohen", "qf":"first_name last_name", "stopwords":"true", "_":"1614858850788"}} – lior r Mar 04 '21 at 13:11
  • @Abhijit Bashetti: shold return object #2 – lior r Mar 04 '21 at 13:12
  • I didn't mention `q.alt` - just `q` (but that might not matter), but does it return anything? What is the type of the `first_name` and `last_name` fields? – MatsLindh Mar 04 '21 at 13:17
  • returns nothing both are "string" using q gives the same results – lior r Mar 04 '21 at 13:18

0 Answers0