You can use Rules to detect a specific word and modify a query setting because of this word.
Limiting the search to only a subset of attributes
Use Case - Title or ID (SKU) searches
A good example of altering a query is with an online document library that allows keyword searches inside documents. If a user types in the word “article ref21”, they are probably signalling to the system that they are looking for an article whose title or ID contains “ref21”.
Rule
If query = “article ref21” then remove article and search for an article whose title or ID contains ‘ref21’
// Turn JSON into an array$rule=array('objectID'=>'article-rule','conditions'=>array(array('pattern'=>'article','anchoring'=>'startsWith')),'consequence'=>array('params'=>array('query'=>array('remove'=>'article'),'restrictSearchableAttributes'=>array('title','book_id'))));// Push Rule to index$index->saveRule($rule);
// Create the ruleconstrule={objectID:'article-rule',conditions:[{pattern:'article',anchoring:'startsWith'}],consequence:{params:{query:{type:'remove',delete:'article'},restrictSearchableAttributes:['title','book_id']}}};// Save the Ruleindex.saveRule(rule);
# Create the Rule
rule={'objectID':'article-rule','conditions':[{'pattern':'article','anchoring':'startsWith'}],'consequence':{'params':{'query':{'type':'remove','delete':'article'},'restrictSearchableAttributes':['title','book_id']}}}# Save the Rule
response=index.save_rule(rule)
// Create the ruleletrule=Rule(objectID:"article-id").set(\.conditions,to:[Rule.Condition().set(\.anchoring,to:.startsWith).set(\.pattern,to:.literal("article"))]).set(\.consequence,to:Rule.Consequence().set(\.query,to:Query().set(\.restrictSearchableAttributes,to:["title","book_id"])))// Save the Ruleindex.saveRule(rule,forwardToReplicas:true){resultinifcase.success(letresponse)=result{print("Response: \(response)")}}