From 2b1b4f5cd9f9ce21f738a4c5ccd50017fc654407 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Wed, 24 Jan 2024 13:12:16 +0000 Subject: propagate phrase weight to all contained items --- container-search/abi-spec.json | 1 + .../src/main/java/com/yahoo/prelude/query/PhraseItem.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/container-search/abi-spec.json b/container-search/abi-spec.json index aedccbee46b..2304743873f 100644 --- a/container-search/abi-spec.json +++ b/container-search/abi-spec.json @@ -1154,6 +1154,7 @@ "public void addItem(int, com.yahoo.prelude.query.Item)", "public com.yahoo.prelude.query.Item setItem(int, com.yahoo.prelude.query.Item)", "public java.util.Optional extractSingleChild()", + "public void setWeight(int)", "public com.yahoo.prelude.query.WordItem getWordItem(int)", "public com.yahoo.prelude.query.BlockItem getBlockItem(int)", "protected void encodeThis(java.nio.ByteBuffer)", diff --git a/container-search/src/main/java/com/yahoo/prelude/query/PhraseItem.java b/container-search/src/main/java/com/yahoo/prelude/query/PhraseItem.java index 755e8de5e4f..ff811c97ba4 100644 --- a/container-search/src/main/java/com/yahoo/prelude/query/PhraseItem.java +++ b/container-search/src/main/java/com/yahoo/prelude/query/PhraseItem.java @@ -153,14 +153,29 @@ public class PhraseItem extends CompositeIndexedItem { private void addIndexedItem(int index, IndexedItem word) { word.setIndexName(this.getIndexName()); + if (word instanceof Item item) { + item.setWeight(this.getWeight()); + } super.addItem(index, (Item) word); } private Item setIndexedItem(int index, IndexedItem word) { word.setIndexName(this.getIndexName()); + if (word instanceof Item item) { + item.setWeight(this.getWeight()); + } return super.setItem(index, (Item) word); } + @Override + public void setWeight(int weight) { + super.setWeight(weight); + for (Iterator i = getItemIterator(); i.hasNext();) { + Item word = i.next(); + word.setWeight(weight); + } + } + /** * Returns a subitem as a word item * -- cgit v1.2.3