Ste*_*fan 12 php mysql sql symfony doctrine-orm
为了支持Symfony2中的全文索引,我使用了MyISAM镜像表.我们定期将生产数据集复制到该表,并创建一个映射表结构的SearchEntity,并与真实实体相关联.因此,我们可以在SearchRepository上执行搜索查询(使用自定义MATCH AGAINST语句构建器),并通过解析关联来检索找到的实体.
现在,当我执行doctrine:schema:updateDoctrine2时,无法识别该表上的(手动添加的)索引,并希望删除它们.不幸的是,没有建议注释说"但保持这个索引完整!".
我已经尝试使用@Index与全文索引(前缀为ft_)相同的字段的注释欺骗Doctrine ,然后手动执行一些SQL以用我的FT索引替换它们但是也失败了:当Doctrine最初使用那些虚拟创建表时索引失败,因为索引键长度大于1000字节(这是MySQL中明显原因的硬限制)
问题是:我可以建议Doctrine在schema:update命令中保留它在表上找到的索引吗?有没有办法将其破解到框架中?在每次架构更新后重新创建全文索引非常麻烦:(
SearchEntity:
/**
* @ORM\Table(name="tmp_search2",options={"engine"="MyISAM"},
* uniqueConstraints={@ORM\UniqueConstraint(name="uq",columns={"language_id","product_offer_id","product_group_id","retailer_id"} )},
* indexes={@Index(name="price_idx", columns={"product_offer_price"}),
* @Index(name="started_at_idx", columns={"product_offer_started_at"}),
* @Index(name="ended_at_idx", columns={"product_offer_ended_at"}),
* @Index(name="ft_products", columns={"product_name"}),
* @Index(name="ft_product_group", columns={"product_group_name"}),
* @Index(name="ft_product_retailer", columns={"retailer_name"})
* }
* )
* @ORM\Entity(repositoryClass="SearchRepository")
*/
class SearchEntity
{
/**
* This field is only here to satisfy doctrine's need for a non-composite primary key.
* @ORM\Id
* @ORM\Column(name="id", type="integer")
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $searchId;
/**
* @ORM\ManyToOne(targetEntity="ProductOffer")
* @ORM\JoinColumn(name="product_offer_id", referencedColumnName="id")
*/
private $productOffer;
/**
* @var integer
*
* @ORM\Column(name="product_offer_price", type="integer")
*/
private $price;
Run Code Online (Sandbox Code Playgroud)
用于创建tmp_search索引的SQL(首先删除什么原则离开那里,然后创建我们的)
DROP INDEX ft_products ON tmp_search2;
DROP INDEX ft_product_group ON tmp_search2;
DROP INDEX ft_product_retailer ON tmp_search2;
# import product data and then...
CREATE FULLTEXT INDEX ft_products ON tmp_search2 (product_name,product_short_text,product_long_text);
CREATE FULLTEXT INDEX ft_product_group ON tmp_search2 (product_group_name);
CREATE FULLTEXT INDEX ft_product_retailer ON tmp_search2 (retailer_name);
Run Code Online (Sandbox Code Playgroud)
小智 0