From 26c0db4d2f97bac4606c4a89b59104c960736902 Mon Sep 17 00:00:00 2001 From: Ziqi Wang Date: Thu, 9 Jan 2025 08:24:54 -0800 Subject: [PATCH] change into topBoostOnly --- .../main/proto/yelp/nrtsearch/search.proto | 4 +- grpc-gateway/luceneserver.swagger.json | 4 +- grpc-gateway/search.pb.go | 170 +++++++++--------- .../highlights/HighlightSettings.java | 24 +-- .../highlights/HighlightUtils.java | 14 +- .../highlights/NRTFastVectorHighlighter.java | 4 +- ... TopBoostOnlyFragmentsBuilderAdaptor.java} | 24 +-- .../NRTFastVectorHighlighterTest.java | 32 +++- 8 files changed, 148 insertions(+), 128 deletions(-) rename src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/{TopPhraseOnceFragmentsBuilderAdaptor.java => TopBoostOnlyFragmentsBuilderAdaptor.java} (84%) diff --git a/clientlib/src/main/proto/yelp/nrtsearch/search.proto b/clientlib/src/main/proto/yelp/nrtsearch/search.proto index 964d28ad0..1d5357b2a 100644 --- a/clientlib/src/main/proto/yelp/nrtsearch/search.proto +++ b/clientlib/src/main/proto/yelp/nrtsearch/search.proto @@ -1132,8 +1132,8 @@ message Highlight { google.protobuf.UInt32Value boundary_max_scan = 15; // Locale used in boundary scanner when using "word" or "sentence" boundary_scanner. Examples: "en-US", "ch-ZH". google.protobuf.StringValue boundary_scanner_locale = 16; - // Only highlight the top matched phrase (with the highest boost value) once per segment. By default, it is false. - google.protobuf.BoolValue top_phrase_once = 17; + // Only highlight the top matched phrases (with the highest boost value) per fragment. By default, it is false. + google.protobuf.BoolValue top_boost_only = 17; } // Highlight settings diff --git a/grpc-gateway/luceneserver.swagger.json b/grpc-gateway/luceneserver.swagger.json index 721ef1581..9ecb3ead1 100644 --- a/grpc-gateway/luceneserver.swagger.json +++ b/grpc-gateway/luceneserver.swagger.json @@ -1766,9 +1766,9 @@ "type": "string", "description": "Locale used in boundary scanner when using \"word\" or \"sentence\" boundary_scanner. Examples: \"en-US\", \"ch-ZH\"." }, - "topPhraseOnce": { + "topBoostOnly": { "type": "boolean", - "description": "Only highlight the top matched phrase (with the highest boost value) once per segment. By default, it is false." + "description": "Only highlight the top matched phrases (with the highest boost value) per fragment. By default, it is false." } } }, diff --git a/grpc-gateway/search.pb.go b/grpc-gateway/search.pb.go index d73f9393d..a9cb1bb6e 100644 --- a/grpc-gateway/search.pb.go +++ b/grpc-gateway/search.pb.go @@ -8660,8 +8660,8 @@ type Highlight_Settings struct { BoundaryMaxScan *wrapperspb.UInt32Value `protobuf:"bytes,15,opt,name=boundary_max_scan,json=boundaryMaxScan,proto3" json:"boundary_max_scan,omitempty"` // Locale used in boundary scanner when using "word" or "sentence" boundary_scanner. Examples: "en-US", "ch-ZH". BoundaryScannerLocale *wrapperspb.StringValue `protobuf:"bytes,16,opt,name=boundary_scanner_locale,json=boundaryScannerLocale,proto3" json:"boundary_scanner_locale,omitempty"` - // Only highlight the top matched phrase (with the highest boost value) once per segment. By default, it is false. - TopPhraseOnce *wrapperspb.BoolValue `protobuf:"bytes,17,opt,name=top_phrase_once,json=topPhraseOnce,proto3" json:"top_phrase_once,omitempty"` + // Only highlight the top matched phrases (with the highest boost value) per fragment. By default, it is false. + TopBoostOnly *wrapperspb.BoolValue `protobuf:"bytes,17,opt,name=top_boost_only,json=topBoostOnly,proto3" json:"top_boost_only,omitempty"` } func (x *Highlight_Settings) Reset() { @@ -8808,9 +8808,9 @@ func (x *Highlight_Settings) GetBoundaryScannerLocale() *wrapperspb.StringValue return nil } -func (x *Highlight_Settings) GetTopPhraseOnce() *wrapperspb.BoolValue { +func (x *Highlight_Settings) GetTopBoostOnly() *wrapperspb.BoolValue { if x != nil { - return x.TopPhraseOnce + return x.TopBoostOnly } return nil } @@ -10191,7 +10191,7 @@ var file_yelp_nrtsearch_search_proto_rawDesc = []byte{ 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x2f, 0x0a, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x17, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, - 0x74, 0x72, 0x75, 0x63, 0x74, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0xc1, 0x0b, + 0x74, 0x72, 0x75, 0x63, 0x74, 0x52, 0x06, 0x70, 0x61, 0x72, 0x61, 0x6d, 0x73, 0x22, 0xbf, 0x0b, 0x0a, 0x09, 0x48, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x12, 0x3c, 0x0a, 0x08, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6c, 0x75, 0x63, 0x65, 0x6e, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x48, 0x69, 0x67, @@ -10203,7 +10203,7 @@ var file_yelp_nrtsearch_search_proto_rawDesc = []byte{ 0x6e, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x48, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2e, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x0d, 0x66, 0x69, 0x65, 0x6c, 0x64, 0x53, 0x65, 0x74, 0x74, - 0x69, 0x6e, 0x67, 0x73, 0x1a, 0xe9, 0x08, 0x0a, 0x08, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, + 0x69, 0x6e, 0x67, 0x73, 0x1a, 0xe7, 0x08, 0x0a, 0x08, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x12, 0x47, 0x0a, 0x10, 0x68, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x65, 0x72, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1c, 0x2e, 0x6c, 0x75, 0x63, 0x65, 0x6e, 0x65, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x48, 0x69, 0x67, 0x68, 0x6c, @@ -10269,85 +10269,85 @@ var file_yelp_nrtsearch_search_proto_rawDesc = []byte{ 0x65, 0x18, 0x10, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1c, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x52, 0x15, 0x62, 0x6f, 0x75, 0x6e, 0x64, 0x61, 0x72, 0x79, 0x53, - 0x63, 0x61, 0x6e, 0x6e, 0x65, 0x72, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x65, 0x12, 0x42, 0x0a, 0x0f, - 0x74, 0x6f, 0x70, 0x5f, 0x70, 0x68, 0x72, 0x61, 0x73, 0x65, 0x5f, 0x6f, 0x6e, 0x63, 0x65, 0x18, - 0x11, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x42, 0x6f, 0x6f, 0x6c, 0x56, 0x61, 0x6c, 0x75, - 0x65, 0x52, 0x0d, 0x74, 0x6f, 0x70, 0x50, 0x68, 0x72, 0x61, 0x73, 0x65, 0x4f, 0x6e, 0x63, 0x65, - 0x1a, 0x62, 0x0a, 0x12, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, - 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x36, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6c, 0x75, 0x63, 0x65, 0x6e, 0x65, - 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x48, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, - 0x2e, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, - 0x3a, 0x02, 0x38, 0x01, 0x22, 0x3b, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, - 0x44, 0x45, 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x46, 0x41, 0x53, - 0x54, 0x5f, 0x56, 0x45, 0x43, 0x54, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x50, 0x4c, - 0x41, 0x49, 0x4e, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x43, 0x55, 0x53, 0x54, 0x4f, 0x4d, 0x10, - 0x03, 0x2a, 0x25, 0x0a, 0x0d, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, - 0x6f, 0x72, 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x48, 0x4f, 0x55, 0x4c, 0x44, 0x10, 0x00, 0x12, 0x08, - 0x0a, 0x04, 0x4d, 0x55, 0x53, 0x54, 0x10, 0x01, 0x2a, 0x95, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x77, - 0x72, 0x69, 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x12, 0x0a, 0x0e, 0x43, 0x4f, - 0x4e, 0x53, 0x54, 0x41, 0x4e, 0x54, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, 0x10, 0x00, 0x12, 0x1a, - 0x0a, 0x16, 0x43, 0x4f, 0x4e, 0x53, 0x54, 0x41, 0x4e, 0x54, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, - 0x5f, 0x42, 0x4f, 0x4f, 0x4c, 0x45, 0x41, 0x4e, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x53, 0x43, - 0x4f, 0x52, 0x49, 0x4e, 0x47, 0x5f, 0x42, 0x4f, 0x4f, 0x4c, 0x45, 0x41, 0x4e, 0x10, 0x02, 0x12, - 0x1b, 0x0a, 0x17, 0x54, 0x4f, 0x50, 0x5f, 0x54, 0x45, 0x52, 0x4d, 0x53, 0x5f, 0x42, 0x4c, 0x45, - 0x4e, 0x44, 0x45, 0x44, 0x5f, 0x46, 0x52, 0x45, 0x51, 0x53, 0x10, 0x03, 0x12, 0x13, 0x0a, 0x0f, - 0x54, 0x4f, 0x50, 0x5f, 0x54, 0x45, 0x52, 0x4d, 0x53, 0x5f, 0x42, 0x4f, 0x4f, 0x53, 0x54, 0x10, - 0x04, 0x12, 0x0d, 0x0a, 0x09, 0x54, 0x4f, 0x50, 0x5f, 0x54, 0x45, 0x52, 0x4d, 0x53, 0x10, 0x05, - 0x2a, 0x38, 0x0a, 0x13, 0x43, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, - 0x65, 0x72, 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x52, 0x45, 0x46, 0x49, - 0x58, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x46, 0x55, 0x5a, - 0x5a, 0x59, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x01, 0x2a, 0xb0, 0x01, 0x0a, 0x0a, 0x52, - 0x65, 0x67, 0x65, 0x78, 0x70, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x45, 0x47, - 0x45, 0x58, 0x50, 0x5f, 0x41, 0x4c, 0x4c, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x52, 0x45, 0x47, - 0x45, 0x58, 0x50, 0x5f, 0x41, 0x4e, 0x59, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, - 0x14, 0x0a, 0x10, 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, 0x41, 0x55, 0x54, 0x4f, 0x4d, 0x41, - 0x54, 0x4f, 0x4e, 0x10, 0x02, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, - 0x43, 0x4f, 0x4d, 0x50, 0x4c, 0x45, 0x4d, 0x45, 0x4e, 0x54, 0x10, 0x03, 0x12, 0x10, 0x0a, 0x0c, - 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, 0x45, 0x4d, 0x50, 0x54, 0x59, 0x10, 0x04, 0x12, 0x17, - 0x0a, 0x13, 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x53, 0x45, - 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x05, 0x12, 0x13, 0x0a, 0x0f, 0x52, 0x45, 0x47, 0x45, 0x58, - 0x50, 0x5f, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x56, 0x41, 0x4c, 0x10, 0x06, 0x12, 0x0f, 0x0a, 0x0b, - 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x07, 0x2a, 0xa6, 0x03, - 0x0a, 0x09, 0x51, 0x75, 0x65, 0x72, 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x4e, - 0x4f, 0x4e, 0x45, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x42, 0x4f, 0x4f, 0x4c, 0x45, 0x41, 0x4e, - 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x48, 0x52, 0x41, - 0x53, 0x45, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x02, 0x12, 0x18, 0x0a, 0x14, 0x46, 0x55, + 0x63, 0x61, 0x6e, 0x6e, 0x65, 0x72, 0x4c, 0x6f, 0x63, 0x61, 0x6c, 0x65, 0x12, 0x40, 0x0a, 0x0e, + 0x74, 0x6f, 0x70, 0x5f, 0x62, 0x6f, 0x6f, 0x73, 0x74, 0x5f, 0x6f, 0x6e, 0x6c, 0x79, 0x18, 0x11, + 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x42, 0x6f, 0x6f, 0x6c, 0x56, 0x61, 0x6c, 0x75, 0x65, + 0x52, 0x0c, 0x74, 0x6f, 0x70, 0x42, 0x6f, 0x6f, 0x73, 0x74, 0x4f, 0x6e, 0x6c, 0x79, 0x1a, 0x62, + 0x0a, 0x12, 0x46, 0x69, 0x65, 0x6c, 0x64, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x45, + 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x36, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x6c, 0x75, 0x63, 0x65, 0x6e, 0x65, 0x73, 0x65, + 0x72, 0x76, 0x65, 0x72, 0x2e, 0x48, 0x69, 0x67, 0x68, 0x6c, 0x69, 0x67, 0x68, 0x74, 0x2e, 0x53, + 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x22, 0x3b, 0x0a, 0x04, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0b, 0x0a, 0x07, 0x44, 0x45, + 0x46, 0x41, 0x55, 0x4c, 0x54, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x46, 0x41, 0x53, 0x54, 0x5f, + 0x56, 0x45, 0x43, 0x54, 0x4f, 0x52, 0x10, 0x01, 0x12, 0x09, 0x0a, 0x05, 0x50, 0x4c, 0x41, 0x49, + 0x4e, 0x10, 0x02, 0x12, 0x0a, 0x0a, 0x06, 0x43, 0x55, 0x53, 0x54, 0x4f, 0x4d, 0x10, 0x03, 0x2a, + 0x25, 0x0a, 0x0d, 0x4d, 0x61, 0x74, 0x63, 0x68, 0x4f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, + 0x12, 0x0a, 0x0a, 0x06, 0x53, 0x48, 0x4f, 0x55, 0x4c, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, + 0x4d, 0x55, 0x53, 0x54, 0x10, 0x01, 0x2a, 0x95, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x77, 0x72, 0x69, + 0x74, 0x65, 0x4d, 0x65, 0x74, 0x68, 0x6f, 0x64, 0x12, 0x12, 0x0a, 0x0e, 0x43, 0x4f, 0x4e, 0x53, + 0x54, 0x41, 0x4e, 0x54, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, 0x10, 0x00, 0x12, 0x1a, 0x0a, 0x16, + 0x43, 0x4f, 0x4e, 0x53, 0x54, 0x41, 0x4e, 0x54, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, 0x5f, 0x42, + 0x4f, 0x4f, 0x4c, 0x45, 0x41, 0x4e, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x53, 0x43, 0x4f, 0x52, + 0x49, 0x4e, 0x47, 0x5f, 0x42, 0x4f, 0x4f, 0x4c, 0x45, 0x41, 0x4e, 0x10, 0x02, 0x12, 0x1b, 0x0a, + 0x17, 0x54, 0x4f, 0x50, 0x5f, 0x54, 0x45, 0x52, 0x4d, 0x53, 0x5f, 0x42, 0x4c, 0x45, 0x4e, 0x44, + 0x45, 0x44, 0x5f, 0x46, 0x52, 0x45, 0x51, 0x53, 0x10, 0x03, 0x12, 0x13, 0x0a, 0x0f, 0x54, 0x4f, + 0x50, 0x5f, 0x54, 0x45, 0x52, 0x4d, 0x53, 0x5f, 0x42, 0x4f, 0x4f, 0x53, 0x54, 0x10, 0x04, 0x12, + 0x0d, 0x0a, 0x09, 0x54, 0x4f, 0x50, 0x5f, 0x54, 0x45, 0x52, 0x4d, 0x53, 0x10, 0x05, 0x2a, 0x38, + 0x0a, 0x13, 0x43, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x69, 0x6f, 0x6e, 0x51, 0x75, 0x65, 0x72, + 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x5f, + 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x46, 0x55, 0x5a, 0x5a, 0x59, + 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x01, 0x2a, 0xb0, 0x01, 0x0a, 0x0a, 0x52, 0x65, 0x67, + 0x65, 0x78, 0x70, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x0e, 0x0a, 0x0a, 0x52, 0x45, 0x47, 0x45, 0x58, + 0x50, 0x5f, 0x41, 0x4c, 0x4c, 0x10, 0x00, 0x12, 0x14, 0x0a, 0x10, 0x52, 0x45, 0x47, 0x45, 0x58, + 0x50, 0x5f, 0x41, 0x4e, 0x59, 0x53, 0x54, 0x52, 0x49, 0x4e, 0x47, 0x10, 0x01, 0x12, 0x14, 0x0a, + 0x10, 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, 0x41, 0x55, 0x54, 0x4f, 0x4d, 0x41, 0x54, 0x4f, + 0x4e, 0x10, 0x02, 0x12, 0x15, 0x0a, 0x11, 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, 0x43, 0x4f, + 0x4d, 0x50, 0x4c, 0x45, 0x4d, 0x45, 0x4e, 0x54, 0x10, 0x03, 0x12, 0x10, 0x0a, 0x0c, 0x52, 0x45, + 0x47, 0x45, 0x58, 0x50, 0x5f, 0x45, 0x4d, 0x50, 0x54, 0x59, 0x10, 0x04, 0x12, 0x17, 0x0a, 0x13, + 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, 0x49, 0x4e, 0x54, 0x45, 0x52, 0x53, 0x45, 0x43, 0x54, + 0x49, 0x4f, 0x4e, 0x10, 0x05, 0x12, 0x13, 0x0a, 0x0f, 0x52, 0x45, 0x47, 0x45, 0x58, 0x50, 0x5f, + 0x49, 0x4e, 0x54, 0x45, 0x52, 0x56, 0x41, 0x4c, 0x10, 0x06, 0x12, 0x0f, 0x0a, 0x0b, 0x52, 0x45, + 0x47, 0x45, 0x58, 0x50, 0x5f, 0x4e, 0x4f, 0x4e, 0x45, 0x10, 0x07, 0x2a, 0xa6, 0x03, 0x0a, 0x09, + 0x51, 0x75, 0x65, 0x72, 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x08, 0x0a, 0x04, 0x4e, 0x4f, 0x4e, + 0x45, 0x10, 0x00, 0x12, 0x11, 0x0a, 0x0d, 0x42, 0x4f, 0x4f, 0x4c, 0x45, 0x41, 0x4e, 0x5f, 0x51, + 0x55, 0x45, 0x52, 0x59, 0x10, 0x01, 0x12, 0x10, 0x0a, 0x0c, 0x50, 0x48, 0x52, 0x41, 0x53, 0x45, + 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x02, 0x12, 0x18, 0x0a, 0x14, 0x46, 0x55, 0x4e, 0x43, + 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, + 0x10, 0x03, 0x12, 0x0e, 0x0a, 0x0a, 0x54, 0x45, 0x52, 0x4d, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, + 0x10, 0x04, 0x12, 0x15, 0x0a, 0x11, 0x54, 0x45, 0x52, 0x4d, 0x5f, 0x49, 0x4e, 0x5f, 0x53, 0x45, + 0x54, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x05, 0x12, 0x13, 0x0a, 0x0f, 0x44, 0x49, 0x53, + 0x4a, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x41, 0x58, 0x10, 0x06, 0x12, 0x09, + 0x0a, 0x05, 0x4d, 0x41, 0x54, 0x43, 0x48, 0x10, 0x07, 0x12, 0x10, 0x0a, 0x0c, 0x4d, 0x41, 0x54, + 0x43, 0x48, 0x5f, 0x50, 0x48, 0x52, 0x41, 0x53, 0x45, 0x10, 0x08, 0x12, 0x0f, 0x0a, 0x0b, 0x4d, + 0x55, 0x4c, 0x54, 0x49, 0x5f, 0x4d, 0x41, 0x54, 0x43, 0x48, 0x10, 0x09, 0x12, 0x09, 0x0a, 0x05, + 0x52, 0x41, 0x4e, 0x47, 0x45, 0x10, 0x0a, 0x12, 0x14, 0x0a, 0x10, 0x47, 0x45, 0x4f, 0x5f, 0x42, + 0x4f, 0x55, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x5f, 0x42, 0x4f, 0x58, 0x10, 0x0b, 0x12, 0x0d, 0x0a, + 0x09, 0x47, 0x45, 0x4f, 0x5f, 0x50, 0x4f, 0x49, 0x4e, 0x54, 0x10, 0x0c, 0x12, 0x0a, 0x0a, 0x06, + 0x4e, 0x45, 0x53, 0x54, 0x45, 0x44, 0x10, 0x0d, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x58, 0x49, 0x53, + 0x54, 0x53, 0x10, 0x0e, 0x12, 0x0e, 0x0a, 0x0a, 0x47, 0x45, 0x4f, 0x5f, 0x52, 0x41, 0x44, 0x49, + 0x55, 0x53, 0x10, 0x0f, 0x12, 0x0e, 0x0a, 0x0a, 0x43, 0x4f, 0x4d, 0x50, 0x4c, 0x45, 0x54, 0x49, + 0x4f, 0x4e, 0x10, 0x10, 0x12, 0x1e, 0x0a, 0x1a, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x5f, 0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, 0x5f, 0x51, 0x55, 0x45, - 0x52, 0x59, 0x10, 0x03, 0x12, 0x0e, 0x0a, 0x0a, 0x54, 0x45, 0x52, 0x4d, 0x5f, 0x51, 0x55, 0x45, - 0x52, 0x59, 0x10, 0x04, 0x12, 0x15, 0x0a, 0x11, 0x54, 0x45, 0x52, 0x4d, 0x5f, 0x49, 0x4e, 0x5f, - 0x53, 0x45, 0x54, 0x5f, 0x51, 0x55, 0x45, 0x52, 0x59, 0x10, 0x05, 0x12, 0x13, 0x0a, 0x0f, 0x44, - 0x49, 0x53, 0x4a, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x4d, 0x41, 0x58, 0x10, 0x06, - 0x12, 0x09, 0x0a, 0x05, 0x4d, 0x41, 0x54, 0x43, 0x48, 0x10, 0x07, 0x12, 0x10, 0x0a, 0x0c, 0x4d, - 0x41, 0x54, 0x43, 0x48, 0x5f, 0x50, 0x48, 0x52, 0x41, 0x53, 0x45, 0x10, 0x08, 0x12, 0x0f, 0x0a, - 0x0b, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x5f, 0x4d, 0x41, 0x54, 0x43, 0x48, 0x10, 0x09, 0x12, 0x09, - 0x0a, 0x05, 0x52, 0x41, 0x4e, 0x47, 0x45, 0x10, 0x0a, 0x12, 0x14, 0x0a, 0x10, 0x47, 0x45, 0x4f, - 0x5f, 0x42, 0x4f, 0x55, 0x4e, 0x44, 0x49, 0x4e, 0x47, 0x5f, 0x42, 0x4f, 0x58, 0x10, 0x0b, 0x12, - 0x0d, 0x0a, 0x09, 0x47, 0x45, 0x4f, 0x5f, 0x50, 0x4f, 0x49, 0x4e, 0x54, 0x10, 0x0c, 0x12, 0x0a, - 0x0a, 0x06, 0x4e, 0x45, 0x53, 0x54, 0x45, 0x44, 0x10, 0x0d, 0x12, 0x0a, 0x0a, 0x06, 0x45, 0x58, - 0x49, 0x53, 0x54, 0x53, 0x10, 0x0e, 0x12, 0x0e, 0x0a, 0x0a, 0x47, 0x45, 0x4f, 0x5f, 0x52, 0x41, - 0x44, 0x49, 0x55, 0x53, 0x10, 0x0f, 0x12, 0x0e, 0x0a, 0x0a, 0x43, 0x4f, 0x4d, 0x50, 0x4c, 0x45, - 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x10, 0x12, 0x1e, 0x0a, 0x1a, 0x4d, 0x55, 0x4c, 0x54, 0x49, 0x5f, - 0x46, 0x55, 0x4e, 0x43, 0x54, 0x49, 0x4f, 0x4e, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, 0x5f, 0x51, - 0x55, 0x45, 0x52, 0x59, 0x10, 0x11, 0x12, 0x17, 0x0a, 0x13, 0x4d, 0x41, 0x54, 0x43, 0x48, 0x5f, - 0x50, 0x48, 0x52, 0x41, 0x53, 0x45, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x10, 0x12, 0x12, - 0x0a, 0x0a, 0x06, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x10, 0x13, 0x12, 0x18, 0x0a, 0x14, 0x43, - 0x4f, 0x4e, 0x53, 0x54, 0x41, 0x4e, 0x54, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, 0x5f, 0x51, 0x55, - 0x45, 0x52, 0x59, 0x10, 0x14, 0x12, 0x0f, 0x0a, 0x0b, 0x47, 0x45, 0x4f, 0x5f, 0x50, 0x4f, 0x4c, - 0x59, 0x47, 0x4f, 0x4e, 0x10, 0x15, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x51, - 0x55, 0x45, 0x52, 0x59, 0x10, 0x16, 0x2a, 0x3c, 0x0a, 0x08, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, - 0x6f, 0x72, 0x12, 0x07, 0x0a, 0x03, 0x4d, 0x49, 0x4e, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4d, - 0x41, 0x58, 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x4d, 0x49, 0x44, 0x44, 0x4c, 0x45, 0x5f, 0x4d, - 0x49, 0x4e, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x4d, 0x49, 0x44, 0x44, 0x4c, 0x45, 0x5f, 0x4d, - 0x41, 0x58, 0x10, 0x03, 0x42, 0x58, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x79, 0x65, 0x6c, 0x70, - 0x2e, 0x6e, 0x72, 0x74, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x72, 0x2e, 0x67, 0x72, 0x70, 0x63, 0x42, 0x13, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x19, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x59, 0x65, 0x6c, 0x70, 0x2f, 0x6e, - 0x72, 0x74, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0xa2, 0x02, 0x03, 0x48, 0x4c, 0x57, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x52, 0x59, 0x10, 0x11, 0x12, 0x17, 0x0a, 0x13, 0x4d, 0x41, 0x54, 0x43, 0x48, 0x5f, 0x50, 0x48, + 0x52, 0x41, 0x53, 0x45, 0x5f, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x10, 0x12, 0x12, 0x0a, 0x0a, + 0x06, 0x50, 0x52, 0x45, 0x46, 0x49, 0x58, 0x10, 0x13, 0x12, 0x18, 0x0a, 0x14, 0x43, 0x4f, 0x4e, + 0x53, 0x54, 0x41, 0x4e, 0x54, 0x5f, 0x53, 0x43, 0x4f, 0x52, 0x45, 0x5f, 0x51, 0x55, 0x45, 0x52, + 0x59, 0x10, 0x14, 0x12, 0x0f, 0x0a, 0x0b, 0x47, 0x45, 0x4f, 0x5f, 0x50, 0x4f, 0x4c, 0x59, 0x47, + 0x4f, 0x4e, 0x10, 0x15, 0x12, 0x0e, 0x0a, 0x0a, 0x53, 0x50, 0x41, 0x4e, 0x5f, 0x51, 0x55, 0x45, + 0x52, 0x59, 0x10, 0x16, 0x2a, 0x3c, 0x0a, 0x08, 0x53, 0x65, 0x6c, 0x65, 0x63, 0x74, 0x6f, 0x72, + 0x12, 0x07, 0x0a, 0x03, 0x4d, 0x49, 0x4e, 0x10, 0x00, 0x12, 0x07, 0x0a, 0x03, 0x4d, 0x41, 0x58, + 0x10, 0x01, 0x12, 0x0e, 0x0a, 0x0a, 0x4d, 0x49, 0x44, 0x44, 0x4c, 0x45, 0x5f, 0x4d, 0x49, 0x4e, + 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x4d, 0x49, 0x44, 0x44, 0x4c, 0x45, 0x5f, 0x4d, 0x41, 0x58, + 0x10, 0x03, 0x42, 0x58, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x79, 0x65, 0x6c, 0x70, 0x2e, 0x6e, + 0x72, 0x74, 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0x2e, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, + 0x67, 0x72, 0x70, 0x63, 0x42, 0x13, 0x53, 0x65, 0x61, 0x72, 0x63, 0x68, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x19, 0x67, 0x69, 0x74, + 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x59, 0x65, 0x6c, 0x70, 0x2f, 0x6e, 0x72, 0x74, + 0x73, 0x65, 0x61, 0x72, 0x63, 0x68, 0xa2, 0x02, 0x03, 0x48, 0x4c, 0x57, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -10703,7 +10703,7 @@ var file_yelp_nrtsearch_search_proto_depIdxs = []int32{ 135, // 197: luceneserver.Highlight.Settings.boundary_chars:type_name -> google.protobuf.StringValue 133, // 198: luceneserver.Highlight.Settings.boundary_max_scan:type_name -> google.protobuf.UInt32Value 135, // 199: luceneserver.Highlight.Settings.boundary_scanner_locale:type_name -> google.protobuf.StringValue - 134, // 200: luceneserver.Highlight.Settings.top_phrase_once:type_name -> google.protobuf.BoolValue + 134, // 200: luceneserver.Highlight.Settings.top_boost_only:type_name -> google.protobuf.BoolValue 125, // 201: luceneserver.Highlight.FieldSettingsEntry.value:type_name -> luceneserver.Highlight.Settings 202, // [202:202] is the sub-list for method output_type 202, // [202:202] is the sub-list for method input_type diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/HighlightSettings.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/HighlightSettings.java index 681e4fd17..ad86b70dd 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/HighlightSettings.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/HighlightSettings.java @@ -38,7 +38,7 @@ public class HighlightSettings { private final Character[] boundaryChars; private final int boundaryMaxScan; private final Locale boundaryScannerLocale; - private final boolean topPhraseOnce; + private final boolean topBoostOnly; public HighlightSettings( Highlighter highlighter, @@ -55,7 +55,7 @@ public HighlightSettings( Character[] boundaryChars, int boundaryMaxScan, Locale boundaryScannerLocale, - boolean topPhraseOnce, + boolean topBoostOnly, Map customHighlighterParams) { this.highlighter = highlighter; this.preTags = preTags; @@ -71,7 +71,7 @@ public HighlightSettings( this.boundaryChars = boundaryChars; this.boundaryMaxScan = boundaryMaxScan; this.boundaryScannerLocale = boundaryScannerLocale; - this.topPhraseOnce = topPhraseOnce; + this.topBoostOnly = topBoostOnly; this.customHighlighterParams = customHighlighterParams; } @@ -91,7 +91,7 @@ public Builder toBuilder() { .withBoundaryChars(this.boundaryChars) .withBoundaryMaxScan(this.boundaryMaxScan) .withBoundaryScannerLocale(this.boundaryScannerLocale) - .withTopPhraseOnce(this.topPhraseOnce) + .withTopBoostOnly(this.topBoostOnly) .withCustomHighlighterParams(this.customHighlighterParams); } @@ -151,8 +151,8 @@ public Locale getBoundaryScannerLocale() { return boundaryScannerLocale; } - public boolean getTopPhraseOnce() { - return topPhraseOnce; + public boolean getTopBoostOnly() { + return topBoostOnly; } public Map getCustomHighlighterParams() { @@ -194,8 +194,8 @@ public String toString() { + boundaryMaxScan + ", boundaryScannerLocale=" + boundaryScannerLocale - + ", topPhraseOnce=" - + topPhraseOnce + + ", topBoostOnly=" + + topBoostOnly + '}'; } @@ -215,7 +215,7 @@ public static final class Builder { private Character[] boundaryChars; private int boundaryMaxScan; private Locale boundaryScannerLocale; - private boolean topPhraseOnce; + private boolean topBoostOnly; private Map customHighlighterParams; public Builder() {} @@ -290,8 +290,8 @@ public Builder withBoundaryScannerLocale(Locale boundaryScannerLocale) { return this; } - public Builder withTopPhraseOnce(boolean topPhraseOnce) { - this.topPhraseOnce = topPhraseOnce; + public Builder withTopBoostOnly(boolean topBoostOnly) { + this.topBoostOnly = topBoostOnly; return this; } @@ -316,7 +316,7 @@ public HighlightSettings build() { boundaryChars, boundaryMaxScan, boundaryScannerLocale, - topPhraseOnce, + topBoostOnly, customHighlighterParams); } } diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/HighlightUtils.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/HighlightUtils.java index dacd17802..63c9c39f7 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/HighlightUtils.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/HighlightUtils.java @@ -133,10 +133,10 @@ static Map createPerFieldSettings( settings.hasBoundaryScannerLocale() ? Locale.forLanguageTag(settings.getBoundaryScannerLocale().getValue()) : globalSettings.getBoundaryScannerLocale()) - .withTopPhraseOnce( - settings.hasTopPhraseOnce() - ? settings.getTopPhraseOnce().getValue() - : globalSettings.getTopPhraseOnce()) + .withTopBoostOnly( + settings.hasTopBoostOnly() + ? settings.getTopBoostOnly().getValue() + : globalSettings.getTopBoostOnly()) .withCustomHighlighterParams( settings.hasCustomHighlighterParams() ? StructValueTransformer.transformStruct( @@ -217,9 +217,9 @@ private static HighlightSettings createGlobalFieldSettings( settings.hasBoundaryScannerLocale() ? Locale.forLanguageTag(settings.getBoundaryScannerLocale().getValue()) : DEFAULT_BOUNDARY_SCANNER_LOCALE) - .withTopPhraseOnce( - settings.hasTopPhraseOnce() - ? settings.getTopPhraseOnce().getValue() + .withTopBoostOnly( + settings.hasTopBoostOnly() + ? settings.getTopBoostOnly().getValue() : DEFAULT_TOP_PHRASE_ONCE) .withCustomHighlighterParams( settings.hasCustomHighlighterParams() diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/NRTFastVectorHighlighter.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/NRTFastVectorHighlighter.java index 561d5ade8..632616d56 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/NRTFastVectorHighlighter.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/NRTFastVectorHighlighter.java @@ -120,12 +120,12 @@ public String[] getHighlights( } BaseFragmentsBuilder fragmentsBuilder = - new TopPhraseOnceFragmentsBuilderAdaptor( + new TopBoostOnlyFragmentsBuilderAdaptor( settings.isScoreOrdered() ? new ScoreOrderFragmentsBuilder() : new SimpleFragmentsBuilder(), boundaryScanner, - settings.getTopPhraseOnce()); + settings.getTopBoostOnly()); fragmentsBuilder.setDiscreteMultiValueHighlighting(settings.getDiscreteMultivalue()); try { diff --git a/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/TopPhraseOnceFragmentsBuilderAdaptor.java b/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/TopBoostOnlyFragmentsBuilderAdaptor.java similarity index 84% rename from src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/TopPhraseOnceFragmentsBuilderAdaptor.java rename to src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/TopBoostOnlyFragmentsBuilderAdaptor.java index 0524bd364..ba8206ccd 100644 --- a/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/TopPhraseOnceFragmentsBuilderAdaptor.java +++ b/src/main/java/com/yelp/nrtsearch/server/luceneserver/highlights/TopBoostOnlyFragmentsBuilderAdaptor.java @@ -15,7 +15,6 @@ */ package com.yelp.nrtsearch.server.luceneserver.highlights; -import java.util.Comparator; import java.util.List; import org.apache.lucene.document.Field; import org.apache.lucene.search.highlight.Encoder; @@ -25,18 +24,18 @@ import org.apache.lucene.search.vectorhighlight.FieldFragList.WeightedFragInfo.SubInfo; import org.apache.lucene.search.vectorhighlight.FieldPhraseList.WeightedPhraseInfo.Toffs; -public class TopPhraseOnceFragmentsBuilderAdaptor extends BaseFragmentsBuilder { +public class TopBoostOnlyFragmentsBuilderAdaptor extends BaseFragmentsBuilder { private final BaseFragmentsBuilder innerBaseFragmentsBuilder; - private final boolean topPhraseOnce; + private final boolean topBoostOnly; /** a constructor. */ - public TopPhraseOnceFragmentsBuilderAdaptor( + public TopBoostOnlyFragmentsBuilderAdaptor( BaseFragmentsBuilder baseFragmentsBuilder, BoundaryScanner boundaryScanner, - boolean topPhraseOnce) { + boolean topBoostOnly) { super(boundaryScanner); this.innerBaseFragmentsBuilder = baseFragmentsBuilder; - this.topPhraseOnce = topPhraseOnce; + this.topBoostOnly = topBoostOnly; } @Override @@ -53,7 +52,7 @@ protected String makeFragment( String[] preTags, String[] postTags, Encoder encoder) { - if (!topPhraseOnce) { + if (!topBoostOnly) { return super.makeFragment(buffer, index, values, fragInfo, preTags, postTags, encoder); } StringBuilder fragment = new StringBuilder(); @@ -63,11 +62,12 @@ protected String makeFragment( getFragmentSourceMSO( buffer, index, values, s, fragInfo.getEndOffset(), modifiedStartOffset); int srcIndex = 0; - // get a list of the first highest boosted phrase only - List subInfos = - fragInfo.getSubInfos().stream().max(Comparator.comparingDouble(SubInfo::getBoost)).stream() - .toList(); - for (SubInfo subInfo : subInfos) { + double topBoostValue = + fragInfo.getSubInfos().stream().map(SubInfo::getBoost).max(Float::compare).orElse(0f); + for (SubInfo subInfo : fragInfo.getSubInfos()) { + if (subInfo.getBoost() < topBoostValue) { + continue; + } for (Toffs to : subInfo.getTermsOffsets()) { fragment .append( diff --git a/src/test/java/com/yelp/nrtsearch/server/luceneserver/highlights/NRTFastVectorHighlighterTest.java b/src/test/java/com/yelp/nrtsearch/server/luceneserver/highlights/NRTFastVectorHighlighterTest.java index 8faddfaa5..ea119d1be 100644 --- a/src/test/java/com/yelp/nrtsearch/server/luceneserver/highlights/NRTFastVectorHighlighterTest.java +++ b/src/test/java/com/yelp/nrtsearch/server/luceneserver/highlights/NRTFastVectorHighlighterTest.java @@ -82,7 +82,7 @@ protected void initIndex(String name) throws Exception { "The food is good there, but the service is terrible.", "I personally don't like the staff at this place.", "Not all food are good.", - "This pizza place was one of my favorites in downtown, and as promised by other users, the pepperoni pizza is the best pepperoni pizza in town.")) + "The margarita pizza and the marinara pizza in this pizzeria are yummy and inexpensive.")) .build()) .putFields( "boundary_scanner_field", @@ -194,7 +194,7 @@ public void testHighlightMultivalueField() { } @Test - public void testHighlightMultivalueFieldWithTopPhraseOnly() { + public void testHighlightMultivalueFieldWithTopBoostOnly() { Highlight highlight = Highlight.newBuilder() .addFields("comment_multivalue") @@ -212,9 +212,29 @@ public void testHighlightMultivalueFieldWithTopPhraseOnly() { PhraseQuery.newBuilder() .setField("comment_multivalue") .addAllTerms( - List.of("pepperoni", "pizza"))) + List.of("margarita", "pizza"))) .setBoost(3)) .setOccurValue(BooleanClause.Occur.SHOULD_VALUE)) + .addClauses( + BooleanClause.newBuilder() + .setQuery( + Query.newBuilder() + .setPhraseQuery( + PhraseQuery.newBuilder() + .setField("comment_multivalue") + .addAllTerms( + List.of("marinara", "pizza"))) + .setBoost(3)) + .setOccurValue(BooleanClause.Occur.SHOULD_VALUE)) + .addClauses( + BooleanClause.newBuilder() + .setQuery( + Query.newBuilder() + .setTermQuery( + TermQuery.newBuilder() + .setField("comment_multivalue") + .setTextValue("delicious")) + .setBoost(4))) .addClauses( BooleanClause.newBuilder() .setQuery( @@ -222,11 +242,11 @@ public void testHighlightMultivalueFieldWithTopPhraseOnly() { .setTermQuery( TermQuery.newBuilder() .setField("comment_multivalue") - .setTextValue("pizza")) + .setTextValue("yummy")) .setBoost(2))))) .setMaxNumberOfFragments(UInt32Value.of(1)) .setFragmentSize(UInt32Value.of(250)) - .setTopPhraseOnce(BoolValue.of(true)) + .setTopBoostOnly(BoolValue.of(true)) .setScoreOrdered(BoolValue.of(true)) .setDiscreteMultivalue(BoolValue.of(true))) .build(); @@ -236,7 +256,7 @@ public void testHighlightMultivalueFieldWithTopPhraseOnly() { assertThat(response.getHits(0).getHighlightsMap().get("comment_multivalue").getFragmentsList()) .containsExactly( - "This pizza place was one of my favorites in downtown, and as promised by other users, the pepperoni pizza is the best pepperoni pizza in town."); + "The margarita pizza and the marinara pizza in this pizzeria are yummy and inexpensive."); assertThat(response.getDiagnostics().getHighlightTimeMs()).isGreaterThan(0); }