mydoghasworms
mydoghasworms

Reputation: 18591

Is it possible to make a Solr query span several documents grouped by a common field value?

Is it possible to do a search across several documents in a Solr index that share a common field value and have Solr treat that as one document?

Let's say for example I upload each chapter of a book into Solr as a separate document, but they share a common field, book which is the title of the book.

<doc>
  <field name="id">book1_chap01</field>
  <field name="book">book1</field>
  <field name="text">The proof is in the pudding.</field>
</doc>
<doc>
  <field name="id">book1_chap02</field>
  <field name="book">book1</field>
  <field name="text">The concept is different than the reality.</field>
</doc>

If you search now for proof AND concept it would return nothing, because the words occur in separate documents.

I would like a search like proof AND concept to be performed over all documents that share the common book value "book1" as if they were one document.

Is such a thing possible in Solr?

Upvotes: 0

Views: 182

Answers (2)

Paige Cook
Paige Cook

Reputation: 22555

I believe the Join operation that is available with Solr 4.0 might be able to help with this.

The following query works for the above:

http://localhost:8080/solr4b/collection1/select?q={!join%20from=title%20to=title}text:proof%20AND%20pudding

Upvotes: 2

Parvin Gasimzade
Parvin Gasimzade

Reputation: 26012

You can filter results of book1 and then call OR query.This will be equivalent to what you are looking for.Query should be look like :

q=proof OR concept&fq=book:book1

Upvotes: 0

Related Questions