```
Prompt:
Update GET /api/products to support fuzzy search.
Fuzzy search means if I mispell a word like
"bsktbll" for "basketball", it will still match
"basketball"
```

- Copilot creates a solution that use the `ILIKE` feature in SQLite. However, running the backend causes an error.

```
Prompt:
I got an error:
Error: SQLITE_ERROR: near "ILIKE": syntax error
```

- Copilot attempts to use an alternative solution that uses case-insensitive matching in SQLite to search the text ("BASKETBALL" matches "basketball").

- However, I realize early that this does not solve the problem I want, which is to handle mispellings (I want "bsktball" to match "basketball").

```
Prompt:
I want a search that handles mispellings, not
just case-insensitivity.
```

- Copilot creates a solution that uses an npm package fuzzysort to do the fuzzy searching.

- In the command line, I run `npm install fuzzysort`

- In Postman, I test with `?search=bsktball` and it works

- I test with `?search=apprl` and it doesn't work

- I take a look at the code, and realize it's trying to use fuzzysort on keywords, but keywords is an array.

```
Prompt:
This solution does not work with keywords, which
is an array not a string.
```

- Copilot creates a solution that transforms the keywords array into a string (by combining the keywords with `,`).

- However, when I get the products from the GET /api/products API, the keyword property is now a string instead of an array.

```
Prompt:
This actually modifies the product's keywords array
and turns it into a string. Can we avoid this?
```

- Copilot creates a solution that saves the combined keywords string into a new property called keywordString.

- However, when I get the products from the GET /api/products API, the products no longer have the keywords property, and only have the keywordString property.

```
Prompt:
No, I don't want to modify the original product
object. This creates a new property called
keywordString, but the original object has a
keywords property that is an array of strings.
```

- Copilot generates a somewhat correct solution that involves creating a new products array specifically for searching and leaving the original products array untouched.

### Code Changes
https://github.com/SuperSimpleDev/ecommerce-backend-ai/pull/3/files

- I add some comments to make the code more clear and clean up the code a bit (break some long lines of code into multiple lines).

- The final code works, but there are some issues. For example, the code combines the keywords before searching. This means a keywords array like `["apparel", "shoes"]` will be combined into `"apparel,shoes"` and a search text like "relsho" would match the end of "apparel" and the start of "shoes".

- The ideal solution would probably be to use a different technology for searching, but this exercise just gives you an example of interacting with the AI back-and-forth.