jackyzha0 / quartz

🌱 a fast, batteries-included static-site generator that transforms Markdown content into fully functional websites
https://quartz.jzhao.xyz
MIT License
7.31k stars 2.52k forks source link

Keyword search #1016

Open migueltorrescosta opened 8 months ago

migueltorrescosta commented 8 months ago

Is your feature request related to a problem? Please describe. Browser keyword searches are a productivity boost. The current search implementation does not support it.

Describe the solution you'd like We should be able to add a Keyword search option. I believe the requirement for this to happen is for there to be a URL that accepts a search query. For instance, I can add a keyword search for the following because there's an endpoint that takes the search parameter:

Describe alternatives you've considered I don't think there's another way of making the search of a published vault a "one click" solution. It would be awesome to type in the browser "quartz callout" and immediately see the quartz note on how callouts can be used.

Additional context This feature would be a massive productivity boost :rocket:

saberzero1 commented 7 months ago

Hey @migueltorrescosta,

I was thinking about a possible implementation. Is the default search plugin sufficient for this purpose?

Let's say for example I want to search the Quartz documentation for the word hello, would something like https://quartz.jzhao.xyz?q=hello be sufficient if it resulted in something approximating below?

image

Another option could be navigating to the first result in the search. (https://quartz.jzhao.xyz/advanced/creating-components in the above example).

Yet another option could be to create a dedicated search page. Something similar to the overlay when searching manually, but as its own page. Possibly with extended functionality, like filtering search results further. This page could then be accessed through a search query in the URL (and possibly through other means as well).

What are your thoughts on this?

migueltorrescosta commented 7 months ago

Any of them would be a great improvement tbh. I would probably prefer the 2nd option, redirecting to the 1st result, since:

Do you think another option could be better?

saberzero1 commented 7 months ago

I think the second option is the best option if there is a good match between the search algorithm and the search query. Basically it works very well if you have a relatively specific query or a query that has very few results.

If you have a more generic query, or a query that has many results, the effectiveness is greatly diminished, as you will most likely need to perform a second, manual search afterwards.

I feel more for something like implementing https://github.com/jackyzha0/quartz/issues/818

I feel like most of the awkwardness when navigation is not necessary a lack of keyword search, but more so the inability to easily switch between opening search (which is now a mouse action) and typing the search query (which is a keyboard action).

Let's say for example, if you were to press the //? key, if that opened the search overlay. Possibly with more keyboard options to select the desired search result, would that be a sufficient solution for your issue?

EDIT: basically, I feel like your request (keyword search) is not necessarily the best solution to your problem (quick site navigation). Please correct me if I misunderstood your goal.

migueltorrescosta commented 7 months ago

The navigation from #818 is great, and it allows the website to emulate the feel of Obsidian locally. It still requires a page load before I can go to any page. Since I have a maps keyword for Google Maps, I can type maps London and immediately be shown a map of London. An improved website navigation doesn't provide that same smooth UI. In this setup, we are comparing the friction of:

  1. Opening https://quartz.jzhao.xyz/, waiting for the page load, going for the search bar, typing callout and getting the new page
  2. Typing quartz callout to see the callouts page ( or the search's best guess at it )

I mention this as I am a very pro-active keyword user, having shortcuts for Google, Youtube, Reddit, Google Maps, Wikipedia, ... ( I think I have some 50 keywords :sweat_smile: ). With this usage:

  1. A keyword option does provide less friction, as there is no page that needs to be rendered before I can search for a specific result
  2. If my particular usage is too niche, I understand it not being a priority compared to #818 , however I would keep this ticket opened until a keyword search is indeed possible / prioritized
saberzero1 commented 7 months ago

Thanks for the clarification.

I'll look further into this issue tomorrow.

I'll keep you posted.

saberzero1 commented 7 months ago

Hey,

I have looked into a few options.

The most obvious is to use the URL API. This is basically the technology behind retrieving the ?q=something after an URL.

So retrieving the search term(s) is not hard.

The easiest thing to do would be to implement a function that grabs the search term(s) from the URL and passes them the same function that searches your site when you press the search component on your Quartz website, then immediately "clicks" the first result to navigate to said page.

This is however not very elegant. I haven't found an elegant solution yet. One that doesn't require a full page load beforehand. The complexity is mostly that the search component retrieves the search options asynchronously.

I suspect this keyword search functionality is not something we will likely implement in Quartz anytime soon. Therefore, is a "form over function" solution of using a keyword query to go to the first result (albeit after a page load) acceptable for your use case? If it is, I could write a small implementation that checks for keyword queries, and if they are present executes the navigation.

migueltorrescosta commented 7 months ago

I could write a small implementation that checks for keyword queries, and if they are present executes the navigation.

I don't understand what this solution looks like :sweat_smile: My best guess is that you can implement a function that:

  1. Checks the URL for ?q=<something>
  2. If the URL has that present, it redirects to the 1st result retrieved by the search component

If my interpretation is correct, this sounds awesome. If not, I don't really see what the solution is.