Skip to content

Commit d3012d3

Browse files
committed
feat(go): more guides
1 parent e6b224a commit d3012d3

File tree

5 files changed

+129
-0
lines changed

5 files changed

+129
-0
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
{{> snippets/import}}
4+
5+
func enableFilterPromote() {
6+
condition := search.NewCondition().
7+
SetPattern("{facet:brand}").
8+
SetAnchoring(search.ANCHORING_IS)
9+
10+
rule := search.NewRule(
11+
"rule_with_filterPromotes",
12+
*search.NewConsequence().SetFilterPromotes(true),
13+
).SetEnabled(true).SetConditions([]search.Condition{*condition})
14+
_ = rule
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
{{> snippets/import}}
10+
11+
func searchInReplicaIndex() {
12+
{{> snippets/init}}
13+
14+
// 1. Change the sort dynamically based on the UI events
15+
sortByPrice := false
16+
17+
// 2. Get the index name based on sortByPrice
18+
indexName := "products"
19+
if sortByPrice {
20+
indexName = "products_price_desc"
21+
}
22+
23+
// 3. Search on dynamic index name (primary or replica)
24+
_, err = {{#dynamicSnippet}}searchWithIndexNameVar{{/dynamicSnippet}}
25+
if err != nil {
26+
panic(err)
27+
}
28+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
{{> snippets/import}}
10+
11+
func searchWithAnalyticsAndHeader() {
12+
{{> snippets/init}}
13+
14+
/*
15+
'94.228.178.246' should be replaced with your user's IP address.
16+
Depending on your stack there are multiple ways to get this information.
17+
*/
18+
ip := "94.228.178.246"
19+
query := "query"
20+
21+
searchParams := search.SearchParamsObjectAsSearchParams(
22+
search.NewSearchParamsObject().
23+
SetQuery(query).
24+
SetAnalytics(true),
25+
)
26+
27+
_, err = {{#dynamicSnippet}}searchWithSearchParamsAndForwardedHeader{{/dynamicSnippet}}
28+
if err != nil {
29+
panic(err)
30+
}
31+
}
32+
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
{{> snippets/import}}
10+
11+
func searchWithLogicalOr() {
12+
{{> snippets/init}}
13+
query := "the query"
14+
optionalWords := search.ArrayOfStringAsOptionalWords([]string{"the", "query"})
15+
searchParams := search.SearchParamsObjectAsSearchParams(
16+
search.NewSearchParamsObject().
17+
SetQuery(query).
18+
SetOptionalWords(optionalWords),
19+
)
20+
_, err = {{#dynamicSnippet}}searchWithSearchParams{{/dynamicSnippet}}
21+
if err != nil {
22+
panic(err)
23+
}
24+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
"net/http"
7+
)
8+
9+
{{> snippets/import}}
10+
11+
func useConditionlessRule() {
12+
{{> snippets/init}}
13+
14+
objectID := "a-rule-id";
15+
16+
rule := search.NewRule(
17+
objectID,
18+
*search.NewConsequence(/* Set relevant consequence */),
19+
). // Set validity (optional)
20+
SetValidity(
21+
[]search.TimeRange{
22+
*search.NewTimeRange(1_688_774_400, 1_738_972_800),
23+
},
24+
)
25+
26+
_, err = {{#dynamicSnippet}}saveRule{{/dynamicSnippet}}
27+
if err != nil {
28+
panic(err)
29+
}
30+
}

0 commit comments

Comments
 (0)