tp/solarium-extensions-bundle

该包已被废弃且不再维护。没有建议的替代包。

Seldaek 创建的针对 NelmioSolariumBundle 的实用扩展集合。

2.1.0 2013-05-13 16:43 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:24:15 UTC


README

一个扩展 NelmioSolariumBundle,它提供了一个用于文档索引配置的 AnnotationDriver,并支持多值字段。

警告 - 该 Bundle 仍在积极开发中,虽然它正在运行,但远未完成。我强烈建议您在问题部分报告您可能遇到的任何错误(您可能会的)谢谢您的帮助!

Build Status

要求

  • Symfony >= 2.2.0(因为使用了 PropertyAccess 组件)
  • NelmioSolariumBundle >= 2.0.0
  • solarium/solarium >= 3.0.0
  • jms/metadata dev-master
  • doctrine/annotations dev-master
  • doctrine/inflector dev-master

安装

在您的 composer.json 中添加 TPSolariumExtensionsBundle

{
    "require": {
        "tp/solarium-extensions-bundle": "dev-master"
    }
}

下载 Bundle

php composer.phar update tp/solarium-extensions-bundle

将 TPSolariumExtensionsBundle 添加到您的 AppKernel.php

public function registerBundles()
{
    $bundles = array(
        ...
        new TP\SolariumExtensionsBundle\TPSolariumExtensionsBundle(),
        ...
    );
    ...
}

这对于使该 Bundle 正确工作非常重要

让您的 AppKernel 类实现 Symfony\Component\HttpKernel\TerminableInterface

use Symfony\Component\HttpKernel\Kernel;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\HttpKernel\TerminableInterface;

class AppKernel extends Kernel implements TerminableInterface
{
    ...
}

配置

先决条件

首先根据这里的描述配置 NelmioSolariumBundle 客户端。

配置元数据缓存目录(如果需要)

默认情况下,ClassMetadata 被缓存,您可以在这里更改缓存目录。

待办事项:添加不同缓存引擎的配置。

tp_solarium_extensions:
    metadata_cache_dir: %kernel.cache_dir%/%kernel.environment%/solarium_extensions

示例注解配置

查看此类的注释以了解配置,直到我编写了适当的文档。测试套件也是一个检查可能性的好地方。

/**
 * This is the main Document Annotation. The Nelmio service id is mandatory in this case:
 *
 * @Solarium\Document("solarium.client.default")
 *
 * This is the same as:
 *
 * @Solarium\Document(
 *      operations={
 *          @Solarium\Operation("all", service="solarium.client.default")
 *      }
 * )
 *
 * Both these notations will listen to all 'save', 'update', and 'delete' transactions via postPersist,
 * postUpdate and postDelete. Commits will only be done when the kernel terminates, so that expensive
 * requests can be done when the Response is already sent to the Client.
 *
 * You can also assign different NelmioSolariumbundle clients to different operations. In the next
 * example, only 'save' and 'update' will be processed, with the coresponding Clients.
 *
 * @Solarium\Document(
 *      operations={
 *          @Solarium\Operation("save", service="solarium.client.save"),
 *          @Solarium\Operation("update", service="solarium.client.update")
 *      }
 * )
 *
 * But that's not all, you can even specify different endpoints for the same client!
 * In the following example, the "save" opration will use the "anotherOne" endpoint, while the
 * "update" operation uses the default endpoint for the given client service.
 *
 * @Solarium\Document(
 *      operations={
 *          @Solarium\Operation("save", service="solarium.client.save", endpoint="anotherOne"),
 *          @Solarium\Operation("update", service="solarium.client.update")
 *      }
 * )

 * You want to add a document boost? No problem:
 *
 * @Solarium\Document("solarium.client.default", boost="2.4")
 *
 * This is an example of the Mapping Annotation, which you can map field types to Solr's dynamic field
 * suffixes.
 * The strict parameter is for strict checking of field types. If no mapping is specified, a default
 * mapping taken from the current Solr default schema.xml file.
 *
 * @Solarium\Mapping(
 *      mapping={"text_multi"="_tmulti"},
 *      strict=false
 * )
 */
