Return `search_level` in content node search responses
Overview
The Learn search page will show different sections depending on how a search ran: with a language model, with vector search, or with keyword search only. Currently, the content node search response does not say which of these ran. This task adds a search_level field to the response of every search request, and makes Learn read it. On a device without models, the value is always "keyword", and search looks and behaves exactly as it does now.
This is the first task in the breakdown of #15567, and the later tasks build on this field.
Complexity: Low
Target branch: develop
Context
Search in Learn uses the content node list endpoint. The learner's text goes in search for autocomplete, or in question for a full search. Currently, both run the same keyword search on titles and descriptions.
The paginated response, built by OptionalContentNodePagination, has three fields: more, results and labels (get_paginated_response). Its API schema lists the same three (get_paginated_response_schema). The same response class serves every paginated content node list, including browsing a folder, which has none of the search query parameters (search, question and keywords).
Search on a remote device, through Explore Libraries, works in three steps:
- Learn sends the search to the learner's device.
- The learner's device passes the request on to the remote device's public endpoint,
PublicContentNodeViewSet. That endpoint builds its response withPublicContentNodePagination, a subclass ofOptionalContentNodePagination. - The learner's device returns the remote device's response to Learn unchanged.
So for a remote search, the remote device decides whether Learn receives a search_level. A device older than 0.20.0 sends none. Those devices also do not know the search and question parameters, so the learner's device sends keywords to them instead (contentnode_previously_renamed_params).
Learn reads the response in useBaseSearch.
"The front-end contract" in #15567 defines search_level and its three values.
The Change
- Every content node search response includes
search_level. A request is a search whensearch,questionorkeywordshas a non-empty value, for exampleGET /api/content/contentnode/?search=fractions. These are the three query parameters that the content node search filter reads. - With no language model and no vector search set up,
search_levelis always"keyword". Later tasks (#15731, #15743) set"lm"and"vector". - The API schema lists
search_levelwith its three values, and states that it appears only for searches. - The public endpoint,
PublicContentNodeViewSet, returnssearch_levelin the same way. useBaseSearchexposes thesearch_levelof the search that is showing. A response without one, for example from a remote device without this change, counts as"keyword".- Nothing visible changes in Learn. Later tasks, starting with #15744, use the value to show or hide sections.
How to Get There
- Start the dev server, and import at least one channel.
- Sign in as a learner, and open the Library page in Learn.
- Open the browser's developer tools on the Network tab.
- Type in the search bar, then press Enter. The autocomplete request carries
search, and the full search request carriesquestion. Both responses show"search_level": "keyword", next toresults,moreandlabels. - Open a channel and browse a folder without searching. The response for that folder has no
search_level.
To check a remote search, use Explore Libraries to search a second Kolibri device. A device that runs this change sends search_level. An older one sends none, and Learn treats it as "keyword".
Out of Scope
- Setting
"lm"or"vector". The pipeline adapter interface (#15731) sets"lm", and the vector search path (#15743) sets"vector". - Any visible change in Learn. The results page (#15744) shows or hides sections.
- The search status request (#15738).
- Changes to how search matches resources, including the keyword search itself.
- Searches that use a remote device's language model. This is still an open question in #15567, under "Search on another device".
Acceptance Criteria
General
- [ ]
?search=fractions,?question=fractionsand?keywords=fractionseach return"search_level": "keyword". - [ ] A request without these query parameters, or with an empty value such as
?search=, returns nosearch_level. - [ ] The public endpoint behaves in the same way.
- [ ] The API schema documents
search_level, its three values, and that it appears only on searches. - [ ]
useBaseSearchgives"keyword"when a search response has nosearch_level, and no value when no search is showing. - [ ] Search results, labels and paging do not change.
Testing
- [ ] Backend tests cover each General criterion, for the local and the public endpoint.
- [ ] Frontend tests cover a response with
search_level, a response without it, and no search showing.
Testing
This task has no visible result of its own, so QA does not test it. The reviewer checks the automated tests and the API responses, following "How to Get There".
Existing tests to extend:
kolibri/core/content/test/test_content_app.pyandkolibri/core/content/test/test_search.py, for content node searchkolibri/core/content/test/test_public_api.py, for the public endpointpackages/kolibri-common/composables/__tests__/useBaseSearch.spec.js, for Learn
Run them with:
pytest kolibri/core/content/test/test_content_app.py kolibri/core/content/test/test_search.py kolibri/core/content/test/test_public_api.py
pnpm test-jest packages/kolibri-common/composables/__tests__/useBaseSearch.spec.js
AI usage
I used Claude Code to draft this issue from my breakdown of #15567. I made the scope decisions, and I reviewed and edited the draft.
assign
Hi! 👋
Thanks so much for your interest! This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues. If there are no unassigned 'help wanted' issues available, please wait until new ones are added.
We really appreciate your willingness to help. 😊
Are you preparing for Google Summer of Code? See our GSoC guidelines.
Plan: Paginated content node search responses carry search_level (always "keyword" for now), and useBaseSearch exposes it as searchLevel.
- [ ] Backend —
search_levelon paginated search responses and in the schema - [ ] Frontend —
useBaseSearchexposessearchLevel - [ ] Self-review the produced code
Assumptions — the issue did not settle these; say so if one is wrong.
- A search without
max_resultsstays a bare list with nosearch_level, though the criterion writes?search=fractionswithout it: the issue places the field "next toresults,moreandlabels", andtest_content_app.py:1977-2052asserts bare lists for unpaginated searches. If wrong, those responses become objects and every bare-list caller and test breaks. - The
kolibri/clientmock can answerContentNodeResource.listinsideuseBaseSearch.spec.jsonce the reallistis restored; not run, this session had nonode_modules. If wrong, thesearchLeveltests fall back to the file'sContentNodeResource.list.mockReturnValue, and the PR body says so.
Written by rtibblesbot, an LLM-based coding agent.
Decided without asking; a reply here changes it.
- Pre-upgrade search ETags stay as they are: no cache-key change and no follow-up issue.
- What happens: the ETag is the content cache key alone (
kolibri/core/content/utils/cache.py:43) and no 0.20 upgrade hook bumps it, so a browser copy cached before the upgrade revalidates to 304 and keeps its body withoutsearch_leveluntil content changes.test_contentnode_etagpasses on the branch. - No user is affected: the issue defines a response without
search_levelas"keyword", the only level this branch sends, anduseBaseSearchapplies that default. The cached results came from keyword search, so the label is true. - "The branch exposes it" pointed to fixing here. "Edge case with no affected user" and "a remedy nothing depends on" outweighed it: the fix changes ETags on the channel metadata, content node tree and import metadata endpoints, and on ETags proxied from peers, for no visible difference.
- Reviewers reading raw responses use a new search term or disable the browser cache; the PR body says so.
- The content-only ETag starts to matter when a search response can change without a content change; a note saying so is drafted for #15731.
- What happens: the ETag is the content cache key alone (
Written by rtibblesbot, an LLM-based coding agent.