Repository navigation
feat(medcat-trainer): Solr backed full text search of clinical notes - #634
Open
tomolopolis wants to merge 7 commits into
Open
tomolopolis wants to merge 7 commits into
tomolopolis wants to merge 7 commits into
Conversation
… API Co-authored-by: tomolopolis <tomolopolis@users.noreply.github.com>
…view Co-authored-by: tomolopolis <tomolopolis@users.noreply.github.com>
… add Solr backed document search endpoint Co-authored-by: tomolopolis <tomolopolis@users.noreply.github.com>
…t search Co-authored-by: tomolopolis <tomolopolis@users.noreply.github.com>
Co-authored-by: tomolopolis <tomolopolis@users.noreply.github.com>
… pane Co-authored-by: tomolopolis <tomolopolis@users.noreply.github.com>
tomolopolis
marked this pull request as ready for review
October 19, 2026 09:36
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The Clinical Notes sidebar search on the annotate entities page could only prefix-match note names, and only among docs already loaded in the browser. This adds a Text search mode backed by a Solr full text index of each dataset's documents, and makes the Clinical Notes panel resizable.
Indexing (
api/document_search.py)DOCUMENT_SEARCH_COLLECTION, defaultmedcattrainer_documents) with fieldsdataset_id,doc_id,name, andtext(text_general). The collection and fields are created on first use.Datasetpost_savesignal (which covers the admin upload, thecreate-datasetAPI, and project import) schedules theindex_dataset_taskbackground task once the upload commits. The task delete-by-queries the dataset's docs and re-adds them in batches of 500, so re-uploads replace rather than duplicate.remove_dataset_task.DOCUMENT_SEARCH_INDEX_ENABLED=0turns indexing off.collections_availableexcludes the document collection, so it never shows up as a concept index.Search (
GET /api/search-documents/?dataset=&text=&page=)text(case-insensitive via the analyzer), filtered to the dataset, 50 results per page. Results use the samecount/next/resultsshape as DRF and include full document objects.highlightsegments from Solr's unified highlighter. They are split on control-character markers server-side, so the frontend never renders HTML.icontainsmatch (search_backend: "db") if Solr is unreachable or the dataset isn't fully indexed yet, i.e. the Solr count differs from the DB count.Frontend
DocumentSummary.vue: Name / Text toggle under the search box. Name mode is unchanged. Text mode calls/api/search-documents/(300ms debounce, stale responses ignored), shows a match count, pages with "More Results", and renders the Solr highlight snippet. Without a Solr highlight (DB fallback), it builds a snippet client-side.<pane>of the samesplitpanesas the clinical text and the ConceptSummary sidebar (15% default, 10% minimum). The fixed 175px width is replaced with a flex column, so the note cards fill the pane and the list scrolls under the title and search box.beforeDestroyhook (never fires in Vue 3) withbeforeUnmount.The earlier
text__icontains/name__icontainsfilters on/api/documents/are kept.resizable-clinical-notes-pane.mp4
Testing
test_document_search.pycovers indexing requests and batching, search ordering, highlights, pagination, both fallbacks, validation, auth, and the upload/delete signals scheduling tasks on commit.LiveSolrDocumentSearchTests(opt-in withMCT_SOLR_LIVE_TESTS=1) passes against Solr 8.11 in cloud mode (-c, as in docker-compose).manage.py process_tasksworker; it indexed an uploaded dataset intomedcattrainer_documents.To show artifacts inline, enable in settings.