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
Allow exact match search via double quotes #1772
Comments
Do you have data to back that up? I've never seen someone using quote syntax in Google Analytics for the official docs.
The regex is already pretty complicated: mkdocs-material/src/assets/javascripts/integrations/search/transform/index.ts Lines 50 to 55 in e02608f
I'm not sure whether |
In the past two years, I've had 701 site searches with quotes, 0 searches with the + operator. Note that the + operator is deprecated in Google Search, so people familiar with Google's syntax will probably avoid it.
Well yes, that is a drawback. We can't exactly replicate Google's search behavior since lunr doesn't support specifying a word order. So BTW, I played around with our search and was able to improve the results by boosting the first word: |
I guess we could implement quotes when we have a spec that is complete. If you can draft something up as part of this issue, we might consider implementing it. Some questions to be answered by this specification:
As a rule of thumb, we should probably stay as close as possible to Google. Please specify the respective transforms for all cases. Also, maybe there're some more edge cases I haven't thought of. |
I am not a search expert, but I would like to see this feature implemented as well, so here are my inputs on the subject.
From what I'm seeing in the Google specification, unmatched quotes would be considered as an incomplete query. You may have to disable look ahead search when the query starts with a double quote.
Modifiers in quotes are taken as literal characters and not interpreted as modifiers.
Single quotes are their own character. They may appear in SQL commands, and therefore do not encapsulate the search query. |
I think unmatched quotes are simply stripped from the query. So More observations via Google: Search for Some additional information here: http://www.googleguide.com/quoted_phrases.html Tidbits:
So let's support it :-)
So disable lunr's pipeline for quoted search terms? Might be difficult to implement? |
Okay, so I guess we have to check how to escape modifiers, so they're treated as literals in queries. The stemmer is disabled for most languages, as most people don't like it and wonder why their queries don't return any results. It also doesn't work well with the type-ahead experience. Thus, there's only a For this reason, I see no possibility to disable the On a second note, there's another problem with some of those modifiers, as |
Okay, so I suggest the following proposal:
It's not trivial to implement, though. I guess we have to depart from the simple regular expression based transform and have to implement a rather decent parser. Should be possible in a few dozen lines. [1] See the end of the paragraph on |
Thanks! Bullets 1) and 3) are fine for me. 2) looks a little overengineered. I assume the number of users that want to both use exact search and search for control characters is too low to justify the development effort. So we could leave that out, and |
Yes, 2. is probably not much of a use case. |
Implemented in #1778. Feedback appreciated so we can push this out quickly. mkdocs-material/src/assets/javascripts/integrations/search/transform/index.ts Lines 66 to 77 in 83bba6b
Also, see the comments in the doc block of the |
Great, thanks! There's no global modifier in E.g. We haven't discussed that - I think it's also not much of a use case, so we can leave it as it is. Just wanted to mention. |
Thanks for pointing it out, we should add it! |
Okay, if you change it anyway, you can also fix some small typos in the comment:
and -> an
expected -> expect
asterisik -> asterisk |
All settled in 759f2b9. |
Looks good! If there's a space after the first quote, the query will be transformed like this:
At first, I thought this might be a problem, but lunr seems to handle that and remove orphan control characters. So no problem. |
Released as part of 5.4.0 |
Why isn't this working for me? I have tried both of these:
I searched for EDIT: Oh, it seems to have to do with some word-count limit in the search, but it also seems bugged in other ways. If I search for |
I checked that...
Description
Material supports lunr's search syntax. With that syntax, to perform an exact match search (logical AND search), all terms must be prefixed with a plus (+):
+my +search +term
This is technically fine, but not intuitive. I assume most users try to perform an exact match search by using double quotes, because that's the way it's usually done in Google:
"my search term"
It would be nice if Material supported this as an additional method to perform an exact match search.
Adding some RegEx magic to
defaultTransform()
should do the trick.Use Cases
Users that don't know how to do a logical AND search would have a much greater chance to find out by trial and error if double quotes were supported.
The text was updated successfully, but these errors were encountered: