QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Want to suggest an idea for a new plug-in? Know for sure what is needed for plug-in X to become the best? Write here.
Post Reply
pandaprada
Posts: 5
Joined: Wed 29 Jan, 2025 03:10

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by pandaprada »

I've migrated to FAR from Total Commander about 10 years ago and never turned back.

But there is this one plugin (QuickSearch Extended) in Total Commander that I miss from time to time, Actually, one feature in this plugin: pinyin search.

I'm a Chinese and have lots of files with Chinese names. With this feature I can search quickly for the Chinese files I need.

Let me explain a bit. To input Chinese characters, we can use Pinyin method, that is, typing a couple of alphabets for each Chinese Character. for example, by typing "zhong guo" I'll get two Chinese characters (中国).

The beauty of this feature from QuickSearch Extended plugin is that to search for files with this two Chinese characters anywhere in the filenames, I just need to type the first letter of each character "z g" in the search and matching files will be shown.

I wish some geeks at the forum can have a look into this. Maybe it can be done for Far as well?
Yegor
Posts: 1420
Joined: Mon 04 Apr, 2005 13:41
Location: San Ramon, CA / Kharkov, UA
Has thanked: 45 times
Been thanked: 73 times

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by Yegor »

As I understand it looks like there is no one to one conversion from Chinese back to Pinyin due to "tones". But if there is a map/table (one to one) from Pinyin to Chinese characters it should be feasible by creating a plugin or even by macro.
Мы не можем ждать милостей от Фара, взять их у него — наша задача! (C) Мичурин
pandaprada
Posts: 5
Joined: Wed 29 Jan, 2025 03:10

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by pandaprada »

@Yegor
You're absolutely right about "tones". So when I search using only the first letter of each character, there might be a couple of matches (characters with different "tones") instead of one. but that's OK in actual use for file name searches.

In the QuickSearch Extended plugin, there is a file called tcmatch.tbl, I'm not sure if this is the mapping table. If I remember correctly, this file was actually created by Ghisler, the creator of Total Commander.

This plugin also includes the source codes, but I'm not a coder and I cannot read or understand it.

I'm attaching both the plugin files and sources files for anyone who are interested.
Attachments
QuickSearch eXtended.zip
(3.42 MiB) Downloaded 12 times
QuickSearch eXtended - source.zip
(1.22 MiB) Downloaded 12 times
pandaprada
Posts: 5
Joined: Wed 29 Jan, 2025 03:10

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by pandaprada »

I tried to peek into the source code (tcmatch.cpp) and indeed, tcmatch.tbl is the mapping table. here's the part of codes that refers to the file tcmatch.tbl.

Code: Select all

void LoadPinYinTable() {
    if(TableCreated) return;
    TableCreated = 1;
    memset(&PinYinTable, 0, sizeof(PinYinTable));
    char cName[MAX_PATH];
    GetModuleFileNameA(hInst, cName, sizeof(cName) - 12);
    char* cPos = strrchr(cName, '\\');
    if(!cPos) return;
    cPos[0] = 0;
    strncat(cName, "\\tcmatch.tbl", MAX_PATH - 1);
    HANDLE File = CreateFileA(cName, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, 0);
    if(File != INVALID_HANDLE_VALUE) {
        int Filesize = GetFileSize(File, 0);
        DWORD bytesread;
        if(Filesize == sizeof(PinYinTable)) ReadFile(File, &PinYinTable, sizeof(PinYinTable), &bytesread, 0);
        CloseHandle(File);
    }

}
User avatar
John Doe
Бюрократ
Posts: 14174
Joined: Wed 27 Apr, 2005 20:42
Location: github.com/FarManagerLegacy
Has thanked: 80 times
Been thanked: 454 times
Contact:

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by John Doe »

pandaprada wrote: Wed 29 Jan, 2025 03:35 Maybe it can be done for Far as well?
The good news is that it's definitely possible. The challenge is that you'll have to implement it yourselves using Lua.

For example, here are a couple of possibilities:
  • Integrate it into a script like PanelFilter.
  • Create a menu that displays a list of files based on your custom filter logic.
We'd be happy to help you with the Lua scripting, but the filter logic itself might be complex for someone who's not familiar with Chinese.

I took a quick look at the C++ source code, and it seems like the implementation there isn't very straightforward either.

