Skip to content

Sort entries by primary reading - #1497

Merged
MarvNC merged 15 commits into
yomidevs:masterfrom
khaitruong922:search-reading
Oct 29, 2024
Merged

MarvNC merged 15 commits into
yomidevs:masterfrom
khaitruong922:search-reading

Conversation

@khaitruong922

@khaitruong922 khaitruong922 commented Oct 17, 2024

Copy link
Copy Markdown
  • Add primary_reading param.
  • When click on gloss link, set furigana as primary_reading if exists.
  • Entries with reading matches primary_reading will be sorted to top.

Works correctly for Jitendex gloss link format. Don't know if there are any kind of dictionary format which will break this feature, since the reading is depended on the classes naming.

@khaitruong922 khaitruong922 changed the title Search term by exact reading when clicking on gloss link Search term by exact reading when clicking on gloss link with furigana Oct 17, 2024
@khaitruong922
khaitruong922 marked this pull request as ready for review October 17, 2024 14:13
@khaitruong922
khaitruong922 requested review from a team as code owners October 17, 2024 14:13
@khaitruong922 khaitruong922 changed the title Search term by exact reading when clicking on gloss link with furigana Sort term by exact reading when clicking on gloss link with furigana Oct 17, 2024
@codspeed

codspeed Bot commented Oct 17, 2024

Copy link
Copy Markdown

CodSpeed Performance Report

Merging #1497 will not alter performance

Comparing khaitruong922:search-reading (521cb1e) with master (9c5f824)

Summary

✅ 2 untouched benchmarks

🆕 1 new benchmarks
⁉️ 1 (👁 1) dropped benchmarks

Benchmarks breakdown

Benchmark master khaitruong922:search-reading Change
👁 Translator.prototype.findTerms - (n=43) 154.8 ms N/A N/A
🆕 Translator.prototype.findTerms - (n=45) N/A 157.8 ms N/A

@khaitruong922

khaitruong922 commented Oct 17, 2024

Copy link
Copy Markdown
Author

Ready for review

  • Extract furigana from gloss link and add primary_reading search param

image
image

  • Sort entries which match primary_reading to top

image

image

@khaitruong922 khaitruong922 changed the title Sort term by exact reading when clicking on gloss link with furigana Sort term by primary reading when clicking on gloss link with furigana Oct 17, 2024
@khaitruong922 khaitruong922 changed the title Sort term by primary reading when clicking on gloss link with furigana Sort entries by primary reading when clicking on gloss link with furigana Oct 17, 2024
@stephenmk

Copy link
Copy Markdown

Thank you for working on this. It looks good.

Works correctly for Jitendex gloss link format. Don't know if there are any kind of dictionary format which will break this feature, since the reading is depended on the classes naming.

I don't like this approach. I think it would be better to rely on the dictionary data to specify the ?primary_reading= parameter. I don't think it's a good idea to try to parse the primary reading from the furigana. This increases the code complexity and could lead to unexpected behavior. It's possible that someone may want to manually specify a ?primary_reading= parameter that is not equivalent to the furigana readings within the link.

In other words, I would remove this block of code:

if (internal) {
let query = '';
if (href.length > 1) {
let hasFurigana = false;
let reading = '';
for (const childNode of text.childNodes) {
if (childNode instanceof HTMLElement) {
const furigana = childNode.querySelector('.gloss-sc-rt')?.textContent;
if (furigana && furigana.length > 0) {
reading += furigana;
hasFurigana = true;
}
} else {
reading += childNode.textContent ?? '';
}
}
query = href;
if (reading.length > 0 && hasFurigana) {
query += `&primary_reading=${reading}`;
}
}
href = `${location.protocol}//${location.host}/search.html${query}`;
}

@Kuuuube

Kuuuube commented Oct 18, 2024

Copy link
Copy Markdown
Member

I think it would be better to rely on the dictionary data to specify the ?primary_reading= parameter.

Agreed.

@khaitruong922

Copy link
Copy Markdown
Author

The only place that user could specify the primary_reading is the search page, by modifying the url. I don't think this is the main use case, and no user will be aware of it.

The main purpose of this PR is to extract the reading from furigana, then sort the terms with that reading on top. For example, suppose that my dictionary has 縁 (えん) above 縁 (ふち). When I click on a word link 縁 (ふち), the entry 縁 (ふち) should be above 縁 (えん).

As far as I know, only Jitendex has furigana for word link. I agree that the implementation is quite fragile, we can find better ways to handle this.

@khaitruong922

Copy link
Copy Markdown
Author

I also agree with having the primary_reading specified inside the href field of Jitendex, then we can remove the extract furigana code.

@khaitruong922 khaitruong922 changed the title Sort entries by primary reading when clicking on gloss link with furigana Sort entries by primary reading Oct 18, 2024
@stephenmk

Copy link
Copy Markdown

I just published a new version of Jitendex that includes the primary_reading parameter in hyperlinks.

@khaitruong922

Copy link
Copy Markdown
Author

Tested with new version of Jitendex. Works great!

My.Video.mp4

@MarvNC MarvNC left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so much work needed to just pass variables around
StampNyaa_12858561_雪子

Comment thread test/utilities/translator.js
@MarvNC
MarvNC added this pull request to the merge queue Oct 29, 2024
@MarvNC MarvNC added the kind/enhancement The issue or PR is a new feature or request label Oct 29, 2024
Merged via the queue into yomidevs:master with commit 0fd7009 Oct 29, 2024
@khaitruong922
khaitruong922 deleted the search-reading branch November 5, 2024 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/enhancement The issue or PR is a new feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants