Introduction
To take advantage of personalized search results, you need to send the enablePersonalization and userToken search parameters. The way to do this depends on your implementation of Algolia, and whether or not you use InstantSearch.
InstantSearch
With InstantSearch, you can enable personalization in two different ways. You only need to choose one of them:
- during initialization of your InstantSearch instance
- or by making use of the
configure
widget.
Either way, you need to use the enablePersonalization parameter. You also have to provide the userToken you’re using to send personalization events.
During Initialization
During the setup of your InstantSearch instance, you can pass (almost) any search parameter, including enablePersonalization.
To do this, you can pass an object containing enablePersonalization
and userToken
keys.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| const search = instantsearch({
indexName: 'instant_search',
searchClient: algoliasearch(
'YourApplicationID',
'YourAdminAPIKey'
),
searchParameters: {
enablePersonalization: true,
userToken: 'user-1234',
}
});
// Add widgets
// ...
search.start();
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| import * as algoliasearch from 'algoliasearch/lite';
@Component({
template: `
<ais-instantsearch [config]="config">
<!-- Widgets -->
</ais-instantsearch>
`,
})
export class AppComponent {
config = {
indexName: 'instant_search',
searchClient: algoliasearch('YourApplicationID', 'YourAdminAPIKey'),
searchParameters: {
enablePersonalization: true,
userToken: 'user-1234',
}
}
}
|
1
2
3
4
5
| instantsearch.widgets.configure({
hitsPerPage: 8,
enablePersonalization: true,
userToken: 'user-1234',
});
|
1
2
3
| <ais-configure
[searchParameters]="{ hitsPerPage: 5, enablePersonalization: true, userToken: 'user-1234' }"
></ais-configure>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| <template>
<ais-instant-search
index-name="instant_search"
:search-client="searchClient"
>
<ais-configure :clickAnalytics="true" userToken="user-1234" />
</ais-instant-search>
</template>
<script>
import algoliasearch from 'algoliasearch/lite';
export default {
data() {
return {
searchClient: algoliasearch(
'YourApplicationID',
'YourAdminAPIKey'
),
};
},
};
</script>
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
| import algoliasearch from 'algoliasearch/lite';
import { InstantSearch } from 'react-instantsearch-dom';
const searchClient = algoliasearch(
'YourApplicationID',
'YourAdminAPIKey'
);
const App = () => (
<InstantSearch
indexName="instant_search"
searchClient={searchClient}
>
<Configure clickAnalytics userToken="user-1234" />
</InstantSearch>
);
|
API Clients
If you’re using one of our API clients, you can use the enablePersonalization parameter in the search method. You also have to provide the userToken that you’re using to send personalization events.
1
2
3
4
| $index->search('query', [
'enablePersonalization' => true,
'userToken' => '123456'
]);
|
1
| index.search('query', {'enablePersonalization': true, 'userToken': '123456'})
|
1
2
3
4
| index.search('query', {
'enablePersonalization': true,
'userToken': '123456'
});
|
1
| index.search('query', {'enablePersonalization': True, 'userToken': '123456'});
|
1
2
3
4
5
6
| let query = Query(query: "query")
query.enablePersonalization = true
index.search(query, completionHandler: { (res, error) in
print(res)
})
|
1
2
3
4
5
| index.search(
new Query("query")
.setEnablePersonalization(true)
.setUserToken("123456")
);
|
1
2
3
| Query query = new Query("query");
query.EnablePersonalization = true;
query.UserToken = "123456";
|
1
2
3
| Query query = new Query("query")
.setUserToken("123456")
.setEnablePersonalization(true);
|
1
2
3
4
| res, err := index.Search(
"query",
opt.EnablePersonalization(true),
)
|
1
2
3
4
5
6
7
| client.execute {
search into "myIndex" query Query(
query = Some("query"),
enablePersonalization = Some(true),
userToken = Some("123456")
)
}
|