Score:0

Can't find "starts with" for Filter criteria In Views (indexed field for taxonomy)

ve flag

I created a view using indexed fields (search api) to list a taxonomy. I used the rest export checkbox so I have an api endpoint for my view. I am not able to find a filter criteria "starts with" for a field (indexed) that is a string. I don't understand why, the field is behaving like an integer and showing greater than, less than etc..

I am trying to use the hook_views_query_alter but I am getting an error from the line $query->where :

Error: Cannot access protected property Drupal\search_api\Plugin\views\query\SearchApiQuery::$where

In my view , I can see in the "Preview" section the query :

Index: books
Keys: NULL
Options: array (
    'search_api_view' => 'object (Drupal\\views\\ViewExecutable)',
    'search_api_base_path' => 'api/books',
  )

How do I add a filter criteria "starts with" for an indexed field which is a string? Thanks for your help

misterdidi avatar
de flag
Apparently, this is a known and old issue since there was a Drupal 7 module specifically for that need. I had an index where I had to filter on author names and I did use the trick mentioned here: https://www.drupal.org/project/search_api/issues/3114833#comment-13528391. Perhaps it may help you as well.
jacksparrow avatar
ve flag
@misterdidi thanks for your help! I will try that
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.