tourze / product-keyword-bundle
商品关键词管理系统,提供关键词分类和商品关联功能
Installs: 0
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
Type:symfony-bundle
pkg:composer/tourze/product-keyword-bundle
Requires
- doctrine/collections: ^2.3
- doctrine/data-fixtures: ^2.0
- doctrine/dbal: ^4.0
- doctrine/doctrine-bundle: ^2.13
- doctrine/doctrine-fixtures-bundle: ^4.0
- doctrine/orm: ^3.0
- doctrine/persistence: ^4.1
- easycorp/easyadmin-bundle: ^4
- knplabs/knp-menu: ^3.7
- symfony/config: ^7.3
- symfony/console: ^7.3
- symfony/dependency-injection: ^7.3
- symfony/doctrine-bridge: ^7.3
- symfony/event-dispatcher-contracts: ^3
- symfony/http-foundation: ^7.3
- symfony/http-kernel: ^7.3
- symfony/messenger: ^7.3
- symfony/property-access: ^7.3
- symfony/serializer: ^7.3
- tourze/arrayable: 1.*
- tourze/bundle-dependency: 1.*
- tourze/catalog-bundle: 1.0.*
- tourze/doctrine-helper: 1.0.*
- tourze/doctrine-indexed-bundle: 1.0.*
- tourze/doctrine-snowflake-bundle: 1.1.*
- tourze/doctrine-timestamp-bundle: 1.1.*
- tourze/doctrine-track-bundle: 1.1.*
- tourze/doctrine-user-bundle: 1.0.*
- tourze/easy-admin-menu-bundle: 1.0.*
- tourze/product-core-bundle: 1.0.*
- tourze/symfony-dependency-service-loader: 1.0.*
Requires (Dev)
This package is auto-updated.
Last update: 2025-11-14 07:23:23 UTC
README
A Symfony Bundle for managing product keywords, supporting product search and keyword categorization.
Table of Contents
- Core Features
- Installation
- Configuration
- Core Entities
- Usage
- Advanced Usage
- Database Schema
- Weight Calculation
- Technical Features
- Requirements
- Extension Suggestions
- Contributing
- License
Core Features
- Keyword Management: Create, edit, and delete product keywords
- Keyword Categorization: Support for keyword category management
- Weight System: Support for weight settings for both keywords and product-keyword associations
- Keyword Search: Find related products based on keywords, sorted by weight
- EasyAdmin Integration: Complete backend management interface
- Recommendation System: Support for keyword recommendation marking
Installation
composer require tourze/product-keyword-bundle
Configuration
Register the Bundle in config/bundles.php:
<?php return [ // ... ProductKeywordBundle\ProductKeywordBundle::class => ['all' => true], ];
Core Entities
Keyword
- id: Unique ID generated by Snowflake algorithm - keyword: Keyword text (max 100 characters, unique) - category: Keyword category (optional) - weight: Weight value (default 1.0) - thumb: Thumbnail (optional) - description: Description (optional) - valid: Is valid (default false) - recommend: Is recommended (default false)
KeywordCategory
- id: Unique ID generated by Snowflake algorithm - name: Category name - description: Category description
ProductKeyword
- id: Unique ID generated by Snowflake algorithm - keyword: Associated keyword - spuId: SPU ID - weight: Association weight (default 1.0) - source: Source of the keyword (default 'manual')
Usage
1. Keyword Search Service
use ProductKeywordBundle\Service\KeywordSearchService; public function __construct( private KeywordSearchService $keywordSearchService ) {} // Find products by single keyword $products = $this->keywordSearchService->findProductsByKeyword('phone'); // Find products by multiple keywords $products = $this->keywordSearchService->findProductsByKeywords(['phone', 'apple']); // Return format: // [ // ['productId' => 123, 'weight' => 2.5], // ['productId' => 456, 'weight' => 1.8], // ]
2. Repository Services
use ProductKeywordBundle\Repository\KeywordRepository; use ProductKeywordBundle\Repository\KeywordCategoryRepository; use ProductKeywordBundle\Repository\ProductKeywordRepository; // Find valid keyword $keyword = $keywordRepository->findByKeyword('phone'); // Find multiple valid keywords by names $keywords = $keywordRepository->findValidKeywordsByNames(['phone', 'apple']); // Find recommended keywords $recommendKeywords = $keywordRepository->findRecommendedKeywords();
3. EasyAdmin Backend Management
The Bundle automatically provides the following management interfaces:
ProductKeywordKeywordCrudController: Keyword managementProductKeywordKeywordCategoryCrudController: Keyword category managementProductKeywordProductKeywordCrudController: Product-keyword association management
Advanced Usage
Custom Keyword Filtering
use ProductKeywordBundle\Repository\KeywordRepository; public function getFilteredKeywords( KeywordRepository $keywordRepository, ?string $category = null, ?float $minWeight = null ): array { $qb = $keywordRepository->createQueryBuilder('k') ->where('k.valid = :valid') ->setParameter('valid', true); if ($category !== null) { $qb->andWhere('k.category = :category') ->setParameter('category', $category); } if ($minWeight !== null) { $qb->andWhere('k.weight >= :minWeight') ->setParameter('minWeight', $minWeight); } return $qb->getQuery()->getResult(); }
Batch Product-Keyword Association
use ProductKeywordBundle\Entity\ProductKeyword; use ProductKeywordBundle\Repository\KeywordRepository; use Doctrine\ORM\EntityManagerInterface; public function batchAssociateKeywords( EntityManagerInterface $em, KeywordRepository $keywordRepository, string $spuId, array $keywordNames, string $source = 'auto' ): void { $keywords = $keywordRepository->findValidKeywordsByNames($keywordNames); foreach ($keywords as $keyword) { $productKeyword = new ProductKeyword(); $productKeyword->setSpuId($spuId) ->setKeyword($keyword) ->setSource($source) ->setWeight($keyword->getWeight()); $em->persist($productKeyword); } $em->flush(); }
Custom Search with Filters
use ProductKeywordBundle\Service\KeywordSearchService; public function searchWithFilters( KeywordSearchService $searchService, array $keywords, ?string $source = null, ?float $minWeight = null ): array { $results = $searchService->findProductsByKeywords($keywords); if ($source !== null || $minWeight !== null) { return array_filter($results, function($result) use ($source, $minWeight) { if ($source !== null && $result['source'] !== $source) { return false; } if ($minWeight !== null && $result['weight'] < $minWeight) { return false; } return true; }); } return $results; }
Database Schema
-- Keywords table CREATE TABLE product_keyword ( id BIGINT PRIMARY KEY COMMENT 'Snowflake ID', keyword VARCHAR(100) UNIQUE NOT NULL COMMENT 'Keyword', category_id BIGINT NULL COMMENT 'Category ID', weight FLOAT DEFAULT 1.0 COMMENT 'Weight value', thumb VARCHAR(255) NULL COMMENT 'Thumbnail', description TEXT NULL COMMENT 'Description', valid BOOLEAN DEFAULT 0 COMMENT 'Valid', recommend BOOLEAN DEFAULT 0 COMMENT 'Recommend', created_at DATETIME COMMENT 'Created at', updated_at DATETIME COMMENT 'Updated at', created_by VARCHAR(255) COMMENT 'Created by', updated_by VARCHAR(255) COMMENT 'Updated by' ); -- Keyword categories table CREATE TABLE product_keyword_category ( id BIGINT PRIMARY KEY COMMENT 'Snowflake ID', name VARCHAR(100) NOT NULL COMMENT 'Category name', description TEXT NULL COMMENT 'Category description', created_at DATETIME COMMENT 'Created at', updated_at DATETIME COMMENT 'Updated at' ); -- Product-keyword associations table CREATE TABLE product_keyword_relation ( id BIGINT PRIMARY KEY COMMENT 'Snowflake ID', keyword_id BIGINT NOT NULL COMMENT 'Keyword ID', spu_id VARCHAR(255) NOT NULL COMMENT 'SPU ID', weight FLOAT DEFAULT 1.0 COMMENT 'Association weight', source VARCHAR(20) DEFAULT 'manual' COMMENT 'Source', created_at DATETIME COMMENT 'Created at', updated_at DATETIME COMMENT 'Updated at', created_by VARCHAR(255) COMMENT 'Created by', updated_by VARCHAR(255) COMMENT 'Updated by' );
Weight Calculation
Final weight calculation formula for search:
Final Weight = Keyword Weight × Product-Keyword Association Weight
Technical Features
- Snowflake Algorithm ID: Uses Snowflake algorithm for distributed unique IDs
- Timestamp Tracking: Automatically records creation and update times
- User Tracking: Automatically records creator and updater
- Index Optimization: Key fields have database indexes added
- Data Validation: Uses Symfony Validator for data validation
- Array Conversion: Supports API, Admin, Plain multiple array output formats
Requirements
- PHP 8.1+
- Symfony 6.4+
- Doctrine ORM 3.0+
- EasyAdmin Bundle 4+
Extension Suggestions
- Cache Optimization: Integrate Redis to cache popular keyword query results
- Search Engine: Combine with Elasticsearch for more powerful full-text search
- Statistics Analysis: Add keyword search statistics functionality
- Auto-complete: Implement search auto-complete based on keyword data
- Synonym Support: Extend synonym matching functionality
Contributing
Please see our contribution guidelines for details on how to contribute to this project.
License
The MIT License (MIT). Please see License File for more information.