1// Copyright 2019 Google LLC 2// 3// Licensed under the Apache License, Version 2.0 (the "License"); 4// you may not use this file except in compliance with the License. 5// You may obtain a copy of the License at 6// 7// http://www.apache.org/licenses/LICENSE-2.0 8// 9// Unless required by applicable law or agreed to in writing, software 10// distributed under the License is distributed on an "AS IS" BASIS, 11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12// See the License for the specific language governing permissions and 13// limitations under the License. 14 15syntax = "proto2"; 16 17package icing.lib; 18 19import "icing/proto/term.proto"; 20 21option java_package = "com.google.android.icing.proto"; 22option java_multiple_files = true; 23option objc_class_prefix = "ICNG"; 24 25// Encapsulates the configurations on how Icing should score and rank the search 26// results. 27// TODO(b/170347684): Change all timestamps to seconds. 28// Next tag: 12 29message ScoringSpecProto { 30 // OPTIONAL: Indicates how the search results will be ranked. 31 message RankingStrategy { 32 enum Code { 33 // No ranking strategy specified, documents may be returned in an 34 // arbitrary order. 35 NONE = 0; 36 37 // Ranked by user-provided document scores. 38 DOCUMENT_SCORE = 1; 39 40 // Ranked by document creation timestamps. 41 CREATION_TIMESTAMP = 2; 42 43 // The following ranking strategies are based on usage reporting. Please 44 // see usage.proto for more information. If one of the usage ranking 45 // strategy is used but none of result documents have reported usage, the 46 // documents will be returned in the default reverse insertion order. 47 48 // Ranked by count of reports with usage type 1. 49 USAGE_TYPE1_COUNT = 3; 50 51 // Ranked by count of reports with usage type 2. 52 USAGE_TYPE2_COUNT = 4; 53 54 // Ranked by count of reports with usage type 3. 55 USAGE_TYPE3_COUNT = 5; 56 57 // Ranked by last used timestamp with usage type 1. The timestamps are 58 // compared in seconds. 59 USAGE_TYPE1_LAST_USED_TIMESTAMP = 6; 60 61 // Ranked by last used timestamp with usage type 2. The timestamps are 62 // compared in seconds. 63 USAGE_TYPE2_LAST_USED_TIMESTAMP = 7; 64 65 // Ranked by last used timestamp with usage type 3. The timestamps are 66 // compared in seconds. 67 USAGE_TYPE3_LAST_USED_TIMESTAMP = 8; 68 69 // Ranked by relevance score, currently computed as BM25F score. 70 RELEVANCE_SCORE = 9; 71 72 // Ranked by the aggregated score of the joined documents. 73 JOIN_AGGREGATE_SCORE = 10; 74 75 // Ranked by the advanced scoring expression provided. 76 ADVANCED_SCORING_EXPRESSION = 11; 77 } 78 } 79 optional RankingStrategy.Code rank_by = 1; 80 81 // OPTIONAL: Indicates the order of returned search results, the default is 82 // DESC, meaning that results with higher scores come first. This order field 83 // will be ignored if 'rank_by' is NONE. 84 message Order { 85 enum Code { 86 // Search results will be returned in a descending order. 87 DESC = 0; 88 89 // Search results will be returned in a ascending order. 90 ASC = 1; 91 } 92 } 93 optional Order.Code order_by = 2; 94 95 // OPTIONAL: Specifies property weights for RELEVANCE_SCORE scoring strategy. 96 // Property weights are used for promoting or demoting query term matches in a 97 // document property. When property weights are provided, the term frequency 98 // is multiplied by the normalized property weight when computing the 99 // normalized term frequency component of BM25F. To prefer query term matches 100 // in the "subject" property over the "body" property of "Email" documents, 101 // set a higher property weight value for "subject" than "body". By default, 102 // all properties that are not specified are given a raw, pre-normalized 103 // weight of 1.0 when scoring. 104 repeated TypePropertyWeights type_property_weights = 3; 105 106 // OPTIONAL: Specifies the scoring expression for ADVANCED_SCORING_EXPRESSION 107 // RankingStrategy. 108 optional string advanced_scoring_expression = 4; 109} 110 111// Next tag: 3 112message SuggestionScoringSpecProto { 113 message SuggestionRankingStrategy { 114 enum Code { 115 // No ranking strategy specified, terms may be returned in an arbitrary 116 // order. 117 NONE = 0; 118 119 // Ranked by the term's hit count. 120 DOCUMENT_COUNT = 1; 121 122 // Ranked by the term's frequency. 123 TERM_FREQUENCY = 2; 124 } 125 } 126 127 // TermMatchType.Code=UNKNOWN 128 // Should never purposely be set and may lead to undefined behavior. This is 129 // used for backwards compatibility reasons. 130 // 131 // TermMatchType.Code=EXACT_ONLY 132 // Only exact hits will be counted to score a suggestion term. 133 // 134 // TermMatchType.Code=PREFIX 135 // Both exact hits and prefix hits will be counted to score a suggestion 136 // term. 137 optional TermMatchType.Code scoring_match_type = 1; 138 139 // Rank the output suggested result by given SuggestionRankingStrategy. 140 optional SuggestionRankingStrategy.Code rank_by = 2; 141} 142 143// Next tag: 3 144message TypePropertyWeights { 145 // Schema type to apply property weights to. 146 optional string schema_type = 1; 147 148 // Property weights to apply to the schema type. 149 repeated PropertyWeight property_weights = 2; 150} 151 152// Next tag: 3 153message PropertyWeight { 154 // Property path to assign property weight to. Property paths must be composed 155 // only of property names and property separators (the '.' character). 156 // For example, if an "Email" schema type has string property "subject" and 157 // document property "sender", which has string property "name", the property 158 // path for the email's subject would just be "subject" and the property path 159 // for the sender's name would be "sender.name". If an invalid path is 160 // specified, the property weight is discarded. 161 optional string path = 1; 162 163 // Property weight, valid values are positive and zero. Setting a zero 164 // property weight will remove scoring contribution for a query term match in 165 // the property. Negative weights are invalid and will result in an error. 166 // By default, a property is given a raw, pre-normalized weight of 1.0. 167 optional double weight = 2; 168} 169