# Design документ для универсальной CMS design_documents = # Design документ для блог постов blog_posts: version: "1.2" views: # Все опубликованные блог посты published: map: ((doc) -> if doc.type is 'blog_post' and doc.status is 'published' emit(doc.created_at, doc)).toString() # Блог посты по домену и языку by_domain_language: map: ((doc) -> if doc.type is 'blog_post' and doc.status is 'published' and doc.domain and doc.language for domain in doc.domain for lang in doc.language emit([domain, lang, doc.created_at], doc)).toString() # Избранные блог посты featured: map: ((doc) -> if doc.type is 'blog_post' and doc.status is 'published' and doc.featured emit(doc.created_at, doc)).toString() # Блог посты по категории by_category: map: ((doc) -> if doc.type is 'blog_post' and doc.status is 'published' and doc.category_id emit([doc.category_id, doc.created_at], doc)).toString() # Блог посты по тегам by_tags: map: ((doc) -> if doc.type is 'blog_post' and doc.status is 'published' and doc.tags for tag_array, lang_index in doc.tags for tag in tag_array emit([tag, doc.created_at], doc)).toString() # Design документ для страниц (page) pages: version: "1.1" views: # Все опубликованные страницы published: map: ((doc) -> if doc.type is 'page' and doc.status is 'published' emit(doc.order || 0, doc)).toString() # Страницы по домену и языку by_domain_language: map: ((doc) -> if doc.type is 'page' and doc.status is 'published' and doc.domain and doc.language for domain in doc.domain for lang in doc.language emit([domain, lang, doc.order || 0], doc)).toString() # Страницы по пути (для меню и навигации) by_path: map: ((doc) -> if doc.type is 'page' and doc.status is 'published' and doc.category_path for path_segment in doc.category_path emit([path_segment, doc.order || 0], doc)).toString() # Страницы по родительскому ID (для иерархии) by_parent: map: ((doc) -> if doc.type is 'page' and doc.status is 'published' parent_id = doc.parent_id || 'root' emit([parent_id, doc.order || 0], doc)).toString() # Защищенные страницы (требующие авторизации) protected: map: ((doc) -> if doc.type is 'page' and doc.status is 'published' and doc.protected emit(doc.order || 0, doc)).toString() # Страницы для карты сайта sitemap: map: ((doc) -> if doc.type is 'page' and doc.status is 'published' and doc.show_in_sitemap != false emit(doc.order || 0, doc)).toString() # Design документ для событий (events) events: version: "1.2" views: # Все опубликованные события published: map: ((doc) -> if doc.type is 'event' and doc.status is 'published' emit(doc.event_data?.event_date || doc.created_at, doc)).toString() # События по домену и языку by_domain_language: map: ((doc) -> if doc.type is 'event' and doc.status is 'published' and doc.domain and doc.language for domain in doc.domain for lang in doc.language emit([domain, lang, doc.event_data?.event_date || doc.created_at], doc)).toString() # Предстоящие события upcoming: map: ((doc) -> if doc.type is 'event' and doc.status is 'published' and doc.event_data event_date = doc.event_data.event_date if event_date and new Date(event_date) > new Date() emit(event_date, doc)).toString() # Прошедшие события past: map: ((doc) -> if doc.type is 'event' and doc.status is 'published' and doc.event_data event_date = doc.event_data.event_date if event_date and new Date(event_date) <= new Date() emit(event_date, doc)).toString() # События по статусу by_status: map: ((doc) -> if doc.type is 'event' and doc.status is 'published' and doc.event_data status = doc.event_data.status || 'upcoming' emit([status, doc.event_data?.event_date || doc.created_at], doc)).toString() # Избранные события featured: map: ((doc) -> if doc.type is 'event' and doc.status is 'published' and doc.featured emit(doc.event_data?.event_date || doc.created_at, doc)).toString() # События по категории by_category: map: ((doc) -> if doc.type is 'event' and doc.status is 'published' and doc.category_id emit([doc.category_id, doc.event_data?.event_date || doc.created_at], doc)).toString() # События по местоположению by_location: map: ((doc) -> if doc.type is 'event' and doc.status is 'published' and doc.event_data?.location for location_array, lang_index in doc.event_data.location for location in location_array emit([location, doc.event_data?.event_date || doc.created_at], doc)).toString() # Design документ для товаров (products) products: version: "1.1" views: # Все опубликованные товары published: map: ((doc) -> if doc.type is 'product' and doc.status is 'published' emit(doc.created_at, doc)).toString() # Товары по домену и языку by_domain_language: map: ((doc) -> if doc.type is 'product' and doc.status is 'published' and doc.domain and doc.language for domain in doc.domain for lang in doc.language emit([domain, lang, doc.created_at], doc)).toString() # Товары по статусу наличия by_availability: map: ((doc) -> if doc.type is 'product' and doc.status is 'published' and doc.product_data status = doc.product_data.status || 'available' emit([status, doc.created_at], doc)).toString() # Избранные товары featured: map: ((doc) -> if doc.type is 'product' and doc.status is 'published' and doc.featured emit(doc.created_at, doc)).toString() # Товары по категории by_category: map: ((doc) -> if doc.type is 'product' and doc.status is 'published' and doc.category_id emit([doc.category_id, doc.created_at], doc)).toString() # Товары по цене by_price: map: ((doc) -> if doc.type is 'product' and doc.status is 'published' and doc.product_data?.price price = doc.product_data.price[0] || 0 emit(price, doc)).toString() # Design документ для слайдеров (slides) slides: version: "1.1" views: # Все активные слайды active: map: ((doc) -> if doc.type is 'slide' and doc.status is 'published' and doc.slide_data?.active != false current_date = new Date().toISOString() start_date = doc.slide_data.start_date || '2000-01-01' end_date = doc.slide_data.end_date || '2100-01-01' if start_date <= current_date <= end_date emit(doc.slide_data?.order || 0, doc)).toString() # Слайды по домену и языку by_domain_language: map: ((doc) -> if doc.type is 'slide' and doc.status is 'published' and doc.slide_data?.active != false and doc.domain and doc.language current_date = new Date().toISOString() start_date = doc.slide_data.start_date || '2000-01-01' end_date = doc.slide_data.end_date || '2100-01-01' if start_date <= current_date <= end_date for domain in doc.domain for lang in doc.language emit([domain, lang, doc.slide_data?.order || 0], doc)).toString() # Слайды по порядку отображения by_order: map: ((doc) -> if doc.type is 'slide' and doc.status is 'published' and doc.slide_data?.active != false current_date = new Date().toISOString() start_date = doc.slide_data.start_date || '2000-01-01' end_date = doc.slide_data.end_date || '2100-01-01' if start_date <= current_date <= end_date emit(doc.slide_data.order || 0, doc)).toString() # Design документ для категорий categories: version: "1.1" views: # Все активные категории active: map: ((doc) -> if doc.type is 'category' and doc.active != false emit(doc.level || 0, doc)).toString() # Категории по домену и языку by_domain_language: map: ((doc) -> if doc.type is 'category' and doc.active != false and doc.domain and doc.language for domain in doc.domain for lang in doc.language emit([domain, lang, doc.level || 0], doc)).toString() # Категории по родительскому ID by_parent: map: ((doc) -> if doc.type is 'category' and doc.active != false parent_id = doc.parent_id || 'root' emit([parent_id, doc.order || 0], doc)).toString() # Категории для меню menu: map: ((doc) -> if doc.type is 'category' and doc.active != false and doc.show_in_menu != false emit([doc.level || 0, doc.menu_order || 0], doc)).toString() # Избранные категории featured: map: ((doc) -> if doc.type is 'category' and doc.active != false and doc.featured emit(doc.level || 0, doc)).toString() # Design документ для настроек доменов domain_settings: version: "1.1" views: # Все активные настройки доменов active: map: ((doc) -> if doc.type is 'domain_settings' and doc.active != false emit(doc.domain, doc)).toString() # Настройки по приоритету by_priority: map: ((doc) -> if doc.type is 'domain_settings' and doc.active != false emit(doc.priority || 0, doc)).toString() # Design документ для пользователей users: version: "1.1" views: # Все активные пользователи active: map: ((doc) -> if doc.type is 'user' and doc.active != false emit(doc.email, doc)).toString() # Пользователи по роли by_role: map: ((doc) -> if doc.type is 'user' and doc.active != false emit(doc.role, doc)).toString() # Пользователи по домену доступа by_domain_access: map: ((doc) -> if doc.type is 'user' and doc.active != false and doc.domains_access for domain in doc.domains_access emit([domain, doc.email], doc)).toString() # Design документ для заказов orders: version: "1.1" views: # Все заказы all: map: ((doc) -> if doc.type is 'order' emit(doc.created_at, doc)).toString() # Заказы по статусу by_status: map: ((doc) -> if doc.type is 'order' emit([doc.status, doc.created_at], doc)).toString() # Заказы по пользователю by_user: map: ((doc) -> if doc.type is 'order' and doc.user_id emit([doc.user_id, doc.created_at], doc)).toString() # Заказы по домену by_domain: map: ((doc) -> if doc.type is 'order' and doc.domain emit([doc.domain, doc.created_at], doc)).toString() # Design документ для аудита audit_logs: version: "1.1" views: # Все записи аудита all: map: ((doc) -> if doc.type is 'audit_log' emit(doc.created_at, doc)).toString() # Записи аудита по пользователю by_user: map: ((doc) -> if doc.type is 'audit_log' and doc.user_id emit([doc.user_id, doc.created_at], doc)).toString() # Записи аудита по типу ресурса by_resource_type: map: ((doc) -> if doc.type is 'audit_log' and doc.resource_type emit([doc.resource_type, doc.created_at], doc)).toString() # Записи аудита по действию by_action: map: ((doc) -> if doc.type is 'audit_log' and doc.action emit([doc.action, doc.created_at], doc)).toString() # Универсальные представления для всех типов документов universal: version: "1.2" views: # Документы по типу и домену by_type_domain: map: ((doc) -> if doc.type and doc.domain if Array.isArray(doc.domain) for domain in doc.domain emit([doc.type, domain, doc.created_at], doc) else emit([doc.type, doc.domain, doc.created_at], doc)).toString() # Документы по типу и статусу by_type_status: map: ((doc) -> if doc.type and doc.status emit([doc.type, doc.status, doc.created_at], doc)).toString() # Поиск по текстовым полям (для полнотекстового поиска) text_search: map: ((doc) -> if doc.title and Array.isArray(doc.title) for title in doc.title words = title.toLowerCase().split(/\s+/) for word in words when word.length > 2 emit(word, {_id: doc._id, type: doc.type, title: doc.title}) if doc.content and Array.isArray(doc.content) for content in doc.content words = content.toLowerCase().split(/\s+/) for word in words when word.length > 2 emit(word, {_id: doc._id, type: doc.type, content: content}) if doc.tags and Array.isArray(doc.tags) for tag_array in doc.tags for tag in tag_array emit(tag.toLowerCase(), {_id: doc._id, type: doc.type, tags: doc.tags})).toString() # Документы с поддержкой мультиязычности multilingual: map: ((doc) -> if doc.language and Array.isArray(doc.language) and doc.domain domain_array = if Array.isArray(doc.domain) then doc.domain else [doc.domain] for domain in domain_array for lang in doc.language emit([domain, lang, doc.type, doc.created_at], doc)).toString() # Экспорт design документов module.exports = design_documents