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

2926: Fallback language in search function #3024

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

LeandraH
Copy link
Contributor

Short description

When your app is set to e.g. English and you look for a German term that you got a letter about like "Bürgergeld", you get zero results because we only search for English results. This PR adds a fallback language (the one that we translate from, i.e. German), so in this case, if there are no results in English, we then look in German.

The feedback screens have not been updated yet, that will be a separate ticket.

Proposed changes

  • Also load all possible search results in the fallback language
  • The search stays in the app language, if there are results. If there are no results, we search through all the possible results in the fallback language.

Side effects

  • The behavior when following a link from the fallback language is different in web and native:
    • In web, you open the link in the fallback language and are then in the app in the fallback language. If you use the browser history, you can go back to the selected language
    • In native, you open the link in the fallback language in the inAppBrowser. When you close that, you're back in the app in the selected language.

Testing

You can switch the app to English and search for "alleinerziehend".

Resolved issues

Partially fixes: #2926


@steffenkleinle
Copy link
Member

The feedback screens have not been updated yet, that will be a separate ticket.

Does this issue already exist? Could you please link it here? Thanks :)

Copy link
Member

@steffenkleinle steffenkleinle left a comment

Choose a reason for hiding this comment

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

Tested on firefox and android.

One thing I noticed: If the native app is still loading possible search results, the search bar is not shown. Even though this was already the case before, this change makes it more visible since there are two hooks loaded now at the same time. I also experienced it to disappear during typing alleinerziehend as probably the German results where not yet available. We can also create a separate issue for this though.

Comment on lines +51 to +54
const mainResults = useSearch(allPossibleResults, query)
const fallbackResults = useSearch(allPossibleFallbackResults, query)

const searchResults = mainResults?.length === 0 ? fallbackResults : mainResults
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Hmmm.... I think minisearch often returns search results even if there are no direct matches in the content. What is the reason to not always returning both (main results first, fallback concatenated afterwards)?

Comment on lines +19 to +23
const useMemoizeResults = (
categories?: CategoriesMapModel | null,
events?: EventModel[] | null,
pois?: PoiModel[] | null,
) => useMemo(() => formatPossibleSearchResults(categories, events, pois), [categories, events, pois])
Copy link
Member

Choose a reason for hiding this comment

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

💭 Do we really have to memoize this? Doesn't really look calculation intense at all 🙈

})
const fallbackResults = useSearch(allPossibleFallbackResults, query)

const results = mainResults?.length === 0 ? fallbackResults : mainResults
Copy link
Member

Choose a reason for hiding this comment

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

🤔 See native above

@@ -45,8 +46,16 @@ const SearchPage = ({ city, cityCode, languageCode, pathname }: CityRouteProps):
language: languageCode,
cmsApiBaseUrl,
})
const mainResults = useSearch(allPossibleResults, query)
Copy link
Member

Choose a reason for hiding this comment

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

🔧 I think something like contentResults or contentLanguageResults would be a little more speaking and explaining what is happening. Accordingly, fallbackLanguageResults might be better.

Comment on lines 35 to 38
const allPossibleResults = useMemo(
() => [...(categories?.toArray().filter(category => !category.isRoot()) || []), ...(events || []), ...(pois || [])],
[categories, events, pois],
() => formatPossibleSearchResults(categories.data, events.data, pois.data),
[categories.data, events.data, pois.data],
)
Copy link
Member

Choose a reason for hiding this comment

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

🔧 Same as for native

const { data: categories, ...categoriesReturn } = useLoadFromEndpoint(createCategoriesEndpoint, cmsApiBaseUrl, params)
const { data: events, ...eventsReturn } = useLoadFromEndpoint(createEventsEndpoint, cmsApiBaseUrl, params)
const { data: pois, ...poisReturn } = useLoadFromEndpoint(createPOIsEndpoint, cmsApiBaseUrl, params)
const categories = useLoadFromEndpoint(createCategoriesEndpoint, cmsApiBaseUrl, params)
Copy link
Member

Choose a reason for hiding this comment

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

💭 In theory we could perhaps add a parameter include root set to true as default or something to the categories endpoint so we don't have to filter it out after again?

Probably only really works well for web though, so not sure if its a good idea.

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.

Search function should have german fallback
2 participants