Download the PHP package tapronto/solr-bundle without Composer

On this page you can find all versions of the php package tapronto/solr-bundle. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package solr-bundle

This Bundle provides a simple API to index and query a Solr Index.

Installation

Solr-Server

Follow the installation instructions in this Tutorial

PHP-Extension

    sudo pecl install -n solr-beta

Bundle

  1. Register bundle in AppKernel.php

    # app/AppKernel.php
    
    $bundles = array(
        // ...
        new FS\SolrBundle\FSSolrBundle(),
        // ...
    );
  2. Add Bundle to autoload

    # app/autoload.php
    
    $loader->registerNamespaces(array(
        // ...
        'FS' => __DIR__.'/../vendor/bundles',
        // ...
    ));

Configuration

You have to setup the connection options

    # app/config/config.yml

    fs_solr:
        solr:
            hostname: localhost
            port: 8983
            path:
                core0: /solr/core0
                core1: /solr/core1
        auto_index: true|false
        entity_manager: default 

Usage

To put an entity to the index, you must add some annotations to your entity:

    // your Entity

    // ....
    use FS\SolrBundle\Doctrine\Annotation as Solr;

    /**
     * 
     *
     * @Solr\Document(repository="Full\Qualified\Class\Name")
     * @ORM\Table()
     */
    class Post
    {
        /**
         * @Solr\Id
         *
         * @ORM\Column(name="id", type="integer")
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="AUTO")
         */
        private $id;

        /**
         *
         * @Solr\Field(type="string")
         *
         * @ORM\Column(name="title", type="string", length=255)
         */
        private $title = '';

        /**
         * 
         * @Solr\Field(type="string")
         *
         * @ORM\Column(name="text", type="text")
         */
        private $text = '';

        /**
         * @Solr\Field(type="date")
         *
         * @ORM\Column(name="created_at", type="datetime")
         */
        private $created_at = null;
    }

If you persist this entity, it will put automaticlly to the index. Update and delete happens automatically too.

To query the index you have to call some services.

    $query = $this->get('solr')->createQuery('AcmeDemoBundle:Post');
    $query->addSearchTerm('title', 'my title');
    $query->addField('id');
    $query->addField('text');

    $result = $query->getResult();

The $result array contains all found entities. The solr-service does all mappings from SolrDocument to your entity for you. In this case only the fields id and text will be mapped (addField()), so title and created_at will be empty. If nothing was found $result is empty.

If no field was explict add, all fields will be mapped.

    $query = $this->get('solr')->createQuery('AcmeDemoBundle:Post');
    $query->addSearchTerm('title', 'my title');

    $result = $result = $query->getResult();

The pervious examples have queried only the field 'title'. You can also query all fields with a string.

    $query = $this->get('solr')->createQuery('AcmeDemoBundle:Post');
    $query->queryAllFields('my title);

    $result = $query->getResult();

To index your entities manually, you can do it the following way:

    $this->get('solr')->addDocument($entity);
    $this->get('solr')->updateDocument($entity);
    $this->get('solr')->deleteDocument($entity);

The delete action needs the id of the entity.

If you specify your own repository you must extend the FS\SolrBundle\Repository\Repository class. The useage is the same like Doctrine-Repositories:

$myRepository = $this->get('solr')->getRepository('AcmeDemoBundle:Post');
$result = $myRepository->mySpecialFindMethod();

If you haven't declared a concrete repository in your entity and you calling $this->get('solr')->getRepository('AcmeDemoBundle:Post'), you will get an instance of FS\SolrBundle\Repository\Repository.

MongoDB

All this functionality is also avaiable for mongo-db entities. The entity configuration via annotations is absolutly the same.

Use multiple Cores

Solr supports multiple indexies. If you have different languages in your application, use can index your documents in different indexies.

The setup is easy:

Under the path option, you can specify your different indexies.

        path:
                core0: /solr/core0
                core1: /solr/core1

In this case the default core is core0. If you use multiple core, then the auto-index functionality should be disabled. In other case all document will index in one core. To disable use the flag auto_index in your config (default value is true).

To index documents with the addDocument method requires a concrete core:

    $this->get('solr')->core('core0')->addDocument($document);

Commands

There are comming two commands with this bundle:


All versions of solr-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=5.3.2
symfony/framework-bundle Version 2.1.*
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package tapronto/solr-bundle contains the following files

Loading the files please wait ....