EINDEX/logseq-copilot

Is it possible to add a fuzzy search function?

BongeZagh opened this issue · 7 comments

Is your feature request related to a problem? Please describe.
I found this plugin to be very helpful when I started collecting data from various websites. However, I encountered a problem when trying to take notes for a specific website. The plugin only matches the note with the exact URL, whereas I would like it to detect any notes I wrote on a certain URL.

Describe the solution you'd like
My suggestion would be to add a fuzzy search option that can be turned on whenever needed.

Describe alternatives you've considered
If it's not the priority, do you mind telling me which file can change the search mode? I can try to see if I can add this function.

EINDEX commented

Currently, I send the URL without the hash part to logseq to make this recall function.

If you want to extend this function, I suggest just sending one request to logseq and recalling everything you need. Otherwise, logseq needs to process a lot of requests in a short time.

And, there are 2 parts of code related to the recall function.

One is for popup searching:

useEffect(() => {
if (isLoading) return;
new Promise(async () => {
console.log('loading');
let queryOptions = { active: true, lastFocusedWindow: true };
let [tab] = await Browser.tabs.query(queryOptions);
setIsLoading(true);
if (!tab.url) return;
const url = removeUrlHash(tab.url);
const result = await client.blockSearch(url);
if (result.status !== 200) return;
setLogseqSearchResult(result.response!);
mountOpenPageMethod();
});
});

Another is for badge count number:

const badgeSearch = async (url: string | undefined, tabId: number) => {
if (!url) return;
const cleanUrl = removeUrlHash(url);
const searchRes = await logseqClient.blockSearch(cleanUrl);
const resultCount = searchRes.count ? searchRes.count!.toString() : '';
await setExtensionBadge(resultCount, tabId);
};

EINDEX commented

And before putting effort into the development work.

I want to know the rules or patterns. what will be in the search result, and what should be excluded.

Could you give an example of fuzzy searching?

Hi EINDEX, thank you for your reply!

Since I primarily use chatGPT for programming, I will do my best to describe it.

Here are two sample websites:
14:42 [[quick capture]]: About us - Wiren Board I removed the hash part it seems copilot can't search notes on my side
14:40 [[quick capture]]: Technologies, equipment and materials for electronic manufacturing sector

My thought will be no matter which page of the site we click, the plugin can always detect my notes under the website. Then we don't have to read the website again.

I gave my question to ChatGPT this is what I got, I have not idea how to test it yet 😂

  useEffect(() => {
    if (isLoading) return;

    new Promise(async () => {
      console.log('loading');
      let queryOptions = { active: true, lastFocusedWindow: true };
      let [tab] = await Browser.tabs.query(queryOptions);
      setIsLoading(true);
      if (!tab.url) return;
      const url = removeUrlHash(tab.url);

      // Format URL to match wildcard
      const formattedUrl = url.replace(/\/.+/, ''); // Matching and removing everything after the last slash using a regular expression

      // Format URL to match regular expression
      const regexFormat = `^${formattedUrl.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')}`; // Escaping special characters

      const result = await client.blockSearch(regexFormat);
      if (result.status !== 200) return;
      setLogseqSearchResult(result.response!);
      mountOpenPageMethod();
    });
  });
EINDEX commented

Oh, Maybe I got your idea, you want to have all the notes related to one website.

For example:

When I am on the https://wirenboard.com/en/pages/about/ page. I can see the note for the https://wirenboard.com/en/catalog/kontrollery/ page.

Is that right?

Yes!! You understand it correctly.

EINDEX commented

released in 1.13.0, it will be available at edge & chrome store soon.

That was Awesome!! Thanks a lot!!!!!🥳