Support for Field and Boost at Query Time

Description

Now that Index time indexing is deprecated I'm trying to move to query time boosting but I'm not able to properly build an query.

The issue is that my query is dynamically built and I have a list of individual fields and their boost values. For example

Name : Boost 10f
Legal Name: Boost 1.5f
Description: Boost 0f

I have a class below which I use to store field name and boost value

What is really need is to be able to loop through my fields that I want to query and their boost value like below

I cannot however find a way to add individual fields to query each with independent query values.

Something like the below.

Environment

None

Activity

Show:
Cody Lerum
October 9, 2018, 10:56 PM
Edited

I think I found a way around this not using the builder

Maybe something like this could be added to the docs?

Yoann Rodière
October 10, 2018, 7:22 AM
Edited

Hello,

This feature is already available. Just do this:

EDIT: This code is wrong, see my next message.

Each boost will be applied to the field mentioned just before, and only that field.

Please tell us if this solves your problem, so that I can close this ticket.

Yoann Rodière
October 10, 2018, 7:28 AM
Edited

Correction: actually, due to how this is implemented, you need to call onField() for the first element only, then call andField for the others. You would do it naturally if you used the fluent API with hard-coded field names, but since you're translating values from your list of IndexedField, it's a bit more difficult.

Something like this:

Cody Lerum
October 10, 2018, 4:29 PM

Yoann,

You are right that does work, but I think my example is cleaner if you are building dynamically.

This can be closed.

Yoann Rodière
October 11, 2018, 6:08 AM

> You are right that does work

Thanks for the feedback.

> but I think my example is cleaner if you are building dynamically.

You example doesn't do exactly the same thing: you're using a query parser, so all sorts of other features are enabled, such as boolean queries (+field1:foo +field:bar), wildcard queries (prefix*suffix), boost queries (field1:bar^4), phrase queries (field1:"some words") and all sorts of other features that give some special characters a meaning. Which you might want, or you might not.

Anyway, you now have two solutions, which should be more than enough Closing.

Assignee

Yoann Rodière

Reporter

Cody Lerum

Labels

None

Suitable for new contributors

None

Pull Request

None

Feedback Requested

None

Components

Affects versions

Priority

Major
Configure