0

I am developing an e-commerce project on angular where I need to implement search functionality. Now I heard about algoila and Elastic Search and we can use them as third party services for indexing the database.

Now usually what I use to do when I developed small scale applications, I use to maintain an array of combination of strings, characters, which was extracted from The actual string. Lets just give me an example, if I am storing a data for product, Where I have some fields like product name, product category, product department and etc.

So what will I do I will make a combination of strings from these three fields like, product name = "Some Product"; product category = "Some Category"; product department = "Some department"; then my result array will be [S, o, m, e, So, Som, Some, Some P, Some Pro, Some Prod, Some Produ, Some Produc, Some Product, Product, P, r, o, d, u, c, t, and so on for other fields too] and to fetch the result in client side I use to accept a string from user and query if that string exists in array of specific or set of documents. and then return the results.

"select name from PRODUCTS where productname LIKE '%" + keyword + "%'";

I am trying to implement above functionality by creating search tags for queries.

I saw some threads and stack overflow regarding the same, and

startAt and endAt

queries does not solve the issues, like the SQL query performs.

So my question is, if I dont want to use mentioned third party services and instead use my logic to implement search, then what will be the bottleneck for the logic in future in case of big data and high traffic for search requests.

For the note, I am not thinking about fuzzy searches right now. Cause if my logic is implementable and the bottleneck is tolerable, in next development phases I can maintain the search database by customers and there behaviours after not getting the result, that what they are manually opening. By machine learnig and creating new search tags to append the array of the search logic.

  • In case you only want to search for a string that **starts** with some specific characters (which is not a LIKE query) you may be interested by https://stackoverflow.com/questions/56001098/how-to-search-documents-from-a-collection-based-on-a-field-in-firestore-databa/56001481#56001481 – Renaud Tarnec May 15 '21 at 10:04
  • 1
    You've accepted an answer that does not answer this question. The question specifically states you want a solution to make an SQL Like query **LIKE '%" + keyword + "%'"** and the accepted answer does not do that - it only queries for strings that *start* with the same characters. A SQL LIKE query matches a string *within a string* (based on the format in the question) e.g. it finds any values that has `keyword` in any position. I am only pointing this out for clarity so future readers have a clear understanding of the accepted answer (which is a good answer, just not *the* answer) – Jay May 15 '21 at 13:43
  • Also, note that Firestore queries and sorting is case-sensitive so if you want to use an approach like in the answer, you'll have to account for upper and lower case matches. – Jay May 15 '21 at 14:00

1 Answers1

2

We use the same technique in one of our projects for the same reason as you mentioned. In the firestore database you can use the array-contains query parameter to get the data a expected. I would recommend to add delay after typing in the search field so you don't read the data for every key stroke. Maybe also only search after 3 letters entered. That depends on your usecase. I would also use just lower or upper case and parse the searching string to it (if it fits in your use case).

As you mentioned it's only for basic search and for smaller text values but in our case it works fine and as expected.

enter image description here

Tarik Huber
  • 7,061
  • 2
  • 12
  • 18
  • Can you tell me how will it work in case of big product data ? – 50_Seconds _Of_Coding May 15 '21 at 07:16
  • Our Aapp is already in beta and we haven't notices any issues regarding search. I would not expect any issues because we are performing usual firestore queries. The only limitations you have are those you have for array in `firestore`. You can find more about them here: https://cloud.google.com/firestore/docs/best-practices – Tarik Huber May 15 '21 at 07:20
  • This cannot work as is. Firebase queries are case sensitive so none of those elements in `player_name_as_array` will match the player name. See [this answer](https://stackoverflow.com/questions/46554793/are-cloud-firestore-queries-still-case-sensitive/46554857#46554857) and [this answer](https://stackoverflow.com/questions/48096063/cloud-firestore-case-insensitive-sorting-using-query/48098215#48098215) – Jay May 15 '21 at 13:59
  • We make all letters lowercase when we search. That is made by purpose like that. – Tarik Huber May 15 '21 at 15:52