Skip to content

Commit bafbb31

Browse files
committed
feat: add comprehensive Lucene search query examples to OpenAPI definitions
Added 34 search query examples to types/types.go covering all Lucene search capabilities: - Basic field search (exact match, wildcards) - Boolean operators (AND, OR, NOT) - Required/Prohibited operators (+, -) - Range queries (inclusive, exclusive, open-ended, date ranges) - Quoted phrases and special characters - Complex nested queries - Implicit search across all string fields - JSONB/nested field access with dot notation - Null value queries - Fuzzy search with edit distance These examples can be referenced in Swagger annotations using: $ref: "#/components/examples/SearchQueryBasic" $ref: "#/components/examples/SearchQueryWildcard" etc. This allows API consumers to easily understand and use the Lucene query syntax for filtering and searching resources, similar to how PatchBody provides examples for PATCH operations. Related to PR tink3rlabs#124 which added Lucene search support.
1 parent 2d239e3 commit bafbb31

1 file changed

Lines changed: 172 additions & 0 deletions

File tree

types/types.go

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,178 @@ const definitions = `
137137
}
138138
}
139139
}
140+
},
141+
"examples": {
142+
"SearchQueryBasic": {
143+
"summary": "Basic field search",
144+
"description": "Search for exact match on a specific field",
145+
"value": "name:john"
146+
},
147+
"SearchQueryWildcard": {
148+
"summary": "Wildcard search",
149+
"description": "Use wildcards (* or ?) for partial matching",
150+
"value": "name:john* OR email:*@example.com"
151+
},
152+
"SearchQueryWildcardPrefix": {
153+
"summary": "Prefix wildcard search",
154+
"description": "Match values starting with a prefix",
155+
"value": "name:john*"
156+
},
157+
"SearchQueryWildcardSuffix": {
158+
"summary": "Suffix wildcard search",
159+
"description": "Match values ending with a suffix",
160+
"value": "email:*@example.com"
161+
},
162+
"SearchQueryWildcardContains": {
163+
"summary": "Contains wildcard search",
164+
"description": "Match values containing a substring",
165+
"value": "description:*important*"
166+
},
167+
"SearchQueryBooleanAND": {
168+
"summary": "Boolean AND operator",
169+
"description": "Combine multiple conditions that must all be true",
170+
"value": "name:john AND status:active"
171+
},
172+
"SearchQueryBooleanOR": {
173+
"summary": "Boolean OR operator",
174+
"description": "Match any of the specified conditions",
175+
"value": "status:active OR status:pending"
176+
},
177+
"SearchQueryBooleanNOT": {
178+
"summary": "Boolean NOT operator",
179+
"description": "Exclude results matching a condition",
180+
"value": "name:john NOT status:inactive"
181+
},
182+
"SearchQueryRequired": {
183+
"summary": "Required term (+)",
184+
"description": "Term must be present in results",
185+
"value": "+name:john +status:active"
186+
},
187+
"SearchQueryProhibited": {
188+
"summary": "Prohibited term (-)",
189+
"description": "Exclude results containing this term",
190+
"value": "name:john -status:deleted"
191+
},
192+
"SearchQueryRangeInclusive": {
193+
"summary": "Inclusive range query",
194+
"description": "Match values within a range (inclusive boundaries)",
195+
"value": "age:[25 TO 65]"
196+
},
197+
"SearchQueryRangeExclusive": {
198+
"summary": "Exclusive range query",
199+
"description": "Match values within a range (exclusive boundaries)",
200+
"value": "age:{25 TO 65}"
201+
},
202+
"SearchQueryRangeOpenMin": {
203+
"summary": "Open-ended range (minimum)",
204+
"description": "Match values greater than or equal to minimum",
205+
"value": "age:[25 TO *]"
206+
},
207+
"SearchQueryRangeOpenMax": {
208+
"summary": "Open-ended range (maximum)",
209+
"description": "Match values less than or equal to maximum",
210+
"value": "age:[* TO 65]"
211+
},
212+
"SearchQueryRangeDate": {
213+
"summary": "Date range query",
214+
"description": "Match dates within a specified range",
215+
"value": "created_at:[2024-01-01 TO 2024-12-31]"
216+
},
217+
"SearchQueryQuotedPhrase": {
218+
"summary": "Quoted phrase search",
219+
"description": "Search for exact phrase match",
220+
"value": "description:\"hello world\""
221+
},
222+
"SearchQueryQuotedSpecialChars": {
223+
"summary": "Quoted phrase with special characters",
224+
"description": "Preserve special characters in search",
225+
"value": "title:\"test-app (v1.0)\""
226+
},
227+
"SearchQueryEscaped": {
228+
"summary": "Escaped special characters",
229+
"description": "Escape special characters with backslash",
230+
"value": "name:C\\+\\+ OR path:\\/usr\\/bin"
231+
},
232+
"SearchQueryComplex": {
233+
"summary": "Complex nested query",
234+
"description": "Combine multiple operators with grouping",
235+
"value": "(name:john* OR email:*@example.com) AND status:active AND age:[25 TO 65]"
236+
},
237+
"SearchQueryComplexNested": {
238+
"summary": "Complex nested with multiple groups",
239+
"description": "Advanced query with nested conditions",
240+
"value": "((name:john OR name:jane) AND status:active) OR (status:pending AND age:[18 TO *])"
241+
},
242+
"SearchQueryImplicit": {
243+
"summary": "Implicit search",
244+
"description": "Search across all string fields without specifying field name",
245+
"value": "searchterm"
246+
},
247+
"SearchQueryImplicitWildcard": {
248+
"summary": "Implicit search with wildcard",
249+
"description": "Wildcard search across all string fields",
250+
"value": "john*"
251+
},
252+
"SearchQueryJSONB": {
253+
"summary": "JSONB field access",
254+
"description": "Search within nested JSONB fields using dot notation",
255+
"value": "labels.category:production"
256+
},
257+
"SearchQueryJSONBWildcard": {
258+
"summary": "JSONB field with wildcard",
259+
"description": "Wildcard search on nested JSONB fields",
260+
"value": "metadata.tags:prod*"
261+
},
262+
"SearchQueryJSONBComplex": {
263+
"summary": "Complex JSONB query",
264+
"description": "Combine JSONB and regular field searches",
265+
"value": "name:john AND labels.env:prod AND metadata.team:engineering"
266+
},
267+
"SearchQueryNull": {
268+
"summary": "Null value search",
269+
"description": "Find records where field is null",
270+
"value": "parent_id:null"
271+
},
272+
"SearchQueryNotNull": {
273+
"summary": "Not null search",
274+
"description": "Find records where field is not null",
275+
"value": "NOT deleted_at:null"
276+
},
277+
"SearchQueryNullCombined": {
278+
"summary": "Null with other conditions",
279+
"description": "Combine null checks with other filters",
280+
"value": "name:john AND deleted_at:null"
281+
},
282+
"SearchQueryFuzzy": {
283+
"summary": "Fuzzy search",
284+
"description": "Find similar matches using fuzzy matching (~)",
285+
"value": "name:roam~"
286+
},
287+
"SearchQueryFuzzyDistance": {
288+
"summary": "Fuzzy search with edit distance",
289+
"description": "Fuzzy matching with specified edit distance",
290+
"value": "name:roam~2"
291+
},
292+
"SearchQueryFuzzyJSONB": {
293+
"summary": "Fuzzy search on JSONB field",
294+
"description": "Fuzzy matching on nested JSONB fields",
295+
"value": "labels.tag:prod~"
296+
},
297+
"SearchQueryMixed": {
298+
"summary": "Mixed search operators",
299+
"description": "Combine required, prohibited, ranges, and wildcards",
300+
"value": "+name:john* -status:deleted age:[25 TO 65] AND (role:admin OR role:moderator)"
301+
},
302+
"SearchQueryMultiField": {
303+
"summary": "Multi-field search",
304+
"description": "Search across multiple fields with different conditions",
305+
"value": "name:john OR email:john@example.com OR phone:*555*"
306+
},
307+
"SearchQueryProduction": {
308+
"summary": "Production-ready search example",
309+
"description": "Real-world example combining multiple features",
310+
"value": "(name:*admin* OR role:administrator) AND status:active AND NOT deleted_at:null AND created_at:[2024-01-01 TO *]"
311+
}
140312
}
141313
}
142314
}

0 commit comments

Comments
 (0)