Determine which field term was found?

2011-07-21 Thread Olson, Ron
Hi all-

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.

Thanks for any info,

Ron

DISCLAIMER: This electronic message, including any attachments, files or 
documents, is intended only for the addressee and may contain CONFIDENTIAL, 
PROPRIETARY or LEGALLY PRIVILEGED information.  If you are not the intended 
recipient, you are hereby notified that any use, disclosure, copying or 
distribution of this message or any of the information included in or with it 
is  unauthorized and strictly prohibited.  If you have received this message in 
error, please notify the sender immediately by reply e-mail and permanently 
delete and destroy this message and its attachments, along with any copies 
thereof. This message does not create any contractual obligation on behalf of 
the sender or Law Bulletin Publishing Company.
Thank you.


Re: Determine which field term was found?

2011-07-21 Thread Yonik Seeley
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=truegroup.query=A_NAMES:smithgroup.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


RE: Determine which field term was found?

2011-07-21 Thread Olson, Ron
Hmm, okay, well, if that's the way it works, then I'll loop through the arrays, 
as the query is pretty much as described.

Related to what you said about how lucene works, do you think this is 
functionality something worth opening an enhancement request for, or is it such 
a tiny corner-case as to not be worth it?

Thanks a lot for the help!

Ron

-Original Message-
From: ysee...@gmail.com [mailto:ysee...@gmail.com] On Behalf Of Yonik Seeley
Sent: Thursday, July 21, 2011 4:27 PM
To: solr-user@lucene.apache.org
Subject: Re: Determine which field term was found?

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=truegroup.query=A_NAMES:smithgroup.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


DISCLAIMER: This electronic message, including any attachments, files or 
documents, is intended only for the addressee and may contain CONFIDENTIAL, 
PROPRIETARY or LEGALLY PRIVILEGED information.  If you are not the intended 
recipient, you are hereby notified that any use, disclosure, copying or 
distribution of this message or any of the information included in or with it 
is  unauthorized and strictly prohibited.  If you have received this message in 
error, please notify the sender immediately by reply e-mail and permanently 
delete and destroy this message and its attachments, along with any copies 
thereof. This message does not create any contractual obligation on behalf of 
the sender or Law Bulletin Publishing Company.
Thank you.


Re: Determine which field term was found?

2011-07-21 Thread Jonathan Rochkind

I've had this problem too, although never come up with a good solution.

I've wondered, is there any clever way to use the highlighter to 
accomplish tasks like this, or is that more trouble than any help it'll 
get you?


Jonathan

On 7/21/2011 5:27 PM, Yonik Seeley wrote:

On Thu, Jul 21, 2011 at 4:47 PM, Olson, Ronrol...@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=truegroup.query=A_NAMES:smithgroup.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