You can use Rules to raise some results over others, or put one result or banner at the top of the results.
Use case
A book store wants to recommend a Harry Potter Box Set whenever the words Harry Potter form part of a search.
Rule
If query=Harry Potter then promote Harry Potter Box Set
By default, you can pin up to 300 items per rule.
Using the API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var response = await client . SaveRuleAsync (
"ALGOLIA_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 }),
},
},
}
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
final response = await client . saveRule (
indexName: "ALGOLIA_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 ,
),
],
),
),
);
1
2
3
4
5
6
7
8
9
10
11
response , err := client . SaveRule ( client . NewApiSaveRuleRequest (
"ALGOLIA_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 )
}
1
2
3
4
5
6
7
8
client . saveRule (
"ALGOLIA_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 ))))
);
1
2
3
4
5
6
7
8
9
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 }] },
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var response = client . saveRule (
indexName = "ALGOLIA_INDEX_NAME" ,
objectID = "promote-harry-potter-box-set" ,
rule = Rule (
objectID = "promote-harry-potter-box-set" ,
conditions = listOf (
Condition (
pattern = "Harry Potter" ,
anchoring = Anchoring . entries . first { it . value == "contains" },
),
),
consequence = Consequence (
promote = listOf (
PromoteObjectID (
objectID = "HP-12345" ,
position = 0 ,
),
),
),
),
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$response = $client -> saveRule (
'ALGOLIA_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 ,
],
],
],
],
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
response = client . save_rule (
index_name = "ALGOLIA_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 ,
},
],
},
},
)
1
2
3
4
5
6
7
8
9
10
11
response = client . save_rule (
"ALGOLIA_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 )]
)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
val response = client . saveRule (
indexName = "ALGOLIA_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
)
)
)
)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
let response = try await client . saveRule (
indexName : "ALGOLIA_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
))])
)
)
Using the dashboard
Visual Editor
Select the Search product icon on your dashboard and then select your index.
Select the Rules section from the left sidebar menu in the Algolia dashboard .
Under the heading Rules , select the index you are adding a Rule to.
Select Create your first rule or New rule . In the drop-down menu, click the Visual Editor option.
In the It all starts here section:
Click Set search query button.
In the side panel, type “Harry Potter” in the input field and click Save
.
In the What do you want to do? section:
Click the Pin item button.
In the side panel, find the product ‘HP-12345’ you want to pin in the input field and press Save
.
Review and publish your changes.
Manual Editor
Select the Rules section from the left sidebar menu in the Algolia dashboard .
Under the heading Rules , select the index you are adding a Rule to.
Select Create your first rule or New rule . In the drop-down menu, click the Manual Editor option.
In the Condition(s) section, keep Query contains and enter “Harry Potter” in the input field.
In the Consequence(s) section:
Click the Add consequence button and select Pin an item .
Find the product ‘HP-12345’ you want to pin the input field and press Enter
.
Save your changes.
Use case
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 telling the engine that whenever iPhone is searched for, place the newest version at the top, but for the rest of the same brand phones, continue sorting by most-sold.
Rule
If query = iphone then promote newest iPhone release
Using the API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var response = await client . SaveRuleAsync (
"ALGOLIA_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 }),
},
},
}
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
final response = await client . saveRule (
indexName: "ALGOLIA_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 ,
),
],
),
),
);
1
2
3
4
5
6
7
8
9
10
11
response , err := client . SaveRule ( client . NewApiSaveRuleRequest (
"ALGOLIA_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 )
}
1
2
3
4
5
6
7
8
client . saveRule (
"ALGOLIA_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 ))))
);
1
2
3
4
5
6
7
8
9
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 }] },
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var response = client . saveRule (
indexName = "ALGOLIA_INDEX_NAME" ,
objectID = "Promote-iPhone-X" ,
rule = Rule (
objectID = "Promote-iPhone-X" ,
conditions = listOf (
Condition (
pattern = "iPhone" ,
anchoring = Anchoring . entries . first { it . value == "contains" },
),
),
consequence = Consequence (
promote = listOf (
PromoteObjectID (
objectID = "iPhone-12345" ,
position = 0 ,
),
),
),
),
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$response = $client -> saveRule (
'ALGOLIA_INDEX_NAME' ,
'Promote-iPhone-X' ,
[ 'objectID' => 'Promote-iPhone-X' ,
'conditions' => [
[ 'pattern' => 'iPhone' ,
'anchoring' => 'contains' ,
],
],
'consequence' => [ 'promote' => [
[ 'objectID' => 'iPhone-12345' ,
'position' => 0 ,
],
],
],
],
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
response = client . save_rule (
index_name = "ALGOLIA_INDEX_NAME" ,
object_id = "Promote-iPhone-X" ,
rule = {
"objectID" : "Promote-iPhone-X" ,
"conditions" : [
{
"pattern" : "iPhone" ,
"anchoring" : "contains" ,
},
],
"consequence" : {
"promote" : [
{
"objectID" : "iPhone-12345" ,
"position" : 0 ,
},
],
},
},
)
1
2
3
4
5
6
7
8
9
10
11
response = client . save_rule (
"ALGOLIA_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 )]
)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
val response = client . saveRule (
indexName = "ALGOLIA_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
)
)
)
)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
let response = try await client . saveRule (
indexName : "ALGOLIA_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
))])
)
)
Using the dashboard
Visual Editor
Select the Search product icon on your dashboard and then select your index.
Select the Rules section from the left sidebar menu in the Algolia dashboard .
Under the heading Rules , select the index you are adding a Rule to.
Select Create your first rule or New rule . In the drop-down menu, click the Visual Editor option.
In the It all starts here section:
Click Set search query button.
In the side panel, type “iPhone” in the input field and click Save
.
In the What do you want to do? section:
Click the Pin item button.
In the side panel, find the product “iPhone-12345” you want to pin in the input field and press Save
.
Review and publish your changes.
Manual Editor
Select the Rules section from the left sidebar menu in the Algolia dashboard .
Under the heading Rules , select the index you are adding a Rule to.
Select Create your first rule or New rule . In the drop-down menu, click the Manual Editor option.
In the Condition(s) section, keep Query toggled on, select Contains in the drop-down menu, and enter “iPhone” in the input field.
In the Consequence(s) section:
Click the Add consequence button and select Pin an item .
Find the product “iPhone-12345” you want to pin the input field and press Enter
.
Save your changes.
Use case
You’re running a promotion on the newest Apple products. Set up a Rule telling the engine that whenever apple is searched for, place the newest releases at the top.
Rule
If query = apple then promote newest Apple releases
Using the API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
var response = await client . SaveRuleAsync (
"ALGOLIA_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 ,
}
),
},
},
}
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
final response = await client . saveRule (
indexName: "ALGOLIA_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 ,
),
],
),
),
);
1
2
3
4
5
6
7
8
9
10
11
12
response , err := client . SaveRule ( client . NewApiSaveRuleRequest (
"ALGOLIA_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 )
}
1
2
3
4
5
6
7
8
9
10
11
client . saveRule (
"ALGOLIA_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 )))
)
);
1
2
3
4
5
6
7
8
9
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 }] },
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
var response = client . saveRule (
indexName = "ALGOLIA_INDEX_NAME" ,
objectID = "Promote-Apple-Newest" ,
rule = Rule (
objectID = "Promote-Apple-Newest" ,
conditions = listOf (
Condition (
pattern = "apple" ,
anchoring = Anchoring . entries . first { it . value == "is" },
),
),
consequence = Consequence (
promote = listOf (
PromoteObjectIDs (
objectIDs = listOf ( "iPhone-12345" , "watch-123" ),
position = 0 ,
),
),
),
),
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$response = $client -> saveRule (
'ALGOLIA_INDEX_NAME' ,
'Promote-Apple-Newest' ,
[ 'objectID' => 'Promote-Apple-Newest' ,
'conditions' => [
[ 'pattern' => 'apple' ,
'anchoring' => 'is' ,
],
],
'consequence' => [ 'promote' => [
[ 'objectIDs' => [
'iPhone-12345' ,
'watch-123' ,
],
'position' => 0 ,
],
],
],
],
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
response = client . save_rule (
index_name = "ALGOLIA_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 ,
},
],
},
},
)
1
2
3
4
5
6
7
8
9
10
11
response = client . save_rule (
"ALGOLIA_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 )]
)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
val response = client . saveRule (
indexName = "ALGOLIA_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
)
)
)
)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
let response = try await client . saveRule (
indexName : "ALGOLIA_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
))])
)
)
Using the dashboard
Visual Editor
Select the Search product icon on your dashboard and then select your index.
Select the Rules section from the left sidebar menu in the Algolia dashboard .
Under the heading Rules , select the index you are adding a Rule to.
Select Create your first rule or New rule . In the drop-down menu, click the Visual Editor option.
In the It all starts here section:
Click Set search query button.
In the side panel, type “apple” in the input field and click Save
.
In the What do you want to do? section:
Click the Pin item button.
In the side panel, click the Pin multiple items button.
One per line, enter the object IDs you want to pin, “iPhone-12345” and “watch-123”, in the input field and press Pin items
.
Click Apply
.
Review and publish your changes.
Manual Editor
The Manual Editor only allows for pinning a single item at a time.
Use case
Tomato: A simple search, but one that may never return the fruit (or vegetable) because too many Tomato Soup brands are selling better than cherry tomatoes.
Rule
If query=tomato then put fruits higher than the rest
Using the API
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
var response = await client . SaveRuleAsync (
"ALGOLIA_INDEX_NAME" ,
"tomato-fruit" ,
new Rule
{
ObjectID = "tomato-fruit" ,
Conditions = new List < Condition >
{
new Condition { Pattern = "tomato" , Anchoring = Enum . Parse < Anchoring >( "Contains" ) },
},
Consequence = new Consequence
{
Params = new ConsequenceParams
{
OptionalFilters = new OptionalFilters ( "food_group:fruit" ),
},
},
}
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
final response = await client . saveRule (
indexName: "ALGOLIA_INDEX_NAME" ,
objectID: "tomato-fruit" ,
rule: Rule (
objectID: "tomato-fruit" ,
conditions: [
Condition (
pattern: "tomato" ,
anchoring: Anchoring . fromJson ( "contains" ),
),
],
consequence: Consequence (
params: ConsequenceParams (
optionalFilters: "food_group:fruit" ,
),
),
),
);
1
2
3
4
5
6
7
8
9
10
response , err := client . SaveRule ( client . NewApiSaveRuleRequest (
"ALGOLIA_INDEX_NAME" , "tomato-fruit" ,
search . NewEmptyRule () . SetObjectID ( "tomato-fruit" ) . SetConditions (
[] search . Condition { * search . NewEmptyCondition () . SetPattern ( "tomato" ) . SetAnchoring ( search . Anchoring ( "contains" ))}) . SetConsequence (
search . NewEmptyConsequence () . SetParams (
search . NewEmptyConsequenceParams () . SetOptionalFilters ( search . StringAsOptionalFilters ( "food_group:fruit" ))))))
if err != nil {
// handle the eventual error
panic ( err )
}
1
2
3
4
5
6
7
8
client . saveRule (
"ALGOLIA_INDEX_NAME" ,
"tomato-fruit" ,
new Rule ()
. setObjectID ( "tomato-fruit" )
. setConditions ( Arrays . asList ( new Condition (). setPattern ( "tomato" ). setAnchoring ( Anchoring . CONTAINS )))
. setConsequence ( new Consequence (). setParams ( new ConsequenceParams (). setOptionalFilters ( OptionalFilters . of ( "food_group:fruit" ))))
);
1
2
3
4
5
6
7
8
9
const response = await client . saveRule ({
indexName : ' indexName ' ,
objectID : ' tomato-fruit ' ,
rule : {
objectID : ' tomato-fruit ' ,
conditions : [{ pattern : ' tomato ' , anchoring : ' contains ' }],
consequence : { params : { optionalFilters : ' food_group:fruit ' } },
},
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
var response = client . saveRule (
indexName = "ALGOLIA_INDEX_NAME" ,
objectID = "tomato-fruit" ,
rule = Rule (
objectID = "tomato-fruit" ,
conditions = listOf (
Condition (
pattern = "tomato" ,
anchoring = Anchoring . entries . first { it . value == "contains" },
),
),
consequence = Consequence (
params = ConsequenceParams (
optionalFilters = OptionalFilters . of ( "food_group:fruit" ),
),
),
),
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
$response = $client -> saveRule (
'ALGOLIA_INDEX_NAME' ,
'tomato-fruit' ,
[ 'objectID' => 'tomato-fruit' ,
'conditions' => [
[ 'pattern' => 'tomato' ,
'anchoring' => 'contains' ,
],
],
'consequence' => [ 'params' => [ 'optionalFilters' => 'food_group:fruit' ,
],
],
],
);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
response = client . save_rule (
index_name = "ALGOLIA_INDEX_NAME" ,
object_id = "tomato-fruit" ,
rule = {
"objectID" : "tomato-fruit" ,
"conditions" : [
{
"pattern" : "tomato" ,
"anchoring" : "contains" ,
},
],
"consequence" : {
"params" : {
"optionalFilters" : "food_group:fruit" ,
},
},
},
)
1
2
3
4
5
6
7
8
9
10
11
response = client . save_rule (
"ALGOLIA_INDEX_NAME" ,
"tomato-fruit" ,
Algolia :: Search :: Rule . new (
algolia_object_id: "tomato-fruit" ,
conditions: [ Algolia :: Search :: Condition . new ( pattern: "tomato" , anchoring: "contains" )],
consequence: Algolia :: Search :: Consequence . new (
params: Algolia :: Search :: ConsequenceParams . new ( optional_filters: "food_group:fruit" )
)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
val response = client . saveRule (
indexName = "ALGOLIA_INDEX_NAME" ,
objectID = "tomato-fruit" ,
rule = Rule (
objectID = "tomato-fruit" ,
conditions = Some (
Seq (
Condition (
pattern = Some ( "tomato" ),
anchoring = Some ( Anchoring . withName ( "contains" ))
)
)
),
consequence = Consequence (
params = Some (
ConsequenceParams (
optionalFilters = Some ( OptionalFilters ( "food_group:fruit" ))
)
)
)
)
)
1
2
3
4
5
6
7
8
9
10
11
12
let response = try await client . saveRule (
indexName : "ALGOLIA_INDEX_NAME" ,
objectID : "tomato-fruit" ,
rule : Rule (
objectID : "tomato-fruit" ,
conditions : [ SearchCondition ( pattern : "tomato" , anchoring : SearchAnchoring . contains )],
consequence : SearchConsequence ( params : SearchConsequenceParams (
optionalFilters : SearchOptionalFilters
. string ( "food_group:fruit" )
))
)
)
Using the dashboard
Visual Editor
Select the Search product icon on your dashboard and then select your index.
Select the Rules section from the left sidebar menu in the Algolia dashboard .
Under the heading Rules , select the index you are adding a Rule to.
Select Create your first rule or New rule . In the drop-down menu, click the Visual Editor option.
In the It all starts here section:
Click Set search query button.
In the side panel, type “tomato” in the input field and click Save
.
In the What do you want to do? section:
Click the Boost Categories button.
In the side panel, type “food_group” in the input field for category, then “fruit” in the second input field and press Save .
Review and publish your changes.
Manual Editor
Select the Rules section from the left sidebar menu in the Algolia dashboard .
Under the heading Rules , select the index you are adding a Rule to.
Select Create your first rule or New rule . In the drop-down menu, click the Manual Editor option.
In the Condition(s) section, keep Query toggled on, select Contains in the drop-down menu, and enter “tomato” in the input field.
In the Consequence(s) section:
Click the Add consequence button and select Add Query Parameter .
Type {"optionalFilters":"food_group:fruit"}
.
Save your changes.
© Algolia · Privacy Policy · Cookie settings