SearchModule+ | Accurate and effective Search Bars/Engines made easily!

:page_with_curl:Source Code|:books:Documentation|:man_surfing:Playground

Create accurate and effective Search Bars/Engines.


🎪Showcase/Examples:🎪

🛒Roblox Catalog re-creation (With working search-bar)🛒:

📑Search-able Player-List:📑

👨‍🏫Search-able rules GUI:👩‍🏫

Extra Details

In this example, the typo detection is turned on.
Notice how the following words show current results:

Typo | Result
sbear → swear
r3st → restricted
r3s → respect
st@f → staff
snare → share

🧊Cube Control Game: 🧊


🍀Features:🍀

🥅1. Accuracy and Filtering:🥅

More Details...

This search bar is designed to be very accurate and return the most relevant results.
From all 3 functions included, you will get an ordered table from the most relevant, to least relevant.
E.g.
Search term/input: i love ban

Worth to mention that Typo/misspelling detection is turned on here, and the letter’s case is ignored.

Options to sort:

i absolutely love ban,
bans are lovable,
i love ban,
i lov3 bam,
bans exist,
banana chipotle,
chocolate
image

Sorted Options:
image
As you can see, the most relevant is 1, and the least relevant is 7. The module was given a raw (unordered) table of strings and ordered them.

Feel free to try the following code for yourself:

