veza/veza-backend-api/internal/elasticsearch/mappings.go
senke 171a154763 feat(v0.10.2): Recherche fulltext Elasticsearch - F361-F365
- Elasticsearch 8.x dans docker-compose.dev
- Package internal/elasticsearch: client, config, mappings, indices
- Sync PG→ES: reindex tracks/users/playlists, IndexTrack/DeleteTrack
- SearchService ES: multi_match + fuzziness (typo tolerance), highlighting
- Fallback gracieux: PostgreSQL si ELASTICSEARCH_URL absent
- Routes: GET /search, GET /search/suggestions, POST /admin/search/reindex
- Frontend: searchApi cursor/limit params (extensibilité)
- docs/ENV_VARIABLES: ELASTICSEARCH_URL, ELASTICSEARCH_INDEX, ELASTICSEARCH_AUTO_INDEX
- Roadmap v0.10.2 → DONE
2026-03-09 10:13:18 +01:00

132 lines
3.2 KiB
Go

package elasticsearch
// Index names (F361, F362)
const (
IdxTracks = "tracks"
IdxUsers = "users"
IdxPlaylists = "playlists"
)
// Track mapping: title, artist, tags, genre, description (F361)
// Multi-field with fuzziness for typo tolerance (F364)
const tracksMapping = `{
"settings": {
"analysis": {
"analyzer": {
"veza_text": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "asciifolding"]
}
},
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"properties": {
"id": { "type": "keyword" },
"title": {
"type": "text",
"analyzer": "veza_text",
"fields": {
"keyword": { "type": "keyword" },
"fuzzy": {
"type": "text",
"analyzer": "veza_text"
}
}
},
"artist": {
"type": "text",
"analyzer": "veza_text",
"fields": {
"keyword": { "type": "keyword" }
}
},
"description": {
"type": "text",
"analyzer": "veza_text"
},
"album": {
"type": "text",
"analyzer": "veza_text",
"fields": { "keyword": { "type": "keyword" } }
},
"genre": { "type": "keyword" },
"tags": { "type": "keyword" },
"created_at": { "type": "date" },
"cover_art_path": { "type": "keyword", "index": false },
"stream_manifest_url": { "type": "keyword", "index": false },
"file_path": { "type": "keyword", "index": false }
}
}
}`
// User mapping: username, display_name, bio (F362)
const usersMapping = `{
"settings": {
"analysis": {
"analyzer": {
"veza_text": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "asciifolding"]
}
},
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"properties": {
"id": { "type": "keyword" },
"username": {
"type": "text",
"analyzer": "veza_text",
"fields": { "keyword": { "type": "keyword" } }
},
"display_name": {
"type": "text",
"analyzer": "veza_text",
"fields": { "keyword": { "type": "keyword" } }
},
"bio": { "type": "text", "analyzer": "veza_text" },
"location": { "type": "keyword" },
"avatar": { "type": "keyword", "index": false },
"created_at": { "type": "date" }
}
}
}`
// Playlist mapping (F363)
const playlistsMapping = `{
"settings": {
"analysis": {
"analyzer": {
"veza_text": {
"type": "custom",
"tokenizer": "standard",
"filter": ["lowercase", "asciifolding"]
}
},
"number_of_shards": 1,
"number_of_replicas": 0
}
},
"mappings": {
"properties": {
"id": { "type": "keyword" },
"name": {
"type": "text",
"analyzer": "veza_text",
"fields": { "keyword": { "type": "keyword" } }
},
"description": { "type": "text", "analyzer": "veza_text" },
"visibility": { "type": "keyword" },
"cover_url": { "type": "keyword", "index": false },
"created_at": { "type": "date" }
}
}
}`