class Example
{
    /**
     * @var int
     *
     * This is the Id Annotation, which is **REQUIRED** on every document.
     * The value "custom_id" is the ID field in solr (if you omit the value, it defaults to 'id'), and
     * propertyAccess is the propertyPath for the new PropertyAccess component.
     *
     * @Solarium\Id("custom_id", propertyAccess="id")
     */
    public $id = 1423;

    /**
     * @var string
     *
     * Fields have as standard type Field::TYPE_STRING = 'string'
     *
     * @Solarium\Field()
     */
    public $string = 'string';

    /**
     * @var string
     *
     * @Solarium\Field(boost="2.3")
     */
    public $boostedField = 'boosted_string';

    /**
     * @var string
     *
     * Use the 'useMapping' parameter to control if you want the dynamic field suffix to be automatically
     * appended, which is the default behavior.
     *
     * @Solarium\Field(useMapping=true)
     */
    public $inflectedNoMapping = 'inflectedNoMapping';

    /**
     * @var string
     *
     * for BC with older Solr versions, inflecting the field names is recommended to work with older
     * filters and components.
     *
     * @Solarium\Field(inflect=true)
     */
    public $mappedNoInflection = 'mappedNoInflection';

    /**
     * @var string
     *
     * Use the 'name' parameter to generate a custom field name instead of the property name.
     *
     * @Solarium\Field(name="myCustomName")
     */
    public $customName = 'customName';

    /**
     * @var bool
     *
     * @Solarium\Field(type="boolean")
     */
    public $bool = false;

    /**
     * @var ArrayCollection
     *
     * The multi-valued field types need to be a Traversable, so either an array or sth that
     * implements \Traversable.
     * The propertyAccess parameter is **MANDATORY** for multi-valued field types, so that the
     * PropertyAccess component can fetch the values from the collection objects.
     *
     * @Solarium\Field(type="text_multi", propertyAccess="multiName")
     */
    public $collection;

    /**
     * @var array
     *
     * The special "__raw__" value for propertyAccess skips the value fetching and just takes the
     * raw items from the collection, like array('value1', 'value2', 'value3').
     *
     * @Solarium\Field(type="string_multi", propertyAccess="__raw__")
     */
    public $stringCollection;

    /**
     * @var object
     *
     * The propertyAccess parameter can also be used to extract a single value from a single
     * object. In this case imagine this object:
     *
     * $this->singleObject = new MySpecialObject();
     * $this->singleObject->title = "Hello propertyAccess on single object";
     *
     * The resulting string in the solr data will be "Hello propertyAccess on single object"!
     * And the PropertyAccess component is very good in guessing the access method, so you
     * don't have to worry if it's a getter, public var, or sth else.
     *
     * @Solarium\Field(type="string", propertyAccess="title")
     */
    public $singleObject;

    /**
     * @var \DateTime
     *
     * Date fields will be automatically converted from \DateTime to UTC Solr Time strings
     *
     * @Solarium\Field(type="date")
     */
    public $date;
}

当前实现的字段类型

    const TYPE_INT           = 'integer';
    const TYPE_INT_MULTI     = 'integer_multi';
    const TYPE_STRING        = 'string';
    const TYPE_STRING_MULTI  = 'string_multi';
    const TYPE_LONG          = 'long';
    const TYPE_LONG_MULTI    = 'long_multi';
    const TYPE_TEXT          = 'text';
    const TYPE_TEXT_MULTI    = 'text_multi';
    const TYPE_BOOLEAN       = 'boolean';
    const TYPE_BOOLEAN_MULTI = 'boolean_multi';
    const TYPE_FLOAT         = 'float';
    const TYPE_FLOAT_MULTI   = 'float_multi';
    const TYPE_DOUBLE        = 'double';
    const TYPE_DOUBLE_MULTI  = 'double_multi';
    const TYPE_DATE          = 'date';
    const TYPE_DATE_MULTI    = 'date_multi';

待办事项:提供详细文档。

运行测试套件

$ phpunit -c phpunit.xml.dist