You are viewing a plain text version of this content. The canonical link for it is here.
Posted to solr-user@lucene.apache.org by Israel Ekpo <is...@gmail.com> on 2010/01/01 21:11:10 UTC

Re: Help with creating a solr schema

On Thu, Dec 31, 2009 at 10:26 AM, JaredM <em...@gmail.com> wrote:

>
> Hi,
>
> I'm new to Solr but so far I think its great.  I've spent 2 weeks reading
> through the wiki and mailing list info.
>
> I have a use case and I'm not sure what the best way is to implement it.  I
> am keeping track of peoples calendar schedules in a really simple way: each
> user can login and input a number of date ranges where they are available
> (so for example - User Alice might be available between 1-Jan-2010 -
> 15-Jan-2010 and 20-Feb-2010 - 22-Feb-2010 and 1-Mar-2010-5-Mar-2010.
>
> In my data model I have this modelled as a one-to-many with a User table
> (consisting of username, some metadata) and an Availability table
> (consisting of start date and end date).
>
> Now I need to search which users are available between a given date range.
> The bit I'm having trouble with is how to store multiple start & end date
> pairs.  Can someone provide some guidance?
> --
> View this message in context:
> http://old.nabble.com/Help-with-creating-a-solr-schema-tp26979319p26979319.html
> Sent from the Solr - User mailing list archive at Nabble.com.
>
>

I have done something similar to this before.

You will have to store the username, firstname, lastname as single valued
fields

<field name="username" type="string" indexed="true" stored="true"
required="true"/>
<field name="firstname" type="string" indexed="true" stored="true" />
<field name="lastname" type="string" indexed="true" stored="true" />
<field name="start_date" type="tint" indexed="true" stored="true"
multiValued="true"/>
<field name="end_date" type="tint" indexed="true" stored="true"
multiValued="true"/>

However, the start and end dates should be multivalued tint types.

I decided to store the dates as UNIX timestamps. The start dates are stored
as the unix timestamps at 12 midnight of that date (00:00:00)

The end dates are stored as the unix time stamps at 11:59:59 PM on the end
date 23:59:59

This (storing the dates as Trie integers) gave me faster range query
results.

when searching you will also have to convert the dates to unix time stamps
using similar logic before using it in the solr search query

You should use the username of the user as the uniqueKey.

If a user has multiple dates of availability you will enter it like so:

<add>
<doc>
<field name="username">exampleun</field>
<field name="firstname">examplefn<f/field>
<field name="lastname">exampleln</field>
<field name="start_date">137865661</field>
<field name="start_date">137865662</field>
<field name="start_date">137865663</field>
<field name="end_date">137865681</field>
<field name="end_date">137865682</field>
<field name="end_date">137865683</field>
</doc>
</add>


-- 
"Good Enough" is not good enough.
To give anything less than your best is to sacrifice the gift.
Quality First. Measure Twice. Cut Once.
http://www.israelekpo.com/