stockpile-co / api

The API for Stockpile, an app that manages stuff for organizations.
0 stars 1 forks source link

Add ability to search for a single item #296

Closed emroussel closed 7 years ago

emroussel commented 7 years ago

As a user, I want to be able to find an item by searching for its brand or model so that I can find it more easily.

AdamVig commented 7 years ago

The useful searchable fields are brand and model. Barcode and category are not currently displayed in the inventory list, so it would be confusing if the search bar showed results for those two pieces of data.

There are two ways I could implement this.

First, MySQL supports full-text search (though Knex.js only supports it via .raw functions). This approach wouldn't work in this specific instance, however, because the item table does not have any textual fields to search (other than barcode, which the average user would not be searching for). I could make a view containing all the textual data related to items, but it is impossible to create fulltext indexes on views.

It might be possible to change the name columns in brand and model to full-text indexes, then to use the match againstsyntax to search them in query where they are joined with the item table. This is worth looking into. Tutorial on full-text searches in MySQL.

Second, MySQL supports the LIKE operator for fuzzy searches in where clauses. Knex.js has good support for it as well. This would work well for this simple use case, but may not be as performant or scale as well as the match against approach.

AdamVig commented 7 years ago

The implementation of this feature shows the value of #373 (Refactor endpoint service) because it involves adding yet another optional parameter to endpoint.getAll that is passed through to the db service.

In this case, there is some logic implemented in the endpoint service before the parameter is passed to the db service, but that could also be implemented with a simple service method called by the endpoint itself before passing the search to the db service.