- Add comprehensive search integration tests (search_test.go) - Test no user, user, and admin contexts - Test partial matching, fuzzy fallback, special characters - Add Bruno API test for search endpoint - Fix missing closing parenthesis in test structure
120 lines
2.9 KiB
Plaintext
120 lines
2.9 KiB
Plaintext
meta {
|
|
name: Search Media Items
|
|
type: http
|
|
seq: 1
|
|
}
|
|
|
|
get {
|
|
url: {{base_url}}/api/media-items/search?q=harry
|
|
auth: inherit
|
|
}
|
|
|
|
headers {
|
|
Content-Type: application/json
|
|
}
|
|
|
|
tests {
|
|
test_search_media_items_success(status, headers, body) {
|
|
if (status !== 200 && status !== 404) {
|
|
throw new Error("Expected status 200 or 404, got " + status);
|
|
}
|
|
|
|
const contentType = headers["content-type"];
|
|
if (!contentType || !contentType.includes("application/json")) {
|
|
throw new Error("Expected content-type to contain application/json, got " + contentType);
|
|
}
|
|
|
|
let data;
|
|
try {
|
|
data = JSON.parse(body);
|
|
} catch (e) {
|
|
throw new Error("Response body is not valid JSON");
|
|
}
|
|
|
|
if (status === 404) {
|
|
if (!data.error || data.error !== "no results found") {
|
|
throw new Error("Expected error message 'no results found' for 404 status");
|
|
}
|
|
return true;
|
|
}
|
|
|
|
if (!Array.isArray(data)) {
|
|
throw new Error("Expected response body to be an array");
|
|
}
|
|
|
|
data.forEach((item, index) => {
|
|
if (!item || typeof item !== "object") {
|
|
throw new Error("Media item at index " + index + " is not an object");
|
|
}
|
|
|
|
if (!item.id) {
|
|
throw new Error("Media item at index " + index + " missing required field: id");
|
|
}
|
|
|
|
if (!item.title) {
|
|
throw new Error("Media item at index " + index + " missing required field: title");
|
|
}
|
|
|
|
if (!item.library_id) {
|
|
throw new Error("Media item at index " + index + " missing required field: library_id");
|
|
}
|
|
});
|
|
|
|
return true;
|
|
}
|
|
}
|
|
|
|
vars:pre-request {
|
|
searchQuery: "harry"
|
|
}
|
|
|
|
settings {
|
|
encodeUrl: true
|
|
timeout: 0
|
|
}
|
|
|
|
docs {
|
|
## Search Media Items
|
|
|
|
Performs a search across all visible media items using partial matching with fuzzy fallback.
|
|
|
|
**Method:** GET
|
|
|
|
**Endpoint:** /api/media-items/search
|
|
|
|
**Authentication:** Required (Bearer token)
|
|
|
|
**Query Parameters:**
|
|
- `q` (string, required): Search query (minimum 2 characters)
|
|
|
|
**Search Behavior:**
|
|
1. First performs case-insensitive partial matching across:
|
|
- Title
|
|
- Author
|
|
- Series
|
|
- Tags
|
|
- Contributors
|
|
2. If no results found, falls back to fuzzy search using word_similarity with 0.3 threshold
|
|
|
|
**Response:** Array of media item objects (same structure as List Media Items)
|
|
|
|
**Status Codes:**
|
|
- 200: Success (results found)
|
|
- 404: No results found
|
|
- 400: Missing or invalid query parameter
|
|
- 401: Unauthorized
|
|
- 500: Internal server error
|
|
|
|
**Examples:**
|
|
- Search by title: `q=harry potter`
|
|
- Search by author: `q=king`
|
|
- Fuzzy search: `q=hary poter` (will find "harry potter")
|
|
|
|
**Ranking:**
|
|
Results are ranked by relevance:
|
|
- Title matches: Highest priority
|
|
- Author matches: High priority
|
|
- Series matches: Medium priority
|
|
- Tag matches: Lower priority
|
|
- Fuzzy matches: Sorted by similarity score
|
|
} |