kix / search-indexer
此包的最新版本(0.5.0)没有可用的许可证信息。
Solr搜索索引器包装器
0.5.0
2013-03-04 12:07 UTC
Requires
- doctrine/common: 2.3.0
- doctrine/doctrine-bundle: 1.0.*
- doctrine/orm: >=2.2.3,<2.4-dev
- nelmio/solarium-bundle: v1.0.0
- oldsound/rabbitmq-bundle: 1.0.0
- symfony/console: *
This package is auto-updated.
Last update: 2024-09-14 02:53:16 UTC
README
这是一个用于美化并简化在Symfony2应用程序中设置Solr搜索后端的过程的包。
用法
在您打算索引的实体类中,使用注解标记类和需要索引的字段
<?php namespace My\MainBundle\Entity; use Doctrine\ORM\Mapping as ORM; use Kix\SearchBundle\Annotation as Search; /** * Work order * * @package Orders * * @ORM\Table(name="orders") * @ORM\Entity * @Search\Indexed(type="workOrder") */ class WorkOrder { /** * @var integer * * @ORM\Column(name="id", type="integer") * @ORM\Id * @ORM\GeneratedValue(strategy="AUTO") * * @Search\Id() * @Search\Indexed(type="int") */ private $id; /** * @var string * * @Search\Indexed(type="string") * @ORM\Column(name="title", type="string", length=255) */ private $title; /** * @var string * * @Search\Indexed(type="text_general") * @ORM\Column(name="description", type="text") */ private $description; /** * @var \DateTime * * @Search\Indexed(type="date") * @ORM\Column(name="createdAt", type="datetime") */ private $createdAt; /** * @var User * * @Search\ComputedIndexed( * types={ * "authorId": "int", * "authorName": "string" * }, calls={ * "authorId": "getId", * "authorName": "getFullName" * } * ) * @ORM\ManyToOne(targetEntity="User") */ private $author; /** * @var City * @ORM\ManyToOne(targetEntity="City") * * @Search\ComputedIndexed( * types={ * "city": "string", * "cityId": "int" * }, calls={ * "city": "getName", * "cityId": "getId" * } * ) */ private $city; /** * Get id * * @return integer */ public function getId() { return $this->id; } /** * Set title * * @param string $title */ public function setTitle($title) { $this->title = $title; return $this; } /** * Get title * * @return string */ public function getTitle() { return $this->title; } /** * @param User $author */ public function setAuthor(User $author) { $this->author = $author; } /** * @return User */ public function getAuthor() { return $this->author; } /** * Set description * * @param string $description * @return WorkOrder */ public function setDescription($description) { $this->description = $description; return $this; } /** * Get description * * @return string */ public function getDescription() { return $this->description; } /** * Set createdAt * * @param \DateTime $createdAt * @return WorkOrder */ public function setCreatedAt($createdAt) { $this->createdAt = $createdAt; return $this; } /** * Get createdAt * * @return \DateTime */ public function getCreatedAt() { return $this->createdAt; } public function setCity($city) { $this->city = $city; } public function getCity() { return $this->city; } }
如您所注意到的,存在几种类型的Indexed
:普通的Indexed
和ComputedIndexed
。区别在于ComputedIndexed
字段通过属性而不是属性本身关联实体。这需要一些额外的配置
@Search\ComputedIndexed( types={ "city": "string", <-- the key "city" is the field name, "string" is the type "cityId": "int" <-- same, "cityId" is the name, the field type is "int" }, calls={ "city": "getName", <-- this is the method name to call on the property for this key "cityId": "getId" } ) */ private $city;
那么,这有什么意义呢?它指定了为了从索引和存储数据到两个Solr字段中,我们需要在注解属性上调用两次。
然后,索引实体的更新将由SearchListener
类捕获。
现在,要索引实体,您需要让OldSound\RabbitMqBundle
工作。