Hi Everyone…I was hoping to get some assistance wi...
# community-help
d
Hi Everyone…I was hoping to get some assistance with the following issue our team is encountering Our client has encountered at least one instance where adding a space within a word in a search query is creating incorrect/unexpected results. The goal is for the search to be intuitive enough that an incorrect space does not drastically alter the expected results. This search query is an example of an instance where a space is creating very unexpected results:
sweet & sour meatballs
vs.
sweet & sour meatb alls
These two queries return very different results – the second one doesn’t really return any results from the first one. Right now space is a token separator in the schema. We’ve tried using the
split_join_tokens
search parameter, but we cannot get Schema
Copy code
add_filter('typesense_schema', function ($collectionName) {
  return [
    'name' => $collectionName,
    'fields' => [
      [
        'name' => '.*',
        'type' => 'auto',
      ],
      [
        'name' => 'post_title',
        'type' => 'string',
        'sort' => true,
        'infix' => true,
      ],
      // ... other fields

      // sorting fields
      [
        'name' => 'post_type_weight',
        'type' => 'int32',
      ],
    ],
    'default_sorting_field' => 'post_type_weight',
    'token_separators' => [" ", "-", "_", ".", "'", "\""],
    'symbols_to_index' => ["&"],
  ];
});
Search params
Copy code
$search_params = [
      'q' => !empty($params['search']) ? $params['search'] : '*',
      'query_by' => 'post_title,primary_parent_category,post_excerpt,post_content_sanitized,search_meta,taxonomy_post_tag',
      'query_by_weights' => '127,68,1,1,1,1',
      'page' => $page,
      'per_page' => $per_page,
      'sort_by' => $sort_by,
      'filter_by' => $filter_by,
    ];
We’ve tried all sorts of combinations of these additional search parameters:
Copy code
'split_join_tokens' => 'always', // Treat space as typo
      'typo_tokens_threshold' => 3,
      'num_typos' => 4,
Any suggestions on how to handle this would be greatly appreciated!