🇬🇧 medDiscover: a healthcare search in Drupal that knows when not to answer

I typed “What is prediabetes?” into the search box and waited about ten seconds. What came back was four short sentences, each ending in a [1], and a single source underneath: the MedlinePlus page on Prediabetes from the National Library of Medicine. One click and I was reading the original.
Then I typed “knee pain when walking”. No answer this time. Instead I got five ranked health topics, filters on the left, and under the first result a Next steps box that explained why each link was there.
Same box, two very different responses. Deciding which one a visitor gets, and what happens when neither is safe, is the real story of medDiscover, a healthcare search proof of concept I built in Drupal. The code is public on GitHub.
Watch it first
This short walkthrough shows the search, the cited answer and the four layers I describe below.
Prefer Loom? The same walkthrough is on Loom.
The architecture in one picture
I organized the project around four layers. Each one answers a different question, and I can inspect each one without the others.

Everything runs in one Drupal 11 site: PostgreSQL 17 with pgvector for semantic retrieval, Apache Solr 9 through Search API for keyword retrieval, and local Ollama models for embeddings (nomic-embed-text) and answers (gemma3:12b). There is no separate microservice and no hosted AI API.
Experience: one box, two kinds of response
The visitor sees one search box. Behind it are two decisions: which kind of response to give, and when to refuse.
When the site shows ranked topics and when it shows a cited answer
Not every query deserves a generated answer. “Knee pain when walking” is a topic lookup: the visitor wants pages to read. “What is prediabetes?” is a question: a short explanation with a source is more useful than a list.
So the homepage looks at the shape of the query before choosing a path:
- A question (it ends in
?, or starts with words like what, how, can I, does) goes to Ask, which writes a cited answer. - Anything else goes to hybrid search, which returns ranked topics.
- Urgent wording always takes the Ask path, because that is where the fixed safety message lives, even when the query is terse.

This is deliberately a simple, readable rule rather than a classifier. When it routes a query the wrong way, I can see exactly why, and the visitor can still switch between the answer and the topics with the tabs on the results page.
An answer that is allowed to say no
Ask is where most of the engineering went, because a health answer has to be checkable and has to fail safely. The pipeline runs in a fixed order:
- Urgency first. A detector looks for crisis and emergency wording before anything else. A match returns a fixed safety message and never calls the model.
- Retrieve. Semantic retrieval picks the top three topics. If nothing passes the similarity threshold, the answer is an abstention and the model is never called.
- Generate with a constrained schema. The model must return JSON where every statement lists its sources, and the
sourcesfield is an enum of the labels I supplied. The model cannot even express a citation to a source it was not given. - Verify. Drupal drops statements whose words do not overlap enough with the cited source, withholds anything that looks like a diagnosis, a dose, a phone number or a link, and treats
answerable: falseas an abstention. - Fall back gracefully. If generation fails or nothing survives verification, the visitor still gets the closest topics.

I chose a local model on purpose. Health questions are sensitive, and with Ollama the question never leaves the machine. I compared four local models on synthetic probes and then on a 34-case evaluation set. gemma3:12b with semantic retrieval passed 32 of 34 cases, at a median of about 13 seconds per answer. A faster model (qwen3:8b) was one config change away but declined fewer diagnosis-seeking questions.
The evaluation also caught a real gap: “My child swallowed pills and is not waking up” was not detected as urgent in the first run. I added the missing patterns and a contract test, and reported it as a post-evaluation change rather than quietly re-running the numbers.
The limits are visible in the interface. Word overlap catches off-topic additions, not a subtle change in meaning, and pattern-based safety rules will miss some phrasings. Every answer carries a notice that it is generated, can be wrong and is not medical advice.
Data: why MedlinePlus, and two ways to search it
Why I chose MedlinePlus
Before writing a line of Drupal, I profiled the full MedlinePlus health topics XML. It has 2,033 topics, 1,017 in English, and it is far richer than a list of articles:
- Aliases. “Also called” and “see reference” terms, so “HbA1c” can resolve to the A1C topic.
- Controlled vocabulary. MeSH headings on 1,015 of the 1,017 English topics.
- Curated relationships. 3,316 related-topic links in English, plus explicit English–Spanish mappings.
- Resources with context. Every topic lists external resources grouped by category, such as Start Here, Patient Handouts, Clinical Trials or Find an Expert.
That structure is what made the other three layers possible. Aliases feed keyword search, the curated text feeds the answers, and the resource categories feed the next steps. It is also written for patients rather than clinicians, which is the right register for a public search.
The profiling also told me what the data cannot do. It links out to directories but has no structured provider or hospital listings, and trial links are search links, not eligibility data. So I ruled out “find a doctor near me” and “am I eligible for this trial” from the start, rather than discovering it halfway through.
For the proof of concept I selected 24 English topics around knee and back pain, diabetes and A1C, headaches, allergies and clinical trials. Together they carry 882 resource assignments and 744 unique resource URLs.
Two retrieval paths, fused by rank
Keyword search and semantic search fail in different ways. Solr is excellent when someone knows the term: on exact terminology it got the right topic first every time. It struggles with paraphrases, where it put the right topic first in only 45% of cases. Semantic search with pgvector handled paraphrases far better (91%) and correctly returned nothing for all 10 unrelated questions.
Hybrid search combines the two with Reciprocal Rank Fusion: each list contributes 1 / (60 + rank) for every topic it returns. That lets me merge a Solr score and a cosine similarity without pretending they are on the same scale, and if one engine is down, results continue from the other with a notice.
I kept vector search exact rather than approximate. On 24 topics it is fast enough, and exact results are easier to evaluate. It is a choice I would revisit with the full corpus.
Activation: next steps an editor can explain
After reading about a topic, a visitor usually wants to do something: read a patient handout, look at research, find a specialist. The Next steps box chooses those actions from the resources MedlinePlus already lists for that topic, using rules configured in Drupal’s admin UI. A query mentioning trials can prioritize a trials action when the topic has one.
Every link says why it appeared (“MedlinePlus lists 2 Find an Expert resources for Walking Problems”). An editor can read the rule, change it, and predict the result. These are starting points for exploration, not recommendations.
Optimization: measure without storing health questions
Search queries about health reveal a lot about a person, so the analytics are aggregate-only: search volume, zero-result rate, latency per stage and clicks on next steps. No query text, topic IDs, URLs or visitor identifiers are stored, and third-party analytics tags were ruled out.
For relevance I used synthetic query sets, including a held-out set I committed before measuring, along with the rule for accepting a change. That rule earned its keep. A tweak to Solr’s stopwords lifted hybrid ranking on the held-out set (MRR@5 from 0.88 to 0.98) but let one more unrelated query through. By the rule I wrote in advance, it was not adopted, and the trade-off went to a human decision instead of being rationalized after the fact.
What I’d carry into the next Drupal project
- Profile the data before choosing the technology. Profiling MedlinePlus decided the scope, the features and the things I would not build.
- Let the system say no. An abstention with good topics underneath is more trustworthy than a confident wrong answer.
- Make every layer observable on its own. When a query goes wrong, I can tell whether retrieval, generation or a next-step rule broke.
- Write the acceptance rule before the experiment. It is the cheapest protection against fooling yourself.
medDiscover is an educational proof of concept over 24 topics, with synthetic evaluations and no clinical validation. Within that boundary, it shows how far Drupal can go as the backbone of a search experience that is useful, explainable and careful with the people using it. Source: MedlinePlus, National Library of Medicine.