P.S.
The same approach can be used not only for PinYin (or Korean lead syllable) search, but for general-purpose fuzzy matching as well.
E.g. with one of the similarity search algorithms (Levenshtein distance was implemented in QuickSearch eXtended).
Edit: previously mentioned here viewtopic.php?p=156490#p156490
https://t.me/FarManager — Telegram чат
Yegor
Posts: 1420
Joined: Mon 04 Apr, 2005 13:41
Location: San Ramon, CA / Kharkov, UA
Has thanked: 45 times
Been thanked: 73 times

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by Yegor »

Here is the actual logic, but it looks like it searches by only the first 'letter' (like in your example 'z g') and it looks like it won't work if you search by 'zh gu'.

Code: Select all

    if(INI_use_pinyin && wcChineseKoreanChar == 0x3007) return (wcSearchChar == 'l');
    else if(INI_use_pinyin && wcChineseKoreanChar >= 0x4E00 && wcChineseKoreanChar <= 0x9FA5) { // Chinese character > search pattern char contains english PinYin
        LoadPinYinTable();
        WORD Dbl = PinYinTable[wcChineseKoreanChar - 0x4E00];
        WCHAR wcEnglishChar1 = (Dbl & 0x1F) - 1 + 'a';
        WCHAR wcEnglishChar2 = ((Dbl >> 5) & 0x1F) - 1 + 'a';
        WCHAR wcEnglishChar3 = ((Dbl >> 10) & 0x1F) - 1 + 'a';
        int result = (wcSearchChar == wcEnglishChar1 || wcSearchChar == wcEnglishChar2 || wcSearchChar == wcEnglishChar3);
        if(!result) {  // there are only 3 ideographs with more than 3 spellings:
            switch(wcChineseKoreanChar) {
            case 0x7AD3: // qian1 fen1 zhi1 yi1 gong1 sheng1
                result = (wcSearchChar == 'y' || wcSearchChar == 'g' || wcSearchChar == 's');
                break;
            case 0x7AD5:  // shi2  fen1 zhi1 yi1 gong1 sheng1
                result = (wcSearchChar == 'y' || wcSearchChar == 'g');
                break;
            case 0x7AE1:  // yi1  gong1 sheng1 bai3 bei4
                result = (wcSearchChar == 'b');
                break;
            }
        }
        return result;
Anyway, as @John Doe said it is feasible.
Last edited by Yegor on Thu 30 Jan, 2025 00:52, edited 1 time in total.
Мы не можем ждать милостей от Фара, взять их у него — наша задача! (C) Мичурин
pandaprada
Posts: 5
Joined: Wed 29 Jan, 2025 03:10

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by pandaprada »

John Doe wrote: Wed 29 Jan, 2025 21:04 Integrate it into a script like PanelFilter.
Yes, this is more intuitive for people already familiar with PanelFilter. Or maybe integrated with Alt key search and filtering, The QuickSearch Extended is integrated into the Alt key search and filtering in Total Commander

My problem is that I just don't know how to get started. For example, how do you load this tcmatch.tbl in lua codes? The lua scripting I've done so far in FAR has always been changes or modifications on Lua scripts you guys created.

I can certainly help with testing or trouble-shooting , though, since I know Chinese.
User avatar
John Doe
Бюрократ
Posts: 14174
Joined: Wed 27 Apr, 2005 20:42
Location: github.com/FarManagerLegacy
Has thanked: 80 times
Been thanked: 454 times
Contact:

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by John Doe »

pandaprada wrote: Thu 30 Jan, 2025 01:28 For example, how do you load this tcmatch.tbl in lua codes?

Code: Select all

local tcmatch_tbl = assert(io.open("tcmatch.tbl","rb"))
local bytes = tcmatch_tbl:read("*a")
assert(#bytes==20902*2)

local PinYinTable = {}
for i = 1, #bytes, 2 do
  local b1, b2 = string.byte(bytes, i, i+1)
  PinYinTable[19967+i] = b2 * 256 + b1
end
pandaprada wrote: Thu 30 Jan, 2025 01:28 My problem is that I just don't know how to get started.
I'd make so:
  1. Find most relevant functions in C++ source code.
  2. Use DeepSeek R1 to translate it into lua code
Then you need to think how to integrate it into Far.
pandaprada
Posts: 5
Joined: Wed 29 Jan, 2025 03:10

QuickSearch Extended plugin in Total Commander - can similar feature be implemented in FAR?

Post by pandaprada »

Thanks for the scode and the suggestion.

I'll give it a try.
Post Reply

Return to “Suggestions and Ideas”