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

Fix 1164 wikivoyage sorting #19858

Merged
merged 5 commits into from
May 16, 2024
Merged

Fix 1164 wikivoyage sorting #19858

merged 5 commits into from
May 16, 2024

Conversation

Dima-1
Copy link
Contributor

@Dima-1 Dima-1 commented May 14, 2024

No description provided.

public void sortSearchResults(@NonNull List<WikivoyageSearchResult> results, String searchQuery) {
String searchQueryLC = searchQuery.toLowerCase();
results.sort((sr1, sr2) -> {
int sr1Comparison = collator.compare(sr1.getArticleTitle(), searchQuery);
Copy link
Member

Choose a reason for hiding this comment

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

getArticleTitle() we can store in local variables

} else {
String title1LC = sr1.getArticleTitle().toLowerCase();
String title2LC = sr2.getArticleTitle().toLowerCase();
if (title1LC.contains(searchQueryLC) && !title2LC.contains(searchQueryLC)) {
Copy link
Member

Choose a reason for hiding this comment

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

result from contains also store in boolean variables

int sr2Comparison = collator.compare(sr2.getArticleTitle(), searchQuery);

if (sr1Comparison == 0 && sr2Comparison != 0) {
return -1;
Copy link
Member

Choose a reason for hiding this comment

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

comparator should always return Integer.compare or String.compare methods to avoid in consistency, this comparator should be rewritten without ifs !=, check Search results comparator

case CONTAINS_OF_TITLE:
if (sr1Comparison != 0 || sr2Comparison != 0) {
if (sr1Comparison || sr2Comparison) {
Copy link
Member

Choose a reason for hiding this comment

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

not correct compare method

@Dima-1 Dima-1 force-pushed the fix-1164-wikivoyage-sorting branch from 0fed150 to 4118fd3 Compare May 16, 2024 12:46
@vshcherb vshcherb merged commit b8324fd into master May 16, 2024
3 checks passed
@Chumva Chumva deleted the fix-1164-wikivoyage-sorting branch May 19, 2024 09:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants