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

Add input-search event bus to plugins #8725

Closed
choyy opened this issue Jul 10, 2023 · 23 comments
Closed

Add input-search event bus to plugins #8725

choyy opened this issue Jul 10, 2023 · 23 comments
Assignees
Milestone

Comments

@choyy
Copy link

choyy commented Jul 10, 2023

In what scenarios do you need this feature?

正在写一个搜索的插件,我想在插件中能够切换ctrl p搜索面板的搜索方式,现在好像是做不到这一点
-447c939d0098e63c

Describe the optimal solution

增加切换搜索方式的接口

Describe the candidate solution

No response

Other information

No response

@88250
Copy link
Member

88250 commented Jul 10, 2023

你需要的是改变界面上的搜索方式设置还是调用内核搜索接口时改变搜索方式?

@choyy
Copy link
Author

choyy commented Jul 11, 2023

界面上的搜索方式,我想根据不同的搜索关键词设置不同的搜索

@choyy
Copy link
Author

choyy commented Jul 11, 2023

还有内核搜索接口吗,是指/api/query/sql吗

@88250
Copy link
Member

88250 commented Jul 11, 2023

界面搜索调用的内核接口,目前还没有正式发布,但是也可以用 /api/search/fullTextSearchBlock,参数可以看下源码或者在界面上 F12 看看。

@88250
Copy link
Member

88250 commented Jul 11, 2023

我先关闭了,如果还有问题请继续跟帖,谢谢 🙏

@88250 88250 closed this as completed Jul 11, 2023
@choyy
Copy link
Author

choyy commented Jul 11, 2023

如果用这个接口的话,还需要把搜索的结果更新到搜索面板中,那如果能增加 updateSearchResult 这个接口应该就能满足需求了
我现在插件的写法是给搜索框设置value,然后用事件触发搜索,基本可以用,就是缺一个搜索方式(0,1,2,3)的设置

@88250
Copy link
Member

88250 commented Jul 11, 2023

试下直接修改 DOM?

@choyy
Copy link
Author

choyy commented Jul 11, 2023

dom能修改搜索方式还是更新api的结果?

@88250
Copy link
Member

88250 commented Jul 11, 2023

应该可以修改搜索方式

@choyy
Copy link
Author

choyy commented Jul 11, 2023

我没找到这个,大概在哪里呢

@88250
Copy link
Member

88250 commented Jul 11, 2023

我意思是直接修改搜索框上的 DOM,相当于模拟用户选择的过程。

@choyy
Copy link
Author

choyy commented Jul 11, 2023

是这个b3-menu__item--selected吗?但修改这个是无效的
图片

@88250
Copy link
Member

88250 commented Jul 11, 2023

确实,我说的这个方法不太靠谱。

这个提供 API 感觉也不大对,你能再描述一下插件的使用场景吗,我们看看有没有其他方案。

@choyy
Copy link
Author

choyy commented Jul 11, 2023

现在弄的插件的作用是,将输入的搜索关键词扩展成SQL语句,然后用SQL去查询,现在如果用户手动选择SQL的查询方式的话,那么其实功能都已实现了,只不过这样只能用SQL搜索了
但现在想把其他搜索方式也加上,即根据搜索关键词选择不同的搜索方法,再执行搜索
现在有两种觉得可行的方法:

  1. 能够在插件中切换当前的搜索方式
  2. 能够在插件中执行查询的请求(包括指定查询方法、查询关键词,然后搜索界面显示,应该就是updateSearchResult 这个方法的功能吧)
    图片

@Vanessa219
Copy link
Member

没太看明白,是需要把四种搜索方式的结果合并到搜索列表中么?

@choyy
Copy link
Author

choyy commented Jul 11, 2023

不是,是想在插件中能够设置Ctrl + P搜索的当前搜索方式
图片

@Vanessa219
Copy link
Member

这个好像不能随便设置,如果是使用查询条件的话是无法修改的。是什么场景下需要修改它呢?

@choyy
Copy link
Author

choyy commented Jul 11, 2023

想用插件实现这种功能:根据搜索关键词,自动切换不同的搜索方法执行搜索

@Vanessa219
Copy link
Member

现在没有相关的接口,不知道你是如何监听输入的,如果可以监听到的话,如下使用即可修改。

config.method = 0;
config.page = 1;
inputEvent(element, config, undefined, edit, app);

@choyy
Copy link
Author

choyy commented Jul 11, 2023

监听输入我是监听keyup的
有办法设置config.method吗

@Vanessa219
Copy link
Member

是怎么监听的?

@choyy
Copy link
Author

choyy commented Jul 12, 2023

类似这样

$("#searchInput").onkeyup = function () {
    console.log("keyup")
}

@Vanessa219
Copy link
Member

那可能没办法,我加一个 input-search 的 eventBus 吧。

@Vanessa219 Vanessa219 changed the title 增加切换搜索方法的接口 Add input-search event bus to plugins Jul 12, 2023
@Vanessa219 Vanessa219 self-assigned this Jul 12, 2023
@Vanessa219 Vanessa219 added this to the 2.9.6 milestone Jul 12, 2023
@Vanessa219 Vanessa219 reopened this Jul 12, 2023
Vanessa219 added a commit to siyuan-note/petal that referenced this issue Jul 12, 2023
Vanessa219 added a commit that referenced this issue Jul 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants