1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| // 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);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| # 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
index.save_rule(rule)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| // Create the rule
const rule = {
objectID: 'article-rule',
conditions: [{
pattern: 'article',
anchoring: 'startsWith'
}],
consequence: {
params: {
query: {
type: 'remove',
delete: 'article'
},
restrictSearchableAttributes: ['title', 'book_id']
}
}
};
// Save the Rule
index.saveRule(rule);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| # 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)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
| // Create the rule
let rule = 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 Rule
index.saveRule(rule, forwardToReplicas: true) { result in
if case .success(let response) = result {
print("Response: \(response)")
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
| var rule = new Rule
{
ObjectID = "article-rule",
Conditions = new List<Condition> { new Condition { Anchoring = "startsWith", Pattern = "article" } },
Consequence = new Consequence
{
Params = new ConsequenceParams
{
SearchableAttributes = new List<string> { "title", "book_id" },
Edits = new List<Edit>
{
new Edit {Type = EditType.Remove, Delete = "article"}
}
}
}
};
index.SaveRule(rule);
// Asynchronous
await index.SaveRuleAsync(rule);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| Condition condition = new Condition().setPattern("article").setAnchoring("startsWith");
Consequence consequence = new Consequence();
List<Edit> edits = Collections.singletonList(new Edit().setDelete("article"));
ConsequenceParams params = new ConsequenceParams();
params.setRestrictSearchableAttributes(Arrays.asList("title","book_id"));
params.setConsequenceQuery(new ConsequenceQuery().setEdits(edits));
consequence.setParams(params);
Rule rule =
new Rule()
.setObjectID("article-rule")
.setConditions(Collections.singletonList(condition))
.setConsequence(consequence);
index.saveRule(rule);
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| rule := search.Rule{
ObjectID: "article-rule",
Conditions: []search.RuleCondition{{Anchoring: search.StartsWith, Pattern: "article"}},
Consequence: search.RuleConsequence{
Params: &search.RuleParams{
Query: search.NewRuleQueryObject(
search.RuleQueryObjectQuery{
Edits: []search.QueryEdit{
search.RemoveEdit("article"),
},
},
),
QueryParams: search.QueryParams{
RestrictSearchableAttributes: opt.RestrictSearchableAttributes(
"title",
"book_id",
),
},
},
},
}
res, err := index.SaveRule(rule)
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| val rule = Rule(
objectID = "article",
conditions = Some(Seq(Condition(
anchoring = "startsWith",
pattern = "article",
))),
consequence = Consequence(
params = Some(
Map(
"query" -> Map("edits" -> Seq(Edit("delete", "article"))),
"restrictSearchableAttributes" -> Seq("title", "book_id"),
)
)
)
)
client.execute {
save rule rule inIndex "indexName"
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
| val rules = rules {
rule(
"rule",
listOf(Condition(StartsWith, Literal("article"))),
Consequence(
query = query {
restrictSearchableAttributes {
+"title"
+"book_id"
}
},
edits = edits { +"article" }
)
)
}
index.saveRules(rules)
|