refactor(wiki): enhance taxonomy planning and streamline category handling
Revamp the wiki taxonomy planning process to assign coherent directory paths to entity/concept pages in a single pass, ensuring consistent reuse of existing folders. This change eliminates the need for per-page category assignments during the reduce phase, preserving user-curated categories. Consolidate category path parsing and deduplication into a shared utility, improving consistency across the service and repository layers. Update related functions and tests to reflect these changes, ensuring efficient handling of category paths in the wiki ingestion process.
This commit is contained in:
@@ -148,7 +148,7 @@ func (h *WikiPageHandler) ListCategories(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pageTypes := parseWikiPageTypes(c.Query("page_type"))
|
||||
pageTypes := types.SplitWikiPageTypes(c.Query("page_type"))
|
||||
if len(pageTypes) == 0 {
|
||||
c.JSON(http.StatusBadRequest, gin.H{"error": "page_type is required"})
|
||||
return
|
||||
@@ -186,28 +186,6 @@ func (h *WikiPageHandler) ListCategories(c *gin.Context) {
|
||||
})
|
||||
}
|
||||
|
||||
// parseWikiPageTypes splits a comma-separated page_type query value (e.g.
|
||||
// "entity,concept") into a deduplicated slice, dropping blanks.
|
||||
func parseWikiPageTypes(raw string) []string {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
return nil
|
||||
}
|
||||
seen := make(map[string]struct{})
|
||||
out := make([]string, 0, 4)
|
||||
for _, part := range strings.Split(raw, ",") {
|
||||
part = strings.TrimSpace(part)
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
if _, ok := seen[part]; ok {
|
||||
continue
|
||||
}
|
||||
seen[part] = struct{}{}
|
||||
out = append(out, part)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
func parseWikiCategoryPath(raw string) []string {
|
||||
if strings.TrimSpace(raw) == "" {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user