alfredapp / google-drive-workflow

Alfred Workflow for Google Drive
BSD 3-Clause "New" or "Revised" License
169 stars 8 forks source link

Case-insensitive Search for non-ASCII Unicode Characters #63

Closed vanushah closed 9 months ago

vanushah commented 9 months ago

Feature details

Hello.

I've found out that the search for non-Latin characters is case-sensitive. So when I search for сбер, it cannot find occurrences of Сбер, for example.

I found out why this is happening. By default, the LIKE operator in this query is case-sensitive for Unicode characters. To make it case-insensitive, you must compile and load the ICU extension. Here is the link to this extension: link

I've managed to compile and change the gd script to solve the issue. However, I'm unsure how to integrate my changes into the main branch.

So, at least, I wanted to share the steps that I took to achieve this:

  1. Installed icu4c, ruby, gcc and pkg-config packages with brew:

    $ brew install icu4c ruby gcc pkg-config
  2. Downloaded and untared the source code of sqlite3 via this link: https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release

    $ wget 'https://www.sqlite.org/src/tarball/sqlite.tar.gz?r=release' -O sqlite.tar.gz
    $ tar xzvf sqlite.tar.gz
  3. Compiled the extension:

    $ cd ~/Downloads/sqlite/ext/icu
    $ export PKG_CONFIG_PATH="$(brew --prefix icu4c)/lib/pkgconfig"
    $ gcc -fPIC -dynamiclib icu.c `pkg-config --libs --cflags icu-uc icu-io` -o libicu.dylib -I../../src

    Note if your command output complains like that:

    $ pkg-config --libs --cflags icu-uc icu-io
    Package icu-uc was not found in the pkg-config search path.
    Perhaps you should add the directory containing `icu-uc.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'icu-uc' found
    Package icu-io was not found in the pkg-config search path.
    Perhaps you should add the directory containing `icu-io.pc'
    to the PKG_CONFIG_PATH environment variable
    No package 'icu-io' found

    Then you need to set PKG_CONFIG_PATH environment variable before trying to compile the extension.

  4. You need to install sqlite3 gem for Homebrew ruby:

    $ $(brew --prefix ruby)/bin/gem install sqlite3
  5. Patched the gd script so it would use Homebrew ruby (I have an Apple Silicon Mac, so my Homebrew is under the/opt folder) and would load the extension:

    
    #!/opt/homebrew/opt/ruby/bin/ruby
    # frozen_string_literal: true

require 'json' require 'sqlite3'

[...]

Filter paths

db = SQLite3::Database.new(Cache_file) db.enable_load_extension(true)

NB: Your path might be different

db.load_extension("/Users/ivan/Downloads/sqlite/ext/icu/libicu.dylib") Results = db.execute("SELECT fullpath FROM main WHERE #{Dir_only} #{Array.new(Query.length, 'basename LIKE ?').join(' AND ')} ORDER BY accesstime DESC LIMIT ?;", Query, Limit).flatten



That's it. After these changes, everything works like a charm!

<img width="764" alt="image" src="https://github.com/alfredapp/google-drive-workflow/assets/188117/7ec85004-6851-473c-8187-d61602471b6e">

Can we integrate my description of steps into the official manual? What do you think?

Regards,
vanushah
vitorgalvao commented 9 months ago

Thank you for the detailed description and steps. Unfortunately, it makes the process somewhat convoluted and adds several dependencies to all users for a problem that only affects a small subset. And since Google Drive is now using the File Provider API, it may even be possible that you can find files without the need for the workflow.

As such I won’t integrate the fix officially, but this post could be quite useful to direct other users who have the same problem. Again, thank you for taking the time to write it. I have a few ideas for the (non-near) future of the workflow, that if viable may end up solving the issue without needing the extra steps.

Have a great weekend.