Jeff
Jeff

Reputation: 73

Solr schema setup help for complex data

I'm trying to setup fields in Solr to do a complex search.

I want users to be able to find organizations based on their hours of operation and services offered during the day and time period.

Example: Find all organizations open Monday at 3pm offering childcare service and Spanish speakers.

The fields are:

- day of week open (long)
- open time (long)
- close time (long)
- services offered (long)
- languages spoken (long)

I know I can use the array field with a range query to search on any one field, but I'm not sure how to correlate the related data. If childcare service is only offered on Wednesday I don't want the organization showing up when searching for Monday.

Upvotes: 0

Views: 386

Answers (1)

Mauricio Scheffer
Mauricio Scheffer

Reputation: 99750

It depends a lot on what kind of queries you'll need. In general it's not possible to design the whole schema from only one sample query, but here's a start:

name: string/text
services: multiValued string
languages: multiValued string
opentime: multiValued string
servicestime: multiValued string

Sample documents:

name: Foo org
services: childcare, something_else
languages: English, Spanish
opentime: Monday 9AM, Monday 10AM, ..., Monday 4PM, Tuesday 9AM, ..., Tuesday 4PM
servicestime: childcare Monday 9AM, ..., childcare Monday 12PM

Your sample query: "Find all organizations open Monday at 3pm offering childcare service and Spanish speakers" can be translated to this schema as: servicestime:"Monday 3PM" AND languages:Spanish (it's implied that if it offers a service on Monday 3PM the organization is open).

In general when designing a Solr schema you will have scenario-specific fields. Remember it's not a relational database, your data should be denormalized.

Upvotes: 2

Related Questions