0

This isn't a question directly related to the code itself, but more towards the best way to implement something.

My app is built with JavaScript, specifically done using React, and allows a user to have multiple products, which each product having multiple sub-items. For example, the user might create a product which they have called "Handmade Wooden Engraved Dog Bowl", and then have sub-items for each website they have their product listed on. The dataset would look something like this:

{ 
  "name": "Handmade Wooden Engraved Dog Bowl",
  "tags": ["wooden", "handmade", "engraved", "pet", "dog", "bowl"],
  "item": {
    id1: {
      "name": "Handmade Dog Bowl",
      "website": "amazon",
      "active": true,
      },
    id2: {
      "name": "Handmade Wooden Dog Bowl",
      "website": "etsy",
      "active": false,
      }
  }
}

I have a requirement for being able to search the name of the product, the product tabs, but then also the data within each item.

For example, show all products where the tag contains engraved dog bowl, where tags contain handmade and where etsy = false

It might be possible to do this client-side with Firestore, but it will require numerous calls, and also data processing will be dependant on the users' computer.

The issue here is each user has about 2,000 products on average, and we could be looking at 2,000 users and up which rules out something such as Algolia due to extremely high costs.

Does anyone have any suggestions around how I could tackle this search issue I have without it costing the earth?

Hyyan Abo Fakher
  • 3,497
  • 3
  • 21
  • 35
K20GH
  • 6,032
  • 20
  • 78
  • 118
  • Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it. – Hyyan Abo Fakher Aug 21 '18 at 13:35
  • might help : https://stackoverflow.com/questions/1946165/json-find-in-javascript – Hyyan Abo Fakher Aug 21 '18 at 13:35
  • might help : https://github.com/bvaughn/js-search – Hyyan Abo Fakher Aug 21 '18 at 13:36
  • Using [web workers](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Using_web_workers) is an option too – Hyyan Abo Fakher Aug 21 '18 at 13:38
  • The issue isn't so much as how to code it, but how best to implement it. I know I can search through the JSON, but downloading thousands of records and processing them on a client isn't suitable – K20GH Aug 21 '18 at 14:02
  • Did you consider using a 3rd party search service, like the Firestore documentation talks about here https://firebase.google.com/docs/firestore/solutions/search? – Frank van Puffelen Aug 21 '18 at 14:17
  • @FrankvanPuffelen Yes- `we could be looking at 2,000 users and up which rules out something such as Algolia due to extremely high costs` – K20GH Aug 21 '18 at 14:37

1 Answers1

1

Your asking how to implement a search algorithm. This article by Meet Zaveri Algorithms I : Searching and Sorting algorithms provides a good intro to the ideas.

Asymptotic Notations Big Oh (O) Big Omega (Ω) Big Theta (Θ)

Space Complexity

Linear Search

Binary Search

Hashing / Hash Functions

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91