(assuming the module is called SearchModule, in a folder called Modules, in ReplicatedStorage:

local searchbar = require(game:GetService("ReplicatedStorage").Modules.SearchModule) --Require the module

--It is here just for testing purposes

local term = "i love ban" --What we search for (search term)

local available = {"i absolutely love ban", "bans are lovable", "i love ban", "i lov3 bam", "bans exist", "banana chipotle", "chocolate"}

--The available options to sort ^

local list = searchbar:GetSortedListFromStringTable(available, term, true,false, false) --Search for the term in the available options,
--and sort them from most relevant, to least relevant.

print(list)

🔡2. Typo/Misspelling Detection:🔤

More Details...

This module includes a nifty Typo/Misspelling Detection.
It’ll detect 1 letter typos/misspellings, and take them into account (if enabled), to show you the most accurate result.

This is optional, and can be disabled/enabled via the function argument.

Examples:

  1. As you can see in this image, the word sbear is written, instead of swear (second letter w misspelled with b:thinking:), yet the module took it into account, and displaying the no swearing
  2. image
    In this image, the word r3st is written as a misspelling of rest. The module noticed it and displayed Restricted.
  3. image
    In this image, the word r3s is misspelled, and you get the results: Restricted, and Respect.
  4. image
    In this image, the word st@f is misspelled, and *staff is displayed.

🔡3. Letter's case detection:🔠

More Details...

In order to give accurate results, the module has an option to ignore the letter’s case.

Therefore, having lower-cased/upper-cased letters won’t affect anything.

Be → be
hELlo → hello
(Important to mention that even with case-ignored letters, the sorted table will return the strings as input, and not lowered!)

Important example

Search Input/Term: i love ban
The following options will be inputted with the same casing
“I absolutely love ban”, “Bans Are Lovable”, “i love ban”, “i lov3 bam”, “bans exist”, “banana chipotle”, “chocolate”.
image

This is optional, and can be disabled/enabled via the function argument.

🚥4. Ignore Sentences with no-matches🚥

More Details...

That means, that when there are no matches in the sentences (E.g. i love ban, is not matching with chocolate), the non-matching sentences won’t be returned in the table.

Examples

I’ll use the Rules GUI as an example.

  1. image
    As you can see here, the term/input is r3s (misspelled res), and only the matching Labels show up (Restricted and Respect).
  2. image
    Here the term/input is Obey, and only the matching sentence shows up, everything else is ignored.

This is optional, and can be disabled/enabled via the function argument.

💾Documentation:💾

This module contains a set of 3 functions:

SearchModule:GetSortedListFromStringTable(tableOfStrings, input, typosConsidered, lettercaseConsidered, ignoreNonMatches)
SearchModule:GetSortedListFromStringTable(
	tableOfStrings, 
	input, 
	typosConsidered, 
	lettercaseConsidered, 
	ignoreNonMatches
)

Yes, this function name is pretty long, but what it does is just as the name.

It inputs a table of unordered strings and sorts them.

Parameters

1. tableOfStrings [table]

The first parameter is a table filled with unordered strings. This argument is a must (not optional).
E.g.

local tableOfStrings = {"I absolutely love ban", "Bans Are Lovable", "i love ban", "i lov3 bam", "bans exist", "banana chipotle", "chocolate"}

2. input [string]

This parameter is our search input/term.
All strings in the tableOfStrings will be sorted by their matches to this string.

3. typosConsidered [boolean](optional)

When set to true, the module will look for possible typos/misspellings (Look at **Feature 2), and take them into account when sorting.

When set to false/nil or not set, it will consider typos as normal words (means typos will not be considered), and misspellings will change results accordingly.

It is completely optional and set to false by default.

4. lettercaseConsidered [boolean](optional)

When set to true, the module will not ignore letter-cases.
E.g.
be ≠ BE (not matching)
oBeY ≠ Obey (not matching)

When set to false/nil or not set, it will ignore all cases (upper and lower), and treat the words by just their letters.
E.g.
be = BE (matching)
oBeY = Obey (matching)

It is completely optional and set to false by default.

5. ignoreNonMatches [boolean](optional)

When set to true, the module will exclude strings that have no matches with the input/term at all, from the table.

When set to false/nil or not set, it will include all strings given, sorted from most relevant, to least relevant, including those that have no matches at all.

It is completely optional and set to false by default.

Code Example:

local SearchModule = require(game:GetService("ReplicatedStorage").Modules.SearchModule) --Require the module

local term = "i love can" --What we search for (search term/input)

local available = {"I absolutely love can", "Cans Are Lovable", "i love ban", "i lov3 cad", "cans exist", "banana chipotle", "chocolate"}

--The available options to sort ^

local list = SearchModule:GetSortedListFromStringTable(
	available, --Table Of Strings
	term, --Search Input/Term
	true, --Typos will be considered
	false, --Ignore letter-cases
	false --Include strings that don't match
) --Search for the term in the available options,
--and sort them from most relevant, to least relevant.

print(list)

Output:
image


SearchModule:GetSortedListFromInstanceTable(tableOfInstances, classFilter, propertyFilter, input, typosConsidered, lettercaseConsidered, ignoreNonMatches)

Woah, an even longer function!

This function acts just like the function above (GetSortedListFromStringTable), but with instances.
It sorts all instances of classFilter in the table, by their propertyFilter property.

And the other 3 parameters are the same as SearchModule:GetSortedListFromInstanceTable(…), read about them above.

Parameters

1. tableOfInstances [table]

This argument is a table of all instances that will be sorted.

2. classFilter [string]

This parameter represents the Class Name of the instances to sort. (e.g. BasePart, ValueBase, GuiObject, Frame, TextLabel, Part, etc)
Only instances of this ClassName will be sorted and added to the table.

3. propertyFilter [string]

This parameter represents the PropertyName of the instances.
The instances will be sorted by this property (e.g. Name, Text, Value)

4. input [string]

This parameter is our search input/term.
All instances in the tableOfInstances will be sorted by their property (propertyFilter) matches to this string.

5. typosConsidered [boolean] (optional)

Explanation

When set to true, the module will look for possible typos/misspellings (Look at **Feature 2), and take them into account when sorting.

When set to false/nil or not set, it will consider typos as normal words (means typos will not be considered), and misspellings will change results accordingly.

It is completely optional and set to false by default.

6. lettercaseConsidered [boolean](optional)

Explanation

When set to true, the module will not ignore letter-cases.
E.g.
be ≠ BE (not matching)
oBeY ≠ Obey (not matching)

When set to false/nil or not set, it will ignore all cases (upper and lower), and treat the words by just their letters.
E.g.
be = BE (matching)
oBeY = Obey (matching)

It is completely optional and set to false by default.

7. ignoreNonMatches [boolean](optional)

Explanation

When set to true, Instances with properties that have no matches with the input/term will be excluded from the table.

When set to false/nil or not set, it will include all instances given, sorted from most relevant, to least relevant by the selected property, including those that have no matches at all.

It is completely optional and set to false by default.

Code Example:

Search Bar GUI
local SearchModule = require(game:GetService("ReplicatedStorage").Modules.SearchModule) --Get the search module
----------<[VARIABLES]>
local frame = script.Parent
local search = frame:WaitForChild("Search") --Get the search bar (TextBox)
local list = frame:WaitForChild("Options") --Get the Search Options
----------------------



search:GetPropertyChangedSignal("Text"):Connect(function() --When the searchbar's text changes, do:
----------------------------------------------------------------------------------------------------------
	local sorted = SearchModule:GetSortedListFromInstanceTable(
		list:GetChildren(), --An instance table of text labels and a UIListLayout
		"TextLabel", --sort only TextLabels
		"Text", --Sort them by their Text property
		search.Text, --The search term (input)
		true, --Take typos/misspellings into account.
		false, --Ignore letters' cases.
		false --Do not exclude no-matches from the table
	)
----------------------------------------------------------------------------------------------------------

	
	--Sort all the commands by the text/input (from the SearchBar), to see which ones the player is looking for.
	--print(sorted) --Debug print
	for i = 1,#sorted,1 do -- Iterate through the sorted rules table:
		sorted[i].LayoutOrder = i --Sort them in the GUI.
	end
end)

SearchModule:GetSortedListFromInstanceChildren(instance, classFilter, propertyFilter, input, typosConsidered, lettercaseConsidered, ignoreNonMatches)

This function is identical to the function above (SearchModule:GetSortedListFromInstanceTable(…)).

But instead of putting a pre-made table into the function, you put an Instance, and it uses Instance:GetChildren() automatically in the function.

Parameters

1. instance [Instance]

All children of this instance will be sorted by the propertyFilter

Parameters 2 to 7 are documented in the function above.

Code Example:

Search Bar GUI
local SearchModule = require(game:GetService("ReplicatedStorage").Modules.SearchModule) --Get the search module
----------<[VARIABLES]>
local frame = script.Parent
local search = frame:WaitForChild("Search") --Get the search bar (TextBox)
local list = frame:WaitForChild("Options") --Get the Search Options
----------------------



search:GetPropertyChangedSignal("Text"):Connect(function() --When the searchbar's text changes, do:
----------------------------------------------------------------------------------------------------------
	local sorted = SearchModule:GetSortedListFromInstanceChildren(
		list, --An instance with children of classes:  TextLabel and a UIListLayout.
		"TextLabel", --sort only TextLabels
		"Text", --Sort them by their Text property
		search.Text, --The search term (input)
		true, --Take typos/misspellings into account.
		false, --Ignore letters' cases.
		false --Do not exclude no-matches from the table
	)
----------------------------------------------------------------------------------------------------------

	
	--Sort all the commands by the text/input (from the SearchBar), to see which ones the player is looking for.
	--print(sorted) --Debug print
	for i = 1,#sorted,1 do -- Iterate through the sorted rules table:
		sorted[i].LayoutOrder = i --Sort them in the GUI.
	end
end)

🏁Get Started:🏁

  1. First, get the module from the link..
    Take it from your inventory (via the toolbox).
    image
  2. Create a folder called “Modules” in ReplicatedStorage, and place the SearchModule there.
    image
  3. That’s it! Now you can use it from any script or local script using the following line:
local SearchModule = require(game:GetService("ReplicatedStorage").Modules.SearchModule) --Require the module

Read in the documentation about the functions to learn how to use it, or edit the playground place! It includes a bunch of examples, with explanations in all scripts..


In Addition,

  • This Module is free for anyone to use, credit is not a must but will appreciate it :wink:.

  • If you have any feedback/suggestions/ideas, please let me know! I’ll gladly consider them.

  • This Module may be Updated in the future, the current version is 1.0.

@LightningLion58

44 Likes

Thank you, LightningLion58. I am sure that many developers will find this useful. Thank you for making this freely accessible.

2 Likes

could’nt agree more. Thanks dude

1 Like

Pretty cool, I liked the catalog searcher.

1 Like