定制 kix/search-indexer 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

kix/search-indexer

Composer 安装命令:

composer require kix/search-indexer

包简介

Solr search indexer wrapper

README 文档

README

This is a bundle intended to prettify and ease the process of setting up a Solr search backend in a Symfony2 application.

Usage:

In an entity class you intend to index, mark the class and needed fields as indexed with the annotaion:

<?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;
    }
}

As you could notice, there are several kinds of Indexed: just the plain ol' Indexed, and ComputedIndexed. The difference is that a ComputedIndexed field works with entities associated through the property rather than the propreties themselves. This leads to some extra configuration being needed:

@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;

So, what sense does it make? It specifies that for fetching the data for indexing and storing it into two Solr fields we need to make two calls on the property that's annotated.

Updates on indexed entities are then captured in the SearchListener class.

Now, to index the entities, you need to get the OldSound\RabbitMqBundle to work.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2013-03-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固