In my current project, I am managing a large hardcoded array of objects that act as a database. These objects contain properties like title and content. One of the challenges I am facing involves enhancing the existing search functionality to return all objects containing a specific keyword in either the title or content.
At the moment, I am using a basic filtering solution, but considering the large number of objects (in the millions), I have been tasked with finding a more efficient way to perform searches accurately. The code base is primarily in Typescript/Javascript.
A snippet of how the objects are structured:
{
"id": "ab6fc754-0e01-5cfb-84b9-cf37c1c0cdb5",
"title": "Collapse/expand code affecting the page footer\n",
"content": "I have placed collapse/expand code onto one of my pages, but the footer now has a huge white space above it in the preview. Is there a way to fix this?",
"userEmail": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ea999f99808598845baa80.........................</a>",
"labels": ["Collapse", "Expand"],
"creationTime": 1517833093439
},
The current simplistic search implementation is as follows:
paginatedData = paginatedData.filter((ticket: Ticket) => (ticket.content.toLowerCase() + ticket.title.toLowerCase()).includes(searchTerm.toLowerCase()))
To improve efficiency, I may need to consider restructuring the database without altering its core structure. Although one idea I am exploring is integrating the objects into a database like Mongo for faster searches, I am unsure if it would provide the desired speed improvements for the type of searches required.