Search 2.0 - Summarizing what I've learned exploring Algolia

@mishav - If you get a chance, one other variant I’ve run into is to be able to use multiple indexes in a single search. I could use your help with the JS.

I initially built a single index (and this works as you’ve shown) but then realized that updates via bubble lead to many schedule a workflow on a list actions which I’d like to avoid.

An alternative is to have 2 indexes underlie the searchbox similar to this question and fiddle. Does this piece of code support using 2 indexes?

image

I assume the search results are separate?

The fiddle didn’t actually do the linking, so I hunted around for the relevant bits and came up with altering the second index query when the first index’s searchFunction is called.

search = instantsearch({
  appId: 'latency',
  apiKey: '6be0576ff61c053d5f9a3225e2a90f76',
  indexName: 'instant_search',
  routing: true,
  searchFunction: function(helper) {
    helper.search();
    movies.helper.setQuery(helper.getQuery().query);
    movies.helper.search();
  }
});

new page with two indexes two searches one searchbox

I see what you did. This might be handy as well, but for this particular use case I’m actually trying to get the results from 2 indexes to appear within the same hits (everything in search_result variable).

Use case: A user wants to search for both their contacts and friends in the same search.

As one index, the index might look something like this…

user1 | user2 | is_friend (yes or NULL) | in_common_groupie (yes or NULL)
john | mary | yes | yes
kate | mary | yes | no

So in instant search filter user1 = current_user and is_friend = yes or in_common_groupie = yes.
But the problem is that updating this structure requires lots of updates. Fo example, if user2 leaves all groups, all user2’s records need to be updated.

If instead, this is two indexes, I can avoid big updates.

friends index
user1 | user2
john | mary
kate | mary

groups index
user | group
john | tech
john | social
mary | social
katie | tech

Bubble database
User table
user | list of groups
john | tech, social
mary | social
katie | tech

Instant search filter
friends$user1 = current_user OR
groups$group IS IN current_user_list_of_groups

So
friends$user1 = john
groups$group IS IN (tech, social)

This will return
mary (as friend)
mary (as social groupie)
katie (as tech groupie)

@kramwe

This time I’ve done a slightly unrealistic example, a search for products and a search for movies, then merge the results together and sort by “name”.

I guess you’d do something similar, but your hits result would be almost the same structure, so the merge would be more natural.

Also I’ve only tied one of the searchboxes to the url query parameter.

You’d probably want to pre-set a filter on your group list, and not use a searchbox for it? I didn’t prototype that combination yet.

The main change is the combine_hits function.

2 indexes merged to 1 result list

image


*EDIT* - I just found the docs for derived multi-queries, maybe I didn't need to do the combine function after all.

I’m looking at this now. Only update I’m trying to make is to make only one search box that searches movies and products simultaneously. Lots of progress!

This is the version I’m working on + your combo function because I’d like the results to appear in a single list as you’ve done.

One search box. Over 2 indexes. All in a single repeating group.


https://jsfiddle.net/j9nwpz34/27/

Just in case someone wants an easier way of using Algolia in their app we have built an Algolia plugin for Bubble. Check it out here 🔍 Algolia Search - New Plugin from Zeroqode

Levon Terteryan

Founder @ Zeroqode

zeroqode-for-web-160x120

Bubble Templates

Bubble Plugins

Bubble Courses

Convert Web to iOS & Android

No-code Development Services

2 Likes

@levon can your plugin be used generally (not updating/searching from internal bubble database, but external database) and then populate a RG with the search results? Wasn’t sure if there are assumptions in the plugin that would require some of the bubble specific configuration. I’d handle passing and updating the data from another database to algolia myself.

Algolia plugin works with Algolia only. But in order to search in Algolia data first has to be transmitted there. The plugin has the actions to send Bubble data to Algolia for further searching.
Makes sense?

yep, I know it works only with Algolia - trying to understand if using bubble data is a requirement for the plugin. thanks!!

I see, no, it’s not required at all. You can populate any data into your Algolia index and then use the plugin to display that data in any repeating group
Hope this helps

Yes, definitely! Thank you

Hi @mishav,

Following your method, users are able to view the API key and id through inspecting the page.

Any suggestions on how to make it so that users aren’t able to access this sensitive information using your method? In addition, does Bubble provide any tools for us developers to encrypt or protect our HTML source code? @emmanuel @josh

The front-end key is by design. There are different types of keys including a front-end specific search key that is exposed to users. There is a separate key only known to you for POSTing data into the indices.

Did anyone tried to search with algolia through fields that contains other data types? Is it possible?
Also, what is the best way of sending data to groups/rg from algolia results?
I can think of either search based on some value from algolia search or display the whole data from the algolia.
What is the best way to do it?

I only have a bit of info on this - my business partner coded this portion of our app. Passing a list of search results back from Algolia to Bubble --> This is by far the slowest portion of the functionality. Loading a RG with data in Bubble is workable but certainly slow-ish.

For much better speed, you can use Algolia’s list of results (in custom code) and then pass the selected result into Bubble to trigger the next step.

1 Like

Thanks for the help. Algolia seems to be little pricy, we have a team of 5 member and 120,000 rows in database and we spent 300 units just for 2 weeks, it should cost us 600$/month when we will jump on paid plan 1$ per unit.
Do you expirience the same amount of units that you spend or maybe it’s something wrong in my setup?

We’re indexing single composite tables that are displayed as bubble RG at a cost of $29/mo. We also aren’t using the bubble Algolia plugin but rather @mishav raw JS to handle the FE instant search.

Could you help me out on how to filter the results using @mishav method in the html element?

This is the best Algolia thread on the forum.

In my case, the new native bubble Algolia plugin won’t work. I don’t have a public/ open data app. Each user only has access to her own data.

I’m torn between:

  1. waiting for the native bubble Algolia plugin to update for private data

or

  1. Trying to set up my own integration via API.

I spent about 8 hours running through this threat and testing on my own API. The level of difficulty seems to be pretty high. I was able to replicate @mishav 's setup and that’s pretty much it. I still need to:

  • make it mobile responsive
  • set the data updates
  • set privacy settings for private data
  • and more

My questions: has anyone set this up for a private data app that’s mobile responsive? Roughly how long did it take and how frequent do you need to maintain bugs?

2 Likes

Thanks a lot @mishav!! I was trying to implement algolia for a while, and through your post it was blazing fast! Do you know how can I insert more Algolia elements (i.e: refinementLists, stats, pagination, …) to the same bubble page?
I’ve tried inserting the code snippets into the same HTML you used and even breaking them into different HTML modules, but had no success in both ways.

1 Like