On Thu, Jul 21, 2011 at 4:47 PM, Olson, Ron <rol...@lbpc.com> wrote:
> Is there an easy way to find out which field matched a term in an OR query 
> using Solr? I have a document with names in two multi-valued fields and I am 
> searching for "Smith", using the query "A_NAMES:smith OR B_NAMES:smith". I 
> figure I could loop through both result arrays, but that seems weird to me to 
> have to search again for the value in a result.

That's pretty much the way lucene currently works - you don't know
what fields match a query.
If the query is simple, looping over the returned stored fields is
probably your best bet.

There are a couple other tricks you could use (although they are not
necessarily better):
1) with grouping by query (a trunk feature) you can essentially return
both queries with one request:
  q=*:*&group=true&group.query=A_NAMES:smith&group.query=B_NAMES:smith
  and optionally add a "group.query=A_NAMES:smith OR B_NAMES:smith" if
you need the combined list
2) use pseudo-fields (also trunk) in conjunction with the termfreq
function (the number of times a term appears in a field).  This
obviously only works with term queries.
  fl=*,count1:termfreq(A_NAMES,'smith'),count2:termfreq(B_NAMES,'smith')
  You can use parameter substitution to pull out the actual term and
simplify the query:
  fl=*,count1:termfreq(A_NAMES,$term),count2:termfreq(B_NAMES,$term)&term=smith


-Yonik
http://www.lucidimagination.com

Reply via email to