Queries with conditional field inclusions?

2013-10-25 Thread Richard Frovarp
I'm trying to put together a query in Solr that is becoming rather 
complicated, and I'm not quite sure where to even start.


I'm building a directory, which for simplicity sake contains:
First Name
Last Name
Department Name (if faculty / staff)
User Types - faculty, staff, student - multivalued.

I want one search field to search first, last, and department. I have 
that working. However, that means you can find students using a first 
name only search, which isn't exactly desirable, but it is desirable for 
faculty and staff.


So I want:

Search Department Name + Last Name every time
include First Name if user type in (faculty, staff) or if another token 
matched last name.


So searching for richard would only work for me if I'm marked as 
faculty or staff. However searching for frovarp richard would limit to 
my record if I was marked as a student as the frovarp piece would match 
against last names.


Any suggestions or ideas? I'm testing against Solr 4.3.1, but will 
probably be updating to 4.5.1 anyway.


I'm open to multiple cores or searches. I actually have 4 different 
first and last name fields (full, ngram, two phonetic), so scoring 
becomes important.


Thanks,
Richard


Re: Queries with conditional field inclusions?

2013-10-25 Thread Chris Hostetter

: Search Department Name + Last Name every time
: include First Name if user type in (faculty, staff) or if another token
: matched last name.

I haven't tested this, but i think conceptually what you want is...

qq=richard frovarp
q={!maxscore v=$maxof}
maxof=({!dismax qf='lastname deptname' mm='100%' v=$qq}
   ( +{!dismax qf='lastname firstname deptname' mm='100%' v=$qq}
 +( type:(faculty staff)
{!dismax qf=lastname mm='1' v=$qq}
  )^0
   )
  )

You want to execute a query using the users input (qq) twice:
 * once against just the lsatnmae  department
 * once against first, last, and department name
   - but for this query, it's also mandatory that either:
 * type is faculty or staff
 * at least one clause of the users input matches on lastname
...and then you just want the highest scoring of those two verisons of the 
query.

You might need to play with the qf boosts in both cases ... but i *think* 
that should get you where you want to be.


-Hoss