1. Help Center
  2. Search Recommendation

How to set up Raptor Search Personalization in Algolia

To sort Algolia’s search results based on personalized products, brands and categories, use “Optional Filters” in Algolia.  

This is done clientside in Javascript in relation to setting up the searches. 

 Read more about Optional Filters here: 

  1. https://www.algolia.com/doc/api-reference/api-parameters/optionalFilters/   
  2. https://www.algolia.com/doc/guides/managing-results/rules/merchandising-and-promoting/in-depth/optional-filters/

      

When setting up, the flow must be as follows:  

  1. When a user enters the site, Raptor is called. (serverside or clientside through your own server as proxy). 
  2. The results must be available clientside, so they can be injected into Algolia Search at every search.  

Example with CategoryId 

API call for raptor:  

https://api.raptorsmartadvisor.com/v1/    

xxxx/GetSearchPersonalCategoryIds/10/{apikey}?CookieId=8750B8F4-0FFF-9080-F27B-8891EB303AAA&json=true

 
* xxxx = insert customerId 
 

Gives the following result:   

[{"CategoryId":"A","Score":"2.153985"},{"CategoryId":"B","Score":"1.441762"},{"CategoryId":"C","Score":"0.999654"}]  

  

Clientside:  

Where resultsFromRaptor  =

{ results:[{"CategoryId":"A","Score":"2.153985"},{"CategoryId":"B","Score":"1.441762"},{"CategoryId":"C","Score":"0.999654"}]};  

  

Tranform into Optional Filter array:  

Where categoryfilters  = 

resultsFromRaptor.results.map(function(val){   

            return `categoryId:${val.CategoryId}<score=${val.Score}>`   

        }); 

console.log(categoryfilters);  // ["categoryId:A<score=2.153985>", "categoryId:B<score=1.441762>", "categoryId:C<score=0.999654>"]  

            

And add to search.query:  

algolia.search("xxxx", {  

  optionalFilters: categoryfilters  

});  


Example with ProductId 

This can also be accomplished without using scores with ProductId’es (scores on productid’s is not necessary as long as they are in the search result.) 

ProductId’s should be an asset in Algolia.  

Example:   
https://api.raptorsmartadvisor.com/v1/[InsertCustomerid]/GetSearchPersonalProductIds/10/{apikey}?CookieId=8750B8F4-0FFF-9080-F27B-8891EB303AAA&json=true&select=ProductId   

  

Where productsFromRaptor=

{results:[{"productid":"307025005"},{"productid":"307025003"},{"productid":"306001027"},{"productid":"306001026"},{"productid":"307010014"},{"productid":"47200100000"}]};  


where productfilters = 

productsFromRaptor.results.map(function(val){   

            return `productId:${val.productid}`   

        });   

  console.log(productfilters); // ["productId:307025005", "productId:307025003", "productId:306001027", "productId:306001026", "productId:307010014", "productId:47200100000"] 

      

  

If you have any further questions, please reach out to our support at support@raptorsmartadvisor.com