To promote groups of results dynamically, see Smart Groups .
If typoTolerance is min or strict,
promoted results might not appear if they contain more typos than the top results.
For example, a book store wants to recommend a Harry Potter box set whenever the words “Harry Potter” form part of a search.
Rule
If the is Harry Potter,
promote the Harry Potter box set.
By default, you can pin up to 300 per rule.
With the API
To run the code examples on this page, install the latest API client .
C#
Dart
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var response = await client . SaveRuleAsync (
"INDEX_NAME" ,
"promote-harry-potter-box-set" ,
new Rule
{
ObjectID = "promote-harry-potter-box-set" ,
Conditions = new List < Condition >
{
new Condition { Pattern = "Harry Potter" , Anchoring = Enum . Parse < Anchoring >( "Contains" ) },
},
Consequence = new Consequence
{
Promote = new List < Promote >
{
new Promote ( new PromoteObjectID { ObjectID = "HP-12345" , Position = 0 }),
},
},
}
);
final response = await client. saveRule (
indexName : "INDEX_NAME" ,
objectID : "promote-harry-potter-box-set" ,
rule : Rule (
objectID : "promote-harry-potter-box-set" ,
conditions : [
Condition (
pattern : "Harry Potter" ,
anchoring : Anchoring . fromJson ( "contains" ),
),
],
consequence : Consequence (
promote : [
PromoteObjectID (
objectID : "HP-12345" ,
position : 0 ,
),
],
),
),
);
response , err := client . SaveRule ( client . NewApiSaveRuleRequest (
"INDEX_NAME" , "promote-harry-potter-box-set" ,
search . NewEmptyRule (). SetObjectID ( "promote-harry-potter-box-set" ). SetConditions (
[] search . Condition { * search . NewEmptyCondition (). SetPattern ( "Harry Potter" ). SetAnchoring ( search . Anchoring ( "contains" ))}). SetConsequence (
search . NewEmptyConsequence (). SetPromote (
[] search . Promote { * search . PromoteObjectIDAsPromote (
search . NewEmptyPromoteObjectID (). SetObjectID ( "HP-12345" ). SetPosition ( 0 ))}))))
if err != nil {
// handle the eventual error
panic ( err )
}
UpdatedAtResponse response = client . saveRule (
"INDEX_NAME" ,
"promote-harry-potter-box-set" ,
new Rule ()
. setObjectID ( "promote-harry-potter-box-set" )
. setConditions ( Arrays . asList ( new Condition (). setPattern ( "Harry Potter" ). setAnchoring ( Anchoring . CONTAINS )))
. setConsequence ( new Consequence (). setPromote ( Arrays . asList ( new PromoteObjectID (). setObjectID ( "HP-12345" ). setPosition ( 0 ))))
);
const response = await client . saveRule ({
indexName: 'indexName' ,
objectID: 'promote-harry-potter-box-set' ,
rule: {
objectID: 'promote-harry-potter-box-set' ,
conditions: [{ pattern: 'Harry Potter' , anchoring: 'contains' }],
consequence: { promote: [{ objectID: 'HP-12345' , position: 0 }] },
},
});
var response =
client. saveRule (
indexName = "INDEX_NAME" ,
object ID = "promote-harry-potter-box-set" ,
rule =
Rule (
object ID = "promote-harry-potter-box-set" ,
conditions =
listOf (
Condition (
pattern = "Harry Potter" ,
anchoring = Anchoring.entries. first { it. value == "contains" },
)
),
consequence =
Consequence (promote = listOf ( PromoteObjectID ( object ID = "HP-12345" , position = 0 ))),
),
)
$response = $client -> saveRule (
'INDEX_NAME' ,
'promote-harry-potter-box-set' ,
[ 'objectID' => 'promote-harry-potter-box-set' ,
'conditions' => [
[ 'pattern' => 'Harry Potter' ,
'anchoring' => 'contains' ,
],
],
'consequence' => [ 'promote' => [
[ 'objectID' => 'HP-12345' ,
'position' => 0 ,
],
],
],
],
);
response = client.save_rule(
index_name = "INDEX_NAME" ,
object_id = "promote-harry-potter-box-set" ,
rule = {
"objectID" : "promote-harry-potter-box-set" ,
"conditions" : [
{
"pattern" : "Harry Potter" ,
"anchoring" : "contains" ,
},
],
"consequence" : {
"promote" : [
{
"objectID" : "HP-12345" ,
"position" : 0 ,
},
],
},
},
)
response = client. save_rule (
"INDEX_NAME" ,
"promote-harry-potter-box-set" ,
Algolia :: Search :: Rule . new (
algolia_object_id: "promote-harry-potter-box-set" ,
conditions: [ Algolia :: Search :: Condition . new ( pattern: "Harry Potter" , anchoring: "contains" )],
consequence: Algolia :: Search :: Consequence . new (
promote: [ Algolia :: Search :: PromoteObjectID . new ( algolia_object_id: "HP-12345" , position: 0 )]
)
)
)
val response = Await .result(
client.saveRule(
indexName = "INDEX_NAME" ,
objectID = "promote-harry-potter-box-set" ,
rule = Rule (
objectID = "promote-harry-potter-box-set" ,
conditions = Some (
Seq (
Condition (
pattern = Some ( "Harry Potter" ),
anchoring = Some ( Anchoring .withName( "contains" ))
)
)
),
consequence = Consequence (
promote = Some (
Seq (
PromoteObjectID (
objectID = "HP-12345" ,
position = 0
)
)
)
)
)
),
Duration ( 100 , "sec" )
)
let response = try await client. saveRule (
indexName : "INDEX_NAME" ,
objectID : "promote-harry-potter-box-set" ,
rule : Rule (
objectID : "promote-harry-potter-box-set" ,
conditions : [ SearchCondition ( pattern : "Harry Potter" , anchoring : SearchAnchoring. contains )],
consequence : SearchConsequence ( promote : [SearchPromote. searchPromoteObjectID ( SearchPromoteObjectID (
objectID : "HP-12345" ,
position : 0
))])
)
)
With the Visual Editor
Go to the Algolia dashboard and select your Algolia .
On the left sidebar, select Search .
Select your Algolia .
Select Rules from the left sidebar.
Select Create your first Rule or New rule .
Click Visual Editor .
Under Conditions :
Click Set query condition(s) .
In Your search , type Harry Potter and click Apply .
Under Consequences :
Click Pin items .
In Pinned items , find and select the item you want to promote (for example, HP-12345) and click Apply .
Review and Publish your rule.
With the Manual Editor
Go to the Algolia dashboard and select your Algolia application.
On the left sidebar, select Search .
Select your Algolia index.
Select Rules from the left sidebar.
Select Create your first Rule or New rule .
Click Manual Editor .
In the Condition(s) section, enter Harry Potter in the Query field.
In the Consequence(s) section:
Click Add consequence and select Pin an item .
Find and select the item you want to promote. For example, HP-12345.
Save your rule.
For example, you’ve placed “best-selling items” at the top of your search results by using custom ranking .
But the newest release?
Set up a rule that promotes the newest iPhone for searches containing iPhone,
while keeping other phones sorted by most-sold.
Rule
If query is iphone,
promote the newest iPhone release.
With the API
C#
Dart
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var response = await client . SaveRuleAsync (
"INDEX_NAME" ,
"Promote-iPhone-X" ,
new Rule
{
ObjectID = "Promote-iPhone-X" ,
Conditions = new List < Condition >
{
new Condition { Pattern = "iPhone" , Anchoring = Enum . Parse < Anchoring >( "Contains" ) },
},
Consequence = new Consequence
{
Promote = new List < Promote >
{
new Promote ( new PromoteObjectID { ObjectID = "iPhone-12345" , Position = 0 }),
},
},
}
);
final response = await client. saveRule (
indexName : "INDEX_NAME" ,
objectID : "Promote-iPhone-X" ,
rule : Rule (
objectID : "Promote-iPhone-X" ,
conditions : [
Condition (
pattern : "iPhone" ,
anchoring : Anchoring . fromJson ( "contains" ),
),
],
consequence : Consequence (
promote : [
PromoteObjectID (
objectID : "iPhone-12345" ,
position : 0 ,
),
],
),
),
);
response , err := client . SaveRule ( client . NewApiSaveRuleRequest (
"INDEX_NAME" , "Promote-iPhone-X" ,
search . NewEmptyRule (). SetObjectID ( "Promote-iPhone-X" ). SetConditions (
[] search . Condition { * search . NewEmptyCondition (). SetPattern ( "iPhone" ). SetAnchoring ( search . Anchoring ( "contains" ))}). SetConsequence (
search . NewEmptyConsequence (). SetPromote (
[] search . Promote { * search . PromoteObjectIDAsPromote (
search . NewEmptyPromoteObjectID (). SetObjectID ( "iPhone-12345" ). SetPosition ( 0 ))}))))
if err != nil {
// handle the eventual error
panic ( err )
}
UpdatedAtResponse response = client . saveRule (
"INDEX_NAME" ,
"Promote-iPhone-X" ,
new Rule ()
. setObjectID ( "Promote-iPhone-X" )
. setConditions ( Arrays . asList ( new Condition (). setPattern ( "iPhone" ). setAnchoring ( Anchoring . CONTAINS )))
. setConsequence ( new Consequence (). setPromote ( Arrays . asList ( new PromoteObjectID (). setObjectID ( "iPhone-12345" ). setPosition ( 0 ))))
);
const response = await client . saveRule ({
indexName: 'indexName' ,
objectID: 'Promote-iPhone-X' ,
rule: {
objectID: 'Promote-iPhone-X' ,
conditions: [{ pattern: 'iPhone' , anchoring: 'contains' }],
consequence: { promote: [{ objectID: 'iPhone-12345' , position: 0 }] },
},
});
var response =
client. saveRule (
indexName = "INDEX_NAME" ,
object ID = "Promote-iPhone-X" ,
rule =
Rule (
object ID = "Promote-iPhone-X" ,
conditions =
listOf (
Condition (
pattern = "iPhone" ,
anchoring = Anchoring.entries. first { it. value == "contains" },
)
),
consequence =
Consequence (
promote = listOf ( PromoteObjectID ( object ID = "iPhone-12345" , position = 0 ))
),
),
)
$response = $client -> saveRule (
'INDEX_NAME' ,
'Promote-iPhone-X' ,
[ 'objectID' => 'Promote-iPhone-X' ,
'conditions' => [
[ 'pattern' => 'iPhone' ,
'anchoring' => 'contains' ,
],
],
'consequence' => [ 'promote' => [
[ 'objectID' => 'iPhone-12345' ,
'position' => 0 ,
],
],
],
],
);
response = client.save_rule(
index_name = "INDEX_NAME" ,
object_id = "Promote-iPhone-X" ,
rule = {
"objectID" : "Promote-iPhone-X" ,
"conditions" : [
{
"pattern" : "iPhone" ,
"anchoring" : "contains" ,
},
],
"consequence" : {
"promote" : [
{
"objectID" : "iPhone-12345" ,
"position" : 0 ,
},
],
},
},
)
response = client. save_rule (
"INDEX_NAME" ,
"Promote-iPhone-X" ,
Algolia :: Search :: Rule . new (
algolia_object_id: "Promote-iPhone-X" ,
conditions: [ Algolia :: Search :: Condition . new ( pattern: "iPhone" , anchoring: "contains" )],
consequence: Algolia :: Search :: Consequence . new (
promote: [ Algolia :: Search :: PromoteObjectID . new ( algolia_object_id: "iPhone-12345" , position: 0 )]
)
)
)
val response = Await .result(
client.saveRule(
indexName = "INDEX_NAME" ,
objectID = "Promote-iPhone-X" ,
rule = Rule (
objectID = "Promote-iPhone-X" ,
conditions = Some (
Seq (
Condition (
pattern = Some ( "iPhone" ),
anchoring = Some ( Anchoring .withName( "contains" ))
)
)
),
consequence = Consequence (
promote = Some (
Seq (
PromoteObjectID (
objectID = "iPhone-12345" ,
position = 0
)
)
)
)
)
),
Duration ( 100 , "sec" )
)
let response = try await client. saveRule (
indexName : "INDEX_NAME" ,
objectID : "Promote-iPhone-X" ,
rule : Rule (
objectID : "Promote-iPhone-X" ,
conditions : [ SearchCondition ( pattern : "iPhone" , anchoring : SearchAnchoring. contains )],
consequence : SearchConsequence ( promote : [SearchPromote. searchPromoteObjectID ( SearchPromoteObjectID (
objectID : "iPhone-12345" ,
position : 0
))])
)
)
With the Visual Editor
Go to the Algolia dashboard and select your Algolia application.
On the left sidebar, select Search .
Select your Algolia index.
Select Rules from the left sidebar.
Select Create your first Rule or New rule .
Click Visual Editor .
Under Conditions :
Click Set query condition(s) .
In Your search , type iPhone and click Apply .
Under Consequences :
Click Pin item .
In Pinned items , find and select the item you want to promote (for example, iPhone-12345) and then click Apply .
Review and Publish your rule.
With the Manual Editor
Go to the Algolia dashboard and select your Algolia application.
On the left sidebar, select Search .
Select your Algolia index.
Select Rules from the left sidebar.
Select Create your first Rule or New rule .
Click Manual Editor .
In the Condition(s) section, enter iPhone in the Query field and change the drop-down from Is to Contains .
In the Consequence(s) section:
Click Add consequence and select Pin an item .
Find and select the item you want to promote (for example, iPhone-12345).
Save your rule.
For example, you’re running a promotion on the newest Apple products.
Set up a rule that promotes the newest Apple releases at the top of results for searches containing apple.
Rule
If query is apple,
promote the newest Apple releases.
With the API
C#
Dart
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
var response = await client . SaveRuleAsync (
"INDEX_NAME" ,
"Promote-Apple-Newest" ,
new Rule
{
ObjectID = "Promote-Apple-Newest" ,
Conditions = new List < Condition >
{
new Condition { Pattern = "apple" , Anchoring = Enum . Parse < Anchoring >( "Is" ) },
},
Consequence = new Consequence
{
Promote = new List < Promote >
{
new Promote (
new PromoteObjectIDs
{
ObjectIDs = new List < string > { "iPhone-12345" , "watch-123" },
Position = 0 ,
}
),
},
},
}
);
final response = await client. saveRule (
indexName : "INDEX_NAME" ,
objectID : "Promote-Apple-Newest" ,
rule : Rule (
objectID : "Promote-Apple-Newest" ,
conditions : [
Condition (
pattern : "apple" ,
anchoring : Anchoring . fromJson ( "is" ),
),
],
consequence : Consequence (
promote : [
PromoteObjectIDs (
objectIDs : [
"iPhone-12345" ,
"watch-123" ,
],
position : 0 ,
),
],
),
),
);
response , err := client . SaveRule ( client . NewApiSaveRuleRequest (
"INDEX_NAME" , "Promote-Apple-Newest" ,
search . NewEmptyRule (). SetObjectID ( "Promote-Apple-Newest" ). SetConditions (
[] search . Condition { * search . NewEmptyCondition (). SetPattern ( "apple" ). SetAnchoring ( search . Anchoring ( "is" ))}). SetConsequence (
search . NewEmptyConsequence (). SetPromote (
[] search . Promote { * search . PromoteObjectIDsAsPromote (
search . NewEmptyPromoteObjectIDs (). SetObjectIDs (
[] string { "iPhone-12345" , "watch-123" }). SetPosition ( 0 ))}))))
if err != nil {
// handle the eventual error
panic ( err )
}
UpdatedAtResponse response = client . saveRule (
"INDEX_NAME" ,
"Promote-Apple-Newest" ,
new Rule ()
. setObjectID ( "Promote-Apple-Newest" )
. setConditions ( Arrays . asList ( new Condition (). setPattern ( "apple" ). setAnchoring ( Anchoring . IS )))
. setConsequence (
new Consequence (). setPromote (
Arrays . asList ( new PromoteObjectIDs (). setObjectIDs ( Arrays . asList ( "iPhone-12345" , "watch-123" )). setPosition ( 0 ))
)
)
);
const response = await client . saveRule ({
indexName: 'indexName' ,
objectID: 'Promote-Apple-Newest' ,
rule: {
objectID: 'Promote-Apple-Newest' ,
conditions: [{ pattern: 'apple' , anchoring: 'is' }],
consequence: { promote: [{ objectIDs: [ 'iPhone-12345' , 'watch-123' ], position: 0 }] },
},
});
var response =
client. saveRule (
indexName = "INDEX_NAME" ,
object ID = "Promote-Apple-Newest" ,
rule =
Rule (
object ID = "Promote-Apple-Newest" ,
conditions =
listOf (
Condition (
pattern = "apple" ,
anchoring = Anchoring.entries. first { it. value == "is" },
)
),
consequence =
Consequence (
promote =
listOf (
PromoteObjectIDs ( object IDs = listOf ( "iPhone-12345" , "watch-123" ), position = 0 )
)
),
),
)
$response = $client -> saveRule (
'INDEX_NAME' ,
'Promote-Apple-Newest' ,
[ 'objectID' => 'Promote-Apple-Newest' ,
'conditions' => [
[ 'pattern' => 'apple' ,
'anchoring' => 'is' ,
],
],
'consequence' => [ 'promote' => [
[ 'objectIDs' => [
'iPhone-12345' ,
'watch-123' ,
],
'position' => 0 ,
],
],
],
],
);
response = client.save_rule(
index_name = "INDEX_NAME" ,
object_id = "Promote-Apple-Newest" ,
rule = {
"objectID" : "Promote-Apple-Newest" ,
"conditions" : [
{
"pattern" : "apple" ,
"anchoring" : "is" ,
},
],
"consequence" : {
"promote" : [
{
"objectIDs" : [
"iPhone-12345" ,
"watch-123" ,
],
"position" : 0 ,
},
],
},
},
)
response = client. save_rule (
"INDEX_NAME" ,
"Promote-Apple-Newest" ,
Algolia :: Search :: Rule . new (
algolia_object_id: "Promote-Apple-Newest" ,
conditions: [ Algolia :: Search :: Condition . new ( pattern: "apple" , anchoring: "is" )],
consequence: Algolia :: Search :: Consequence . new (
promote: [ Algolia :: Search :: PromoteObjectIDs . new ( object_ids: [ "iPhone-12345" , "watch-123" ], position: 0 )]
)
)
)
val response = Await .result(
client.saveRule(
indexName = "INDEX_NAME" ,
objectID = "Promote-Apple-Newest" ,
rule = Rule (
objectID = "Promote-Apple-Newest" ,
conditions = Some (
Seq (
Condition (
pattern = Some ( "apple" ),
anchoring = Some ( Anchoring .withName( "is" ))
)
)
),
consequence = Consequence (
promote = Some (
Seq (
PromoteObjectIDs (
objectIDs = Seq ( "iPhone-12345" , "watch-123" ),
position = 0
)
)
)
)
)
),
Duration ( 100 , "sec" )
)
let response = try await client. saveRule (
indexName : "INDEX_NAME" ,
objectID : "Promote-Apple-Newest" ,
rule : Rule (
objectID : "Promote-Apple-Newest" ,
conditions : [ SearchCondition ( pattern : "apple" , anchoring : SearchAnchoring. `is` )],
consequence : SearchConsequence ( promote : [SearchPromote. searchPromoteObjectIDs ( SearchPromoteObjectIDs (
objectIDs : [ "iPhone-12345" , "watch-123" ],
position : 0
))])
)
)
With the Visual Editor
Go to the Algolia dashboard and select your Algolia application.
On the left sidebar, select Search .
Select your Algolia index.
Select Rules from the left sidebar.
Select Create your first Rule or New rule .
Click Visual Editor .
Under Conditions :
Click Set query condition(s) .
In Your search , type apple and click Apply .
Under Consequences :
Click Pin items .
Click Pin multiple items .
One per line, enter the object IDs of the items you want to pin, for example, iPhone-12345 and watch-123, in the input field and then click Pin items .
Click Apply .
Review and Publish your rule.
You can’t promote more than one item with the Manual Editor.
For example, you only want to promote items if they match a user’s active ,
such as stock availability, color, or category.
This prevents irrelevant items such as out-of-stock products from appearing.
Rule
Create a rule with a consequence that pins the item only if it matches active filters.
With the API
To pin an item only if it matches active filters,
set filterPromotes to true in the rule’s consequence.
C#
Dart
Go
Java
JavaScript
Kotlin
PHP
Python
Ruby
Scala
Swift
namespace Algolia ;
using System ;
using System . Collections . Generic ;
using System . Net . Http ;
using System . Text . Json ;
using Algolia . Search . Clients ;
using Algolia . Search . Http ;
using Algolia . Search . Models . Search ;
class EnableFilterPromote
{
async Task Main ( string [] args )
{
var condition = new Condition { Anchoring = Anchoring . Is , Pattern = "{facet:brand}" };
var consequence = new Consequence { FilterPromotes = true };
var rule = new Rule
{
ObjectID = "rule_with_filterPromotes" ,
Conditions = [ condition ],
Consequence = consequence ,
};
}
}
import 'package:algolia_client_search/algolia_client_search.dart' ;
void enableFilterPromote () async {
final condition = Condition (
pattern : "{facet:brand}" ,
anchoring : Anchoring .is_,
);
final consequence = Consequence (filterPromotes : true );
// ignore: unused_local_variable
final rule = Rule (
objectID : "rule_with_filterPromotes" ,
conditions : [condition],
consequence : consequence);
}
package main
import (
" fmt "
" github.com/algolia/algoliasearch-client-go/v4/algolia/search "
)
func enableFilterPromote () {
condition := search . NewCondition ().
SetPattern ( "{facet:brand}" ).
SetAnchoring ( search . ANCHORING_IS )
rule := search . NewRule (
"rule_with_filterPromotes" ,
* search . NewConsequence (). SetFilterPromotes ( true ),
). SetEnabled ( true ). SetConditions ([] search . Condition { * condition })
fmt . Printf ( "Rule: %#v \n " , rule )
}
package com.algolia;
import com.algolia.config. * ;
import com.algolia.model.search. * ;
import java.util.List;
public class enableFilterPromote {
public static void main ( String [] args ) throws Exception {
Condition condition = new Condition (). setAnchoring ( Anchoring . IS ). setPattern ( "{facet:brand}" );
Consequence consequence = new Consequence (). setFilterPromotes ( true );
Rule rule = new Rule (). setObjectID ( "rule_with_filterPromotes" ). setConditions ( List . of (condition)). setConsequence (consequence);
}
}
import type { Condition , Consequence } from 'algoliasearch' ;
const condition : Condition = {
anchoring: 'is' ,
pattern: '{facet:brand}' ,
};
const consequence : Consequence = {
filterPromotes: true ,
};
import com.algolia.client.configuration. *
import com.algolia.client.extensions. *
import com.algolia.client.model.search. *
import com.algolia.client.transport. *
suspend fun enableFilterPromote () {
val condition = Condition (pattern = "{facet:brand}" , anchoring = Anchoring.Is)
val consequence = Consequence (filterPromotes = true )
val rule =
Rule (
object ID = "rule_with_filterPromotes" ,
conditions = listOf (condition),
consequence = consequence,
)
}
<? php
require __DIR__ . '/../vendor/autoload.php' ;
use Algolia\AlgoliaSearch\Model\Search\ Anchoring ;
use Algolia\AlgoliaSearch\Model\Search\ Condition ;
use Algolia\AlgoliaSearch\Model\Search\ Consequence ;
use Algolia\AlgoliaSearch\Model\Search\ Rule ;
$condition = ( new Condition ())
-> setAnchoring (( new Anchoring ()) :: IS )
-> setPattern ( '{facet:brand}' )
;
$consequence = ( new Consequence ())
-> setFilterPromotes ( true )
;
$rule = ( new Rule ())
-> setObjectID ( 'rule_with_filterPromotes' )
-> setConditions ([ $condition ])
-> setConsequence ( $consequence );
from algoliasearch.search.models.anchoring import Anchoring
from algoliasearch.search.models.condition import Condition
from algoliasearch.search.models.consequence import Consequence
from algoliasearch.search.models.rule import Rule
condition = Condition(
anchoring = Anchoring. IS ,
pattern = " {facet:brand} " ,
)
consequence = Consequence(
filter_promotes = True ,
)
rule = Rule(
enabled = True ,
object_id = "rule_with_filterPromotes" ,
conditions = [condition],
consequence = consequence,
)
condition = Algolia :: Search :: Condition . new (
anchoring: Algolia :: Search :: Anchoring :: IS ,
pattern: "{facet:brand}"
)
consequence = Algolia :: Search :: Consequence . new (
filter_promotes: true
)
rule = Algolia :: Search :: Rule . new (
enabled: true ,
object_id: "rule_with_filterPromotes" ,
conditions: [condition],
consequence: consequence
)
import scala . concurrent . ExecutionContext . Implicits . global
import algoliasearch . api . SearchClient
import algoliasearch . config . *
import algoliasearch . extension . SearchClientExtensions
import algoliasearch . search .{ Anchoring , Condition , Consequence , Rule }
def enableFilterPromote () : Unit = {
val condition = Condition (
pattern = Some ( "{facet:brand}" ),
anchoring = Some ( Anchoring . Is )
)
val consequence = Consequence (
filterPromotes = Some ( true )
)
val rule = Rule (
objectID = "rule_with_filterPromotes" ,
conditions = Some ( Seq (condition)),
consequence = consequence
)
}
import Foundation
# if os ( Linux ) // For linux interop
import FoundationNetworking
# endif
import AlgoliaCore
import AlgoliaSearch
func enableFilterPromote () async throws {
let condition = SearchCondition (
pattern : "{facet:brand}" ,
anchoring : . is
)
let consequence = SearchConsequence (
filterPromotes : true
)
let rule = Rule ( objectID : "rule_with_filterPromotes" , conditions : [condition], consequence : consequence)
print (rule)
}
With the Visual Editor
Go to the Algolia dashboard and select your Algolia application.
On the left sidebar, select Search .
Select your Algolia index.
Select Rules from the left sidebar.
Select Create your first Rule or New rule .
Click Visual Editor .
Under Conditions :
Click Set query condition(s) .
In Your search , enter the item you want to promote (for example, shoes) and click Apply .
Under Consequences :
Click Pin items .
In Pinned items , find and select the item you want to promote.
Keep the checkbox Pinned items must match active filters to be displayed selected and click Apply .
Review and Publish your rule.
With the Manual Editor
Go to the Algolia dashboard and select your Algolia application.
On the left sidebar, select Search .
Select your Algolia index.
Select Rules from the left sidebar.
Select Create your first Rule or New rule .
Click Manual Editor .
In the Condition(s) section, enter the query (for example, shoes) in the Query field.
In the Consequence(s) section:
Click Add consequence and select Pin an item .
Find and select the item you want to promote (for example, brogue-12345).
In the Additional settings section, keep the checkbox Pinned items must match active filters to be displayed selected.
Save your rule.