Contains filter only searches for words

so is this all about fixing the search function so that i can have a search box like in twitter or google, or this bubble forum?

i have tried everything to get a search box that doesnt rely on having to type in an exact word, i want a search box that searches for relevancy, not exact match.

i wonder if anyone found a solution to this.

Actually, yes. Not sure why I hadn’t thought of it before. It won’t work at the scale of a large forum, but should do for smaller searches.

Data …

StringThing

Text
List of Words

WordThing

Text
List of Strings

  1. Take your input with your words in it, and split them out using an “Extract with a Regex” “[^”]+"|([^)]+)|[^"\s()]+ so this produces a list of words

  2. Save your “string” of words. Run an API workflow on the list from step 1. Pass in the “string” thing and the text.

  3. If the “word” doesn’t already exist in WordThing, then Create it, and add it to the List of Words on String

  4. If the “word” does exist in WordThing, then update the Word to add the string to the list, and add it to the List of Words on String as well.

This then gives you a list of words. You can use this in a search box, and then use the output of the search box to show that Word’s list of Strings.

And there you go. Partial Word Search on the beginning of words only. So Alb, Albe, Alber etc

If you were really clever, you could then run API workflows on each word (you will need to limit the number of letters in a word I would think) and pull back all the internal combinations too. So “bert” to match with Albert.

But at that level of complexity your might be better off spinning up an instance of ElasticSearch and using the API connector.

Will put in as an Example in BuildingOnBubble shortly.

2 Likes

I came up with a partial solution that works fairly well and allows me to search multiple fields (with a single part-word term). It’s a basic adaptation of Advanced filters, although rather than truncating, I used Extract with Regex and a dynamic expression.

  • Add a custom state to the input field that will store a lowercase version of the search term

  • Add a workflow for When Input’s Value is Changed so that the first step will update the custom state and the second will change the source of the repeating group to a new filtered list

  • Create the search for your repeating group’s type:filtered, and in the filter criteria, select the Advanced constraint.

  • The constraint looks something like, This Type’s Field1:lowercase:Extract with Regex:count>0 or This Type’s Field2:lowercase:Extract with Regex:count>0


3 Likes

I guess the one detail I should add is that I can’t quite get the input field to function like an autocomplete. The workflow fires when the input value is changed, but this only occurs on a focus change (not a keystroke). Open to any ideas on how to improve this.

Here’s a screenshot of the current solution. My search will pick up any text in the first name, last name, or email address. It is case insensitive and doesn’t care about position within the text. You could easily adapt the regex to match the start of a word or term.

1 Like

Would you mind elaborating a bit more on your solution. I couldn’t follow your description well enough to play with the strategy. I see that you’re working on an example, but thought it might be nice to have a bit more detail here in the forum for brave bubbler’s who want to experiment further.

Yes, I will put it up onto BuildingOnBubble (which I know I said I would do 6 days ago as well !).

The work in progress is here …

https://bubble.io/page?type=page&name=wordsplit&id=trest6&tab=tabs-1

3 Likes

One of my first thoughts was to use a regex to do the partial match but I couldn’t get it to work. What was the regex you used ?

1 Like

I actually tried a couple of more complex options before I settled on the simplest regex I’ve ever written. It is nothing but the search term (converted to lower case). For ‘Input A’, I have a custom state called ‘lowercase’ defined. Within a workflow (When Input A’s value is changed), I assign the value of ‘Input A’s value:lowercase’ to the custom state and then apply extract with regex to each field I want to test (where the regex is ‘Input A’s lowercase’). Next I count the items in the result to determine whether there was a match.



I extended this a bit further to work with multiple search terms in an ‘OR’ fashion. In this case, the custom state is called search_terms. Again, I apply the lowercase transformation followed by search and replace with another simple regex (swapping whitespace for the ‘|’). The regex is nothing more than the transformed string.

Having done this, the search term ‘Al Ein’ becomes the regex ‘al|ein’, which will match Albert Einstien, Al Franken, Bob Feinstein, etc … ‘OR’ logic isn’t perfect, but ‘AND’ would make for a much more complex solution given that I’m searching multiple database fields. I suppose I could also get clever and sort based on the number of matched terms, but the current setup will work well for the size of user list I’m trying to filter.

2 Likes

do you know if your solution for a proper search box works?

what do you mean by those quotations. do i literally type all of those quatations, slashes, and brackets into the extract with a regre, or do i fill something in between those brackets, quatations, etc?

sorry, im a relative newby.

Yes, type that exactly.

1 Like

I was trying to implement your solution but I cannot seem to understand if I am following the steps right.

From your instructions, I created StringThing as a type of data, with a field called String Text (list of wordthings), and I also created WordThing as a type of data, with a field called Wordthing Text (list of stringthings).

Workflow:

  1. When Input Search is value is changed: Create a new StringThing, add this input’s value:extract with regex (regex you provided)
  2. …but then I am not sure what to do

what am i missing here? i know for one, i am missing the role that Wordthing plays, its not clear in your instructions here:

2 Likes

i am looking at your solution. its is very intimidating to me because of its complexity but i will see which one works better for me, so far I have tried the solution NigelG has given and quickly got stuck, so I assume I would quickly get stuck trying to implement your solution too. I wonder if your solution will work for what I am trying to do with giving users the ability to search for posts from other users.

Hi

I implemented your solution. It is working fine. However, when I enter the value in input box once it shows the value correctly. However when I change the input, it does not show the data in the repeating group unless, I refresh the page. Any way around it

Thanks

Add “Clear List in a repeating group” function to the beginning of the search workflow, and clear the group you add your repeating list to.

I’ve just published an article on Medium that outlines a simple implementation on Bubble of search-like functionality.
It can only search for the beginning or end of a text, but it works pretty well, and doesn’t require workflows and other complex combinations.
[https://medium.com/@raz_855/building-a-bubble-is-search-filter-db80b8253d13](http://Building a-Bubble.is search filter)

3 Likes

Just went through your article; thanks for the tip!

May I suggest that you also publish it on the forum in the Tips category? Could be found more easily by other users.

1 Like