Skip to content

Commit 8057f2c

Browse files
authored
Merge pull request #46 from haydenhoang/multi-search-params
Prevent the `MultiSearchSearchesParameter` extension from being overwritten when running swagger codegen
2 parents abb3ffc + fd331b2 commit 8057f2c

File tree

4 files changed

+84
-8
lines changed

4 files changed

+84
-8
lines changed

Sources/Typesense/Models/MultiSearchCollectionParameters.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,12 @@ public struct MultiSearchCollectionParameters: Codable {
121121
public var facetReturnParent: String?
122122
/** The base64 encoded audio file in 16 khz 16-bit WAV format. */
123123
public var voiceQuery: String?
124+
/** Whether to rerank hybrid matches. */
125+
public var rerankHybridMatches: Bool?
126+
/** API key for the request. */
127+
public var xTypesenseApiKey: String?
124128

125-
public init(q: String? = nil, queryBy: String? = nil, queryByWeights: String? = nil, textMatchType: String? = nil, _prefix: String? = nil, _infix: String? = nil, maxExtraPrefix: Int? = nil, maxExtraSuffix: Int? = nil, filterBy: String? = nil, sortBy: String? = nil, facetBy: String? = nil, maxFacetValues: Int? = nil, facetQuery: String? = nil, numTypos: String? = nil, page: Int? = nil, perPage: Int? = nil, limit: Int? = nil, offset: Int? = nil, groupBy: String? = nil, groupLimit: Int? = nil, groupMissingValues: Bool? = nil, includeFields: String? = nil, excludeFields: String? = nil, highlightFullFields: String? = nil, highlightAffixNumTokens: Int? = nil, highlightStartTag: String? = nil, highlightEndTag: String? = nil, snippetThreshold: Int? = nil, dropTokensThreshold: Int? = nil, typoTokensThreshold: Int? = nil, pinnedHits: String? = nil, hiddenHits: String? = nil, overrideTags: String? = nil, highlightFields: String? = nil, preSegmentedQuery: Bool? = nil, preset: String? = nil, enableOverrides: Bool? = nil, prioritizeExactMatch: Bool? = nil, prioritizeTokenPosition: Bool? = nil, prioritizeNumMatchingFields: Bool? = nil, enableTyposForNumericalTokens: Bool? = nil, exhaustiveSearch: Bool? = nil, searchCutoffMs: Int? = nil, useCache: Bool? = nil, cacheTtl: Int? = nil, minLen1typo: Int? = nil, minLen2typo: Int? = nil, vectorQuery: String? = nil, remoteEmbeddingTimeoutMs: Int? = nil, remoteEmbeddingNumTries: Int? = nil, collection: String? = nil, facetStrategy: String? = nil, stopwords: String? = nil, facetReturnParent: String? = nil, voiceQuery: String? = nil) {
129+
public init(q: String? = nil, queryBy: String? = nil, queryByWeights: String? = nil, textMatchType: String? = nil, _prefix: String? = nil, _infix: String? = nil, maxExtraPrefix: Int? = nil, maxExtraSuffix: Int? = nil, filterBy: String? = nil, sortBy: String? = nil, facetBy: String? = nil, maxFacetValues: Int? = nil, facetQuery: String? = nil, numTypos: String? = nil, page: Int? = nil, perPage: Int? = nil, limit: Int? = nil, offset: Int? = nil, groupBy: String? = nil, groupLimit: Int? = nil, groupMissingValues: Bool? = nil, includeFields: String? = nil, excludeFields: String? = nil, highlightFullFields: String? = nil, highlightAffixNumTokens: Int? = nil, highlightStartTag: String? = nil, highlightEndTag: String? = nil, snippetThreshold: Int? = nil, dropTokensThreshold: Int? = nil, typoTokensThreshold: Int? = nil, pinnedHits: String? = nil, hiddenHits: String? = nil, overrideTags: String? = nil, highlightFields: String? = nil, preSegmentedQuery: Bool? = nil, preset: String? = nil, enableOverrides: Bool? = nil, prioritizeExactMatch: Bool? = nil, prioritizeTokenPosition: Bool? = nil, prioritizeNumMatchingFields: Bool? = nil, enableTyposForNumericalTokens: Bool? = nil, exhaustiveSearch: Bool? = nil, searchCutoffMs: Int? = nil, useCache: Bool? = nil, cacheTtl: Int? = nil, minLen1typo: Int? = nil, minLen2typo: Int? = nil, vectorQuery: String? = nil, remoteEmbeddingTimeoutMs: Int? = nil, remoteEmbeddingNumTries: Int? = nil, collection: String? = nil, facetStrategy: String? = nil, stopwords: String? = nil, facetReturnParent: String? = nil, voiceQuery: String? = nil, rerankHybridMatches: Bool? = nil, xTypesenseApiKey: String? = nil) {
126130
self.q = q
127131
self.queryBy = queryBy
128132
self.queryByWeights = queryByWeights
@@ -178,6 +182,8 @@ public struct MultiSearchCollectionParameters: Codable {
178182
self.stopwords = stopwords
179183
self.facetReturnParent = facetReturnParent
180184
self.voiceQuery = voiceQuery
185+
self.rerankHybridMatches = rerankHybridMatches
186+
self.xTypesenseApiKey = xTypesenseApiKey
181187
}
182188

183189
public enum CodingKeys: String, CodingKey {
@@ -236,6 +242,8 @@ public struct MultiSearchCollectionParameters: Codable {
236242
case stopwords
237243
case facetReturnParent = "facet_return_parent"
238244
case voiceQuery = "voice_query"
245+
case rerankHybridMatches = "rerank_hybrid_matches"
246+
case xTypesenseApiKey = "x-typesense-api-key"
239247
}
240248

241249
}

Sources/Typesense/Models/MultiSearchParameters.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,12 @@ public struct MultiSearchParameters: Codable {
126126
public var conversationModelId: String?
127127
/** The Id of a previous conversation to continue, this tells Typesense to include prior context when communicating with the LLM. */
128128
public var conversationId: String?
129+
/** Whether to rerank hybrid matches. */
130+
public var rerankHybridMatches: Bool?
131+
/** API key for the request. */
132+
public var xTypesenseApiKey: String?
129133

130-
public init(q: String? = nil, queryBy: String? = nil, queryByWeights: String? = nil, textMatchType: String? = nil, _prefix: String? = nil, _infix: String? = nil, maxExtraPrefix: Int? = nil, maxExtraSuffix: Int? = nil, filterBy: String? = nil, sortBy: String? = nil, facetBy: String? = nil, maxFacetValues: Int? = nil, facetQuery: String? = nil, numTypos: String? = nil, page: Int? = nil, perPage: Int? = nil, limit: Int? = nil, offset: Int? = nil, groupBy: String? = nil, groupLimit: Int? = nil, groupMissingValues: Bool? = nil, includeFields: String? = nil, excludeFields: String? = nil, highlightFullFields: String? = nil, highlightAffixNumTokens: Int? = nil, highlightStartTag: String? = nil, highlightEndTag: String? = nil, snippetThreshold: Int? = nil, dropTokensThreshold: Int? = nil, typoTokensThreshold: Int? = nil, pinnedHits: String? = nil, hiddenHits: String? = nil, overrideTags: String? = nil, highlightFields: String? = nil, preSegmentedQuery: Bool? = nil, preset: String? = nil, enableOverrides: Bool? = nil, prioritizeExactMatch: Bool? = nil, prioritizeTokenPosition: Bool? = nil, prioritizeNumMatchingFields: Bool? = nil, enableTyposForNumericalTokens: Bool? = nil, exhaustiveSearch: Bool? = nil, searchCutoffMs: Int? = nil, useCache: Bool? = nil, cacheTtl: Int? = nil, minLen1typo: Int? = nil, minLen2typo: Int? = nil, vectorQuery: String? = nil, remoteEmbeddingTimeoutMs: Int? = nil, remoteEmbeddingNumTries: Int? = nil, facetStrategy: String? = nil, stopwords: String? = nil, facetReturnParent: String? = nil, voiceQuery: String? = nil, conversation: Bool? = nil, conversationModelId: String? = nil, conversationId: String? = nil) {
134+
public init(q: String? = nil, queryBy: String? = nil, queryByWeights: String? = nil, textMatchType: String? = nil, _prefix: String? = nil, _infix: String? = nil, maxExtraPrefix: Int? = nil, maxExtraSuffix: Int? = nil, filterBy: String? = nil, sortBy: String? = nil, facetBy: String? = nil, maxFacetValues: Int? = nil, facetQuery: String? = nil, numTypos: String? = nil, page: Int? = nil, perPage: Int? = nil, limit: Int? = nil, offset: Int? = nil, groupBy: String? = nil, groupLimit: Int? = nil, groupMissingValues: Bool? = nil, includeFields: String? = nil, excludeFields: String? = nil, highlightFullFields: String? = nil, highlightAffixNumTokens: Int? = nil, highlightStartTag: String? = nil, highlightEndTag: String? = nil, snippetThreshold: Int? = nil, dropTokensThreshold: Int? = nil, typoTokensThreshold: Int? = nil, pinnedHits: String? = nil, hiddenHits: String? = nil, overrideTags: String? = nil, highlightFields: String? = nil, preSegmentedQuery: Bool? = nil, preset: String? = nil, enableOverrides: Bool? = nil, prioritizeExactMatch: Bool? = nil, prioritizeTokenPosition: Bool? = nil, prioritizeNumMatchingFields: Bool? = nil, enableTyposForNumericalTokens: Bool? = nil, exhaustiveSearch: Bool? = nil, searchCutoffMs: Int? = nil, useCache: Bool? = nil, cacheTtl: Int? = nil, minLen1typo: Int? = nil, minLen2typo: Int? = nil, vectorQuery: String? = nil, remoteEmbeddingTimeoutMs: Int? = nil, remoteEmbeddingNumTries: Int? = nil, facetStrategy: String? = nil, stopwords: String? = nil, facetReturnParent: String? = nil, voiceQuery: String? = nil, conversation: Bool? = nil, conversationModelId: String? = nil, conversationId: String? = nil, rerankHybridMatches: Bool? = nil, xTypesenseApiKey: String? = nil) {
131135
self.q = q
132136
self.queryBy = queryBy
133137
self.queryByWeights = queryByWeights
@@ -185,6 +189,8 @@ public struct MultiSearchParameters: Codable {
185189
self.conversation = conversation
186190
self.conversationModelId = conversationModelId
187191
self.conversationId = conversationId
192+
self.rerankHybridMatches = rerankHybridMatches
193+
self.xTypesenseApiKey = xTypesenseApiKey
188194
}
189195

190196
public enum CodingKeys: String, CodingKey {
@@ -245,6 +251,8 @@ public struct MultiSearchParameters: Codable {
245251
case conversation
246252
case conversationModelId = "conversation_model_id"
247253
case conversationId = "conversation_id"
254+
case rerankHybridMatches = "rerank_hybrid_matches"
255+
case xTypesenseApiKey = "x-typesense-api-key"
248256
}
249257

250258
}

Sources/Typesense/Models/MultiSearchSearchesParameter.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,10 @@
77

88
import Foundation
99

10-
11-
1210
public struct MultiSearchSearchesParameter: Codable {
13-
1411
public var searches: [MultiSearchCollectionParameters]
1512

1613
public init(searches: [MultiSearchCollectionParameters]) {
1714
self.searches = searches
1815
}
19-
20-
2116
}

Sources/Typesense/utils/Extensions.swift

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,69 @@ internal extension String {
1010
}
1111
return valid
1212
}
13-
}
13+
}
14+
15+
extension MultiSearchSearchesParameter {
16+
public init(searches: [MultiSearchParameters]) {
17+
self.searches = searches.map { params in
18+
var collectionParams = MultiSearchCollectionParameters()
19+
collectionParams.q = params.q
20+
collectionParams.queryBy = params.queryBy
21+
collectionParams.queryByWeights = params.queryByWeights
22+
collectionParams.textMatchType = params.textMatchType
23+
collectionParams._prefix = params._prefix
24+
collectionParams._infix = params._infix
25+
collectionParams.maxExtraPrefix = params.maxExtraPrefix
26+
collectionParams.maxExtraSuffix = params.maxExtraSuffix
27+
collectionParams.filterBy = params.filterBy
28+
collectionParams.sortBy = params.sortBy
29+
collectionParams.facetBy = params.facetBy
30+
collectionParams.maxFacetValues = params.maxFacetValues
31+
collectionParams.facetQuery = params.facetQuery
32+
collectionParams.numTypos = params.numTypos
33+
collectionParams.page = params.page
34+
collectionParams.perPage = params.perPage
35+
collectionParams.limit = params.limit
36+
collectionParams.offset = params.offset
37+
collectionParams.groupBy = params.groupBy
38+
collectionParams.groupLimit = params.groupLimit
39+
collectionParams.groupMissingValues = params.groupMissingValues
40+
collectionParams.includeFields = params.includeFields
41+
collectionParams.excludeFields = params.excludeFields
42+
collectionParams.highlightFullFields = params.highlightFullFields
43+
collectionParams.highlightAffixNumTokens = params.highlightAffixNumTokens
44+
collectionParams.highlightStartTag = params.highlightStartTag
45+
collectionParams.highlightEndTag = params.highlightEndTag
46+
collectionParams.snippetThreshold = params.snippetThreshold
47+
collectionParams.dropTokensThreshold = params.dropTokensThreshold
48+
collectionParams.typoTokensThreshold = params.typoTokensThreshold
49+
collectionParams.pinnedHits = params.pinnedHits
50+
collectionParams.hiddenHits = params.hiddenHits
51+
collectionParams.overrideTags = params.overrideTags
52+
collectionParams.highlightFields = params.highlightFields
53+
collectionParams.preSegmentedQuery = params.preSegmentedQuery
54+
collectionParams.preset = params.preset
55+
collectionParams.enableOverrides = params.enableOverrides
56+
collectionParams.prioritizeExactMatch = params.prioritizeExactMatch
57+
collectionParams.prioritizeTokenPosition = params.prioritizeTokenPosition
58+
collectionParams.prioritizeNumMatchingFields = params.prioritizeNumMatchingFields
59+
collectionParams.enableTyposForNumericalTokens = params.enableTyposForNumericalTokens
60+
collectionParams.exhaustiveSearch = params.exhaustiveSearch
61+
collectionParams.searchCutoffMs = params.searchCutoffMs
62+
collectionParams.useCache = params.useCache
63+
collectionParams.cacheTtl = params.cacheTtl
64+
collectionParams.minLen1typo = params.minLen1typo
65+
collectionParams.minLen2typo = params.minLen2typo
66+
collectionParams.vectorQuery = params.vectorQuery
67+
collectionParams.remoteEmbeddingTimeoutMs = params.remoteEmbeddingTimeoutMs
68+
collectionParams.remoteEmbeddingNumTries = params.remoteEmbeddingNumTries
69+
collectionParams.facetStrategy = params.facetStrategy
70+
collectionParams.stopwords = params.stopwords
71+
collectionParams.facetReturnParent = params.facetReturnParent
72+
collectionParams.voiceQuery = params.voiceQuery
73+
collectionParams.rerankHybridMatches = params.rerankHybridMatches
74+
collectionParams.xTypesenseApiKey = params.xTypesenseApiKey
75+
return collectionParams
76+
}
77+
}
78+
}

0 commit comments

Comments
 (0)