John Meinken
John Meinken

Reputation: 469

In Solr run text search against document groups instead of individual documents

I have a Solr index containing medical notes for patients. While the index is built around notes, we're generally interested in patients. I typically use the group and facet features to group my search results by patient. This approach typically works well, but there's one situation where it doesn't.

Lets say I want a list of all patients who have notes related to 'arthritis' and 'Lipitor'. I can do a group search like this:

q = NOTE:(arthritis AND lipitor)
facet = true
facet.field = PATIENT_ID

But that will only match patients who have at least one note containing both terms in the same note. What I really want is patients with at least one note containing 'arthritis' and at least one note containing 'lipitor'. I don't care if the terms are contained together in the same note.

Is there any way for Solr to do this?

Upvotes: 0

Views: 53

Answers (2)

John Meinken
John Meinken

Reputation: 469

Nested documents work, but there's another way to do it without changing the database itself. The following will correctly return patients with at least one note containing 'arthritis' and at least one note containing 'lipitor'.

q = arthritis
fq = {!join from=PATIENT_ID to=PATIENT_ID}lipitor,
df = NOTE
facet = true
facet.field = PATIENT_ID

Upvotes: 0

Persimmonium
Persimmonium

Reputation: 15789

There is: use nested documents, where the parent doc is the patient and the child docs are the notes.

I would advise to use the newest Solr release you are allowed to, as this is a feature that is improved all the time (and are some patches on the works too)

Using this setup has some disadvantages (a bit less flexibility in general), but for your use case would work quite well I think.

For docs:

  1. here you can see quick examples as json
  2. the two parsers discussed, you are interested in the second on, for your query

Upvotes: 1

Related Questions