lucene-solr-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Olson, Ron" <ROL...@lbpc.com>
Subject RE: Determine which field term was found?
Date Thu, 21 Jul 2011 21:36:30 GMT
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: yseeley@gmail.com [mailto:yseeley@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 <ROLSON@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


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.

Mime
View raw message