Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
May 13, 2024

Conversation

chmorgan
Copy link
Collaborator

…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
Copy link
Collaborator Author

@whmountains can you give this a shot?

@whmountains
Copy link
Collaborator

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
Copy link
Collaborator Author

chmorgan commented Apr 25, 2024 via email

…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
Copy link
Collaborator Author

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

@chmorgan
Copy link
Collaborator Author

@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
Copy link
Collaborator

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

:shipit:

@chmorgan
Copy link
Collaborator Author

chmorgan commented May 6, 2024

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

@Bouni
Copy link
Owner

Bouni commented May 6, 2024

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

@chmorgan
Copy link
Collaborator Author

chmorgan commented May 6, 2024 via email

@Bouni
Copy link
Owner

Bouni commented May 13, 2024

LGTM

@Bouni Bouni merged commit 3c5c730 into Bouni:main May 13, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants