Repository navigation
Update Imgur title to prioritize Image block when searching with img - #38589
ntsekouras wants to merge 1 commit into
Conversation
|
Size Change: +3 B (0%) Total Size: 1.14 MB
ℹ️ View Unchanged
|
That's the tradeoff, yes. We could also think of a different related title for
That's a different issue and can be solved generically I think with this PR probably (🤔 ). The specific PR and issue here is harder to solve in a generic way, because when we search for |
|
I think I like the generic solution more. I will try to test it shortly 👍 |
I couldn't find a generic solution for the |
|
Thank you Nik for working on this! Having a generic way to tackle embeds would be helpful. I believe this would be very helpful: "Could we make a rule that the embed aliases are all automatically ranked lower than any other block?" --> I see this has been done in this PR: #38616 I do believe that we should not add Embed visible text to the blocks. As that would become noisy. Some brainstorming.... this has believe also been discussed before but I want to bring it up again. Should we begin to explore the slash inserter and how we can add more selectable information to it. Kinda like a version 2 of the slash inserter that is a bit more complex compared to what we see now. I got to think on that... One thing that is nice with the slash inserter is the simplicity of selecting blocks. Something might be taken away when one begins to add more complexity to this screen. |
|
These ranking problems are always difficult. I looked at this issue the other day and slept on it. What do you think of this instead: diff --git a/packages/block-editor/src/components/inserter/search-items.js b/packages/block-editor/src/components/inserter/search-items.js
index 265726643b..cdd5a200d8 100644
--- a/packages/block-editor/src/components/inserter/search-items.js
+++ b/packages/block-editor/src/components/inserter/search-items.js
@@ -140,7 +140,11 @@ export function getItemSearchRank( item, searchTerm, config = {} ) {
if ( normalizedSearchInput === normalizedTitle ) {
rank += 30;
} else if ( normalizedTitle.startsWith( normalizedSearchInput ) ) {
- rank += 20;
+ // Halve the score for embeds, which by their nature and number are
+ // more likely to match a search term and shadow a more adequate block.
+ // For instance, the Image block should score higher for "img" than the
+ // Imgur embed block.
+ rank += name === 'core/embed' ? 10 : 20;
} else {
const terms = [
name,Now as I type this, yet another approach could be the following: if title STARTS WITH search input:
- rank += 20
+ if name is 'core/embed':
+ if title FULLY MATCHES search input:
+ rank += 20
+ else
+ rank += 10
+ else:
+ rank += 20That is, for embeds the score is only a full 20 when the entire title is matched. For a partial match at position 0 we only increment by 10. |
These approaches wouldn't work well either I think, because by prioritizing the core blocks entirely by tinkering the rank for So for example if we start typing for a rather popular variation like For the record I don't like my approach either, but maybe a proper renaming would do it for the specific use case. I still cannot think of a good generic solution. |


Resolves: #37532
In the inserter results we use a generic algorithm for
rankingthem here and IMO this works well. It prioritizes the results based on the searched term and if we would sort them alphabetically, the results would be less relevant.There is a very specific request about searching for
img, which is a really common term forimageswhere theImgurembed variation is shown first instead of theImageblock. The above case happens because theimgis part of the block variation's title(imgur) and I can't think of any adjustment that could be generic and work well in all scenarios.So we could probably handle this on it's own. A specific approach for this is this PR, where I change the title of
imgurvariation toembed imgur.Testing instructions
imgImageblock should be shown on top of the results.