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 Chris Hostetter <ho...@fucit.org> on 2009/01/02 20:30:07 UTC

Re: Using query functions against a "type" field

: I would like to use a query function to boost documents of a certain
: "type". I realize that I can use a boost query for this, but in
: analyzing the scoring it doesn't seem as predictable as the query
: functions.

It should be fairly predictible, can you elaborate on what problems you 
have just adding boost queries for the specific types?

if you us want simple boosting by type, i would use boost queries ... if 
you want the type to contribute to a more complex calculation, then yeah a 
function queyr is hte way to go...

: Can this be done with function queries?

the simplest approach would be to pick numeric constants for each type 
(BAR=>1, BAZ=>2) and index those in a numeric field -- you could still 
choose not to use them in some queries (unlike document boosts) but the 
downside is hte weighting would be the same for every function.


: As a follow up, how difficult would it be for me to write my own
: function (and plug it into Solr) that allowed me to return a 1.0 or 0.0
: if a field had a particular string value in it? A function that would
: look something like "fieldEq(foo,BAR)"

if you want BAR to be worth 1 in some queries and 5 in other queries, then 
writing a custom function is hte way to go.  the way to implement it would 
be as a ValueSource -- ValueSources are the inputs to functions, 
(functions are themselves also ValueSources so they can be fed to other 
functions) and the lowest level ValueSources get their values from some 
contcrete location: ConstValueSource, FieldCacheSource, FileFloatSource.  
You could write a subclass of FieldCacheSource that looked at the 
StringIndex FieldCache to get the indexed term (BAR) and then map that to 
a number.

to take advantage of your new ValueSource, you write a simple 
ValueSourceParser impl and add a <valueSourceParser> line to your 
solrconfig.xml registering it to the name you want ("fieldEq" in your 
example)

a generic Parser/ValueSource that let you specific term=>float mappings in 
it's init params would certianly make a cool patch for Solr.


-Hoss


RE: Using query functions against a "type" field

Posted by "Feak, Todd" <To...@smss.sony.com>.
Thanks Yonik!

I still may investigate the query function stuff that was discussed, as
Hoss indicated it may hold value.

-Todd Feak

-----Original Message-----
From: Yonik Seeley [mailto:yseeley@gmail.com] 
Sent: Tuesday, January 06, 2009 10:19 AM
To: solr-user@lucene.apache.org
Subject: Re: Using query functions against a "type" field

On Tue, Jan 6, 2009 at 1:05 PM, Feak, Todd <To...@smss.sony.com>
wrote:
> I'm not sure I followed all that Yonik.
>
> Are you saying that I can achieve this affect now with a bq setting in
> my DisMax query instead of via a bf setting?

Yep, a "const" QParser would enable that.

bq={!const}foo:bar

-Yonik


Re: Using query functions against a "type" field

Posted by Yonik Seeley <ys...@gmail.com>.
On Tue, Jan 6, 2009 at 1:05 PM, Feak, Todd <To...@smss.sony.com> wrote:
> I'm not sure I followed all that Yonik.
>
> Are you saying that I can achieve this affect now with a bq setting in
> my DisMax query instead of via a bf setting?

Yep, a "const" QParser would enable that.

bq={!const}foo:bar

-Yonik

RE: Using query functions against a "type" field

Posted by "Feak, Todd" <To...@smss.sony.com>.
I'm not sure I followed all that Yonik.

Are you saying that I can achieve this affect now with a bq setting in
my DisMax query instead of via a bf setting?

-Todd Feak

-----Original Message-----
From: Yonik Seeley [mailto:yseeley@gmail.com] 
Sent: Tuesday, January 06, 2009 9:46 AM
To: solr-user@lucene.apache.org
Subject: Re: Using query functions against a "type" field

On Tue, Jan 6, 2009 at 10:41 AM, Feak, Todd <To...@smss.sony.com>
wrote:
> The boost queries are true queries, so the amount boost can be
affected
> by things like term frequency for the query.

Sounds like a constant score query is a general way to do this.

Possible QParser syntax:
{!const}tag:FOO OR tag:BAR

Could be implemented via
ConstantScoreQuery(QueryWrapperFilter(theQuery))

The value could be the boost, optionally set within this QParser...
{!const v=2.0}tag:FOO OR tag:BAR

-Yonik


Re: Using query functions against a "type" field

Posted by Yonik Seeley <ys...@gmail.com>.
On Tue, Jan 6, 2009 at 10:41 AM, Feak, Todd <To...@smss.sony.com> wrote:
> The boost queries are true queries, so the amount boost can be affected
> by things like term frequency for the query.

Sounds like a constant score query is a general way to do this.

Possible QParser syntax:
{!const}tag:FOO OR tag:BAR

Could be implemented via ConstantScoreQuery(QueryWrapperFilter(theQuery))

The value could be the boost, optionally set within this QParser...
{!const v=2.0}tag:FOO OR tag:BAR

-Yonik

RE: Using query functions against a "type" field

Posted by "Feak, Todd" <To...@smss.sony.com>.
:It should be fairly predictible, can you elaborate on what problems you

:have just adding boost queries for the specific types?

The boost queries are true queries, so the amount boost can be affected
by things like term frequency for the query. The functions aren't
affected by this and therefore more predictable over the life of the
index. If I want to boost documents via multiple factors, their
interaction is very important. If that interaction slowly changes over
the life of the index, I lose that control.

:a generic Parser/ValueSource that let you specific term=>float mappings
in 
:it's init params would certianly make a cool patch for Solr.

I do believe I will work on this (may take me a bit). Once I nail it
down, I've got a couple of other easier query functions I would like to
add as well, if they hold value for the community.

-Hoss