Bouni / kicad-jlcpcb-tools

Plugin to generate BOM + CPL files for JLCPCB, assigning LCSC part numbers directly from the plugin, query the JLCPCB parts database, lookup datasheets and much more.
MIT License
1.16k stars 105 forks source link

library.py: search() - fts5 search improvement for keywords shorter t… #452

Closed chmorgan closed 4 months ago

chmorgan commented 5 months ago

…han 3 unicode characters

FTS5 'match' only evaluates substrings longer than 3 unicode characters, searching for shorter substrings results in no matches being returned.

Fixes an issue where attempting to search for substrings shorter than 3 characters was resulting in empty search results.

Add "AND description LIKE '%SUBSTRING%'" terms for each substring shorter than 3 characters.

chmorgan commented 5 months ago

@whmountains can you give this a shot?

whmountains commented 5 months ago

Thanks for this @chmorgan

I may be doing something wrong, but it's not working for me. When I type in a two-letter query, it continues displaying the results of the previous, longer query.

I added some some logging to find the problem:

2024.04.25 10:09:26 - INFO - search -  evaluating keyword `2k`
2024.04.25 10:09:26 - INFO - search -  using LIKE query for `2k`: `AND description LIKE '%2k%'`
2024.04.25 10:09:26 - INFO - search -  Executing query: SELECT "LCSC Part","MFR.Part","Package","Solder Joint","Library Type","Stock","Manufacturer","Description","Price" FROM parts WHERE parts MATCH ''AND description LIKE '%2k%' AND "Library Type" IN ("Basic") ORDER BY "LCSC Part" COLLATE naturalsort ASC LIMIT 1000
Traceback (most recent call last):
  File "/Users/cw/Documents/KiCad/8.0/scripting/plugins/chmorgan-kicad-tools/partselector.py", line 587, in search
    result = self.parent.library.search(parameters)
  File "/Users/cw/Documents/KiCad/8.0/scripting/plugins/chmorgan-kicad-tools/library.py", line 218, in search
    return cur.execute(query).fetchall()
sqlite3.OperationalError: fts5: syntax error near ""

Something funny is going on when there is nothing to match.: WHERE parts MATCH ''AND

chmorgan commented 5 months ago

Doh, I’ll fix tonight. We may be assuming there is always a match term.

Thanks for the test run.

On Thu, Apr 25, 2024 at 11:13 AM Caleb Whiting @.***> wrote:

Thanks for this @chmorgan https://github.com/chmorgan

I may be doing something wrong, but it's not working for me. When I type in a two-letter query, it continues displaying the results of the previous, longer query.

I added some some logging to find the problem:

2024.04.25 10:09:26 - INFO - search - evaluating keyword 2k 2024.04.25 10:09:26 - INFO - search - using LIKE query for 2k: AND description LIKE '%2k%' 2024.04.25 10:09:26 - INFO - search - Executing query: SELECT "LCSC Part","MFR.Part","Package","Solder Joint","Library Type","Stock","Manufacturer","Description","Price" FROM parts WHERE parts MATCH ''AND description LIKE '%2k%' AND "Library Type" IN ("Basic") ORDER BY "LCSC Part" COLLATE naturalsort ASC LIMIT 1000 Traceback (most recent call last): File "/Users/cw/Documents/KiCad/8.0/scripting/plugins/chmorgan-kicad-tools/partselector.py", line 587, in search result = self.parent.library.search(parameters) File "/Users/cw/Documents/KiCad/8.0/scripting/plugins/chmorgan-kicad-tools/library.py", line 218, in search return cur.execute(query).fetchall() sqlite3.OperationalError: fts5: syntax error near ""

Something funny is going on when there is nothing to match.: WHERE parts MATCH ''AND

— Reply to this email directly, view it on GitHub https://github.com/Bouni/kicad-jlcpcb-tools/pull/452#issuecomment-2077529038, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJH4AG74OCNZDHHY72NE6DY7EMPZAVCNFSM6AAAAABGX4NKM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDANZXGUZDSMBTHA . You are receiving this because you were mentioned.Message ID: @.***>

chmorgan commented 5 months ago

@whmountains alright, updated and should fix the issue you saw.

chmorgan commented 5 months ago

@whmountains ping on whether this addresses your issues. Would like to get it merged in for quality of life improvements for anyone using the plugin.

whmountains commented 5 months ago

Can confirm this PR now works correctly with searches less than 3 chars.

:shipit:

chmorgan commented 4 months ago

Any updates on this @Bouni ? Would like to get this and the other PR merged for quality of use improvements for present users.

Bouni commented 4 months ago

No, I'm on vacation at the moment. Will be back next week

chmorgan commented 4 months ago

Ahh ok, np, have a good vacation!

On Mon, May 6, 2024 at 7:23 AM bouni @.***> wrote:

No, I'm on vacation at the moment. Will be back next week

— Reply to this email directly, view it on GitHub https://github.com/Bouni/kicad-jlcpcb-tools/pull/452#issuecomment-2095787432, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAJH4ABVNXFCTAKKNUODNMLZA5R2DAVCNFSM6AAAAABGX4NKM6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAOJVG44DONBTGI . You are receiving this because you were mentioned.Message ID: @.***>

Bouni commented 4 months ago

LGTM