|
| 1 | +package es |
| 2 | + |
| 3 | +import ZeroTermsQuery "github.com/Trendyol/es-query-builder/es/enums/zero-terms-query" |
| 4 | + |
| 5 | +type matchPhrasePrefixType Object |
| 6 | + |
| 7 | +// MatchPhrasePrefix creates a new es.matchPhrasePrefixType object with the specified field and query. |
| 8 | +// |
| 9 | +// This function initializes an es.matchPhrasePrefixType object for a match phrase prefix query, where the key |
| 10 | +// is the field name and query is the value to search for in that field. This is used |
| 11 | +// to construct queries that match the specified value in the given field. |
| 12 | +// |
| 13 | +// Example usage: |
| 14 | +// |
| 15 | +// m := es.MatchPhrasePrefix("title", "es-query-builder") |
| 16 | +// // m now contains an es.matchPhrasePrefixType object that matches the query "es-query-builder" in the "title" field. |
| 17 | +// |
| 18 | +// Parameters: |
| 19 | +// - key: A string representing the field name for the match phrase prefix query. |
| 20 | +// - query: The value to be matched in the specified field. The type is generic. |
| 21 | +// |
| 22 | +// Returns: |
| 23 | +// |
| 24 | +// An es.matchPhrasePrefixType object containing the specified match phrase prefix query. |
| 25 | +func MatchPhrasePrefix[T any](key string, query T) matchPhrasePrefixType { |
| 26 | + return matchPhrasePrefixType{ |
| 27 | + "match_phrase_prefix": Object{ |
| 28 | + key: Object{ |
| 29 | + "query": query, |
| 30 | + }, |
| 31 | + }, |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +// Analyzer sets the "analyzer" field in the match phrase prefix query. |
| 36 | +// |
| 37 | +// This method specifies the analyzer to use for the match phrase prefix query, which determines |
| 38 | +// how the input text is processed during analysis (e.g., tokenization and normalization). |
| 39 | +// Custom analyzers can be used to tailor the query behavior to specific requirements. |
| 40 | +// |
| 41 | +// Example usage: |
| 42 | +// |
| 43 | +// m := es.MatchPhrasePrefix("title", "es-query-builder").Analyzer("custom_analyzer") |
| 44 | +// // m now has an "analyzer" field set to "custom_analyzer" in the match phrase prefix query object. |
| 45 | +// |
| 46 | +// Parameters: |
| 47 | +// - value: A string representing the name of the analyzer to use. |
| 48 | +// |
| 49 | +// Returns: |
| 50 | +// |
| 51 | +// The updated es.matchPhrasePrefixType object with the "analyzer" field set to the specified value. |
| 52 | +func (m matchPhrasePrefixType) Analyzer(value string) matchPhrasePrefixType { |
| 53 | + return m.putInTheField("analyzer", value) |
| 54 | +} |
| 55 | + |
| 56 | +// Boost sets the "boost" field in the match phrase prefix query. |
| 57 | +// |
| 58 | +// This method configures the match phrase prefix query to use a specified boost factor, which influences |
| 59 | +// the relevance scoring of the matched documents. |
| 60 | +// |
| 61 | +// Example usage: |
| 62 | +// |
| 63 | +// m := es.MatchPhrasePrefix("title", "es-query-builder").Boost(1.5) |
| 64 | +// // m now has a "boost" field set to 1.5 in the match phrase prefix query object. |
| 65 | +// |
| 66 | +// Parameters: |
| 67 | +// - boost: A float64 value representing the boost factor to be applied to the match phrase prefix query. |
| 68 | +// |
| 69 | +// Returns: |
| 70 | +// |
| 71 | +// The updated es.matchPhrasePrefixType object with the "boost" field set to the specified value. |
| 72 | +func (m matchPhrasePrefixType) Boost(boost float64) matchPhrasePrefixType { |
| 73 | + return m.putInTheField("boost", boost) |
| 74 | +} |
| 75 | + |
| 76 | +// MaxExpansions sets the "max_expansions" field in the match phrase prefix query. |
| 77 | +// |
| 78 | +// This method configures the match phrase prefix query to limit the maximum number of terms that can be expanded |
| 79 | +// for multi-term queries, such as those involving fuzzy matching. Higher values allow more terms to |
| 80 | +// be considered, but may impact performance. |
| 81 | +// |
| 82 | +// Example usage: |
| 83 | +// |
| 84 | +// m := es.MatchPhrasePrefix("title", "es-query-builder").MaxExpansions(50) |
| 85 | +// // m now has a "max_expansions" field set to 50 in the match phrase prefix query object. |
| 86 | +// |
| 87 | +// Parameters: |
| 88 | +// - maxExpansions: An integer representing the maximum number of term expansions to be allowed in the match phrase prefix query. |
| 89 | +// |
| 90 | +// Returns: |
| 91 | +// |
| 92 | +// The updated es.matchPhrasePrefixType object with the "max_expansions" field set to the specified value. |
| 93 | +func (m matchPhrasePrefixType) MaxExpansions(maxExpansions int) matchPhrasePrefixType { |
| 94 | + return m.putInTheField("max_expansions", maxExpansions) |
| 95 | +} |
| 96 | + |
| 97 | +// ZeroTermsQuery sets the "zero_terms_query" field in the match phrase prefix query. |
| 98 | +// |
| 99 | +// This method configures the behavior of the match phrase prefix query when no terms remain after analysis |
| 100 | +// (for example, if all terms are stop words). The specified zero_terms_query value determines |
| 101 | +// how to handle this scenario, with options like "all" to match all documents or "none" to |
| 102 | +// match none. |
| 103 | +// |
| 104 | +// Example usage: |
| 105 | +// |
| 106 | +// m := es.MatchPhrasePrefix("title", "es-query-builder").ZeroTermsQuery(zerotermsquery.All) |
| 107 | +// // m now has a "zero_terms_query" field set to "all" in the match phrase prefix query object. |
| 108 | +// |
| 109 | +// Parameters: |
| 110 | +// - zeroTermsQuery: A zerotermsquery.ZeroTermsQuery value that specifies the behavior for zero-term queries. |
| 111 | +// |
| 112 | +// Returns: |
| 113 | +// |
| 114 | +// The updated es.matchPhrasePrefixType object with the "zero_terms_query" field set to the specified value. |
| 115 | +func (m matchPhrasePrefixType) ZeroTermsQuery(zeroTermsQuery ZeroTermsQuery.ZeroTermsQuery) matchPhrasePrefixType { |
| 116 | + return m.putInTheField("zero_terms_query", zeroTermsQuery) |
| 117 | +} |
| 118 | + |
| 119 | +// Slop sets the "slop" field in the match phrase prefix query. |
| 120 | +// |
| 121 | +// This method specifies the allowed distance between terms in a phrase query, enabling more |
| 122 | +// flexibility in matching phrases that may have slight variations in word order or spacing. |
| 123 | +// A higher slop value allows more variation, while a slop of 0 requires exact matching. |
| 124 | +// |
| 125 | +// Example usage: |
| 126 | +// |
| 127 | +// m := es.MatchPhrasePrefix("title", "es-query-builder").Slop(2) |
| 128 | +// // m now has a "slop" field set to 2 in the match phrase prefix query object. |
| 129 | +// |
| 130 | +// Parameters: |
| 131 | +// - slop: An integer representing the maximum allowed distance between terms. |
| 132 | +// |
| 133 | +// Returns: |
| 134 | +// |
| 135 | +// The updated es.matchPhrasePrefixType object with the "slop" field set to the specified value. |
| 136 | +func (m matchPhrasePrefixType) Slop(slop int) matchPhrasePrefixType { |
| 137 | + return m.putInTheField("slop", slop) |
| 138 | +} |
| 139 | + |
| 140 | +func (m matchPhrasePrefixType) putInTheField(key string, value any) matchPhrasePrefixType { |
| 141 | + if matchPhrasePrefix, ok := m["match_phrase_prefix"].(Object); ok { |
| 142 | + for _, fieldObj := range matchPhrasePrefix { |
| 143 | + if fieldObject, foOk := fieldObj.(Object); foOk { |
| 144 | + fieldObject[key] = value |
| 145 | + break |
| 146 | + } |
| 147 | + } |
| 148 | + } |
| 149 | + return m |
| 150 | +} |
0 commit comments