PHP code example of kix / search-indexer

1. Go to this page and download the library: Download kix/search-indexer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kix / search-indexer example snippets




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

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