Developed with love by KnpLabs Hire us for your project!
11

EWZSearchBundle

by excelwebzone

This bundle provides advance search capability for Symfony.

EWZSearchBundle

This bundle provides advance search capability for Symfony.

Installation

Installation depends on how your project is setup:

Installation using composer

To install EWZSearchBundle with Composer just add the following to your composer.json file:

// composer.json
{
    // ...
    require: {
        // ...
        "excelwebzone/zend-search": "dev-master",
        "excelwebzone/search-bundle": "dev-master",
    }
}

Then, you can install the new dependencies by running Composer’s update command from
the directory where your composer.json file is located:

php composer.phar update

Now, Composer will automatically download all required files, and install them for you.
All that is left to do is to update your AppKernel.php file, and register the new bundle:

<?php

// in AppKernel::registerBundles()
$bundles = array(
    // ...
    new EWZ\Bundle\SearchBundle\EWZSearchBundle(),
    // ...
);

alternative Installation methods

Install with the vendors.php or using submodules

The bin/vendors.php method

If you're using the bin/vendors.php method to manage your vendor libraries,
add the following entries to the deps in the root of your project file:

[EWZSearchBundle]
    git=http://github.com/excelwebzone/EWZSearchBundle.git
    target=/bundles/EWZ/Bundle/SearchBundle

; Dependency:
;------------
[Search]
    git=http://github.com/excelwebzone/zend-search.git
    target=/zend-search

Next, update your vendors by running:

$ ./bin/vendors

Great! Now skip down to Configure the autoloader.

Submodules

If you're managing your vendor libraries with submodules, first create the
vendor/bundles/EWZ/Bundle directory:

$ mkdir -pv vendor/bundles/EWZ/Bundle

Next, add the necessary submodules:

$ git submodule add git://github.com/excelwebzone/zend-search.git vendor/zend-search/Zend/Search
$ git submodule add git://github.com/excelwebzone/EWZSearchBundle.git vendor/bundles/EWZ/Bundle/SearchBundle

Configure the autoloader

Add the following entry to your autoloader:

<?php
// app/autoload.php

$loader->registerNamespaces(array(
    // ...

    'Zend\\Search' => __DIR__.'/../vendor/zend-search/',
    'EWZ'          => __DIR__.'/../vendor/bundles',
));

Enable the bundle

Finally, enable the bundle in the kernel:

<?php
// app/AppKernel.php

public function registerBundles()
{
    $bundles = array(
        // ...

        new EWZ\Bundle\SearchBundle\EWZSearchBundle(),
    );
}

Configuration

Define your search indices in the config.yml. You can use the EWZSearchBundle with multiple search indices and with various Analyzers.

NOTE: If you want to include numbers in your search queries then you'll need to set
analyzer to Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive
See http://framework.zend.com/manual/en/zend.search.lucene.extending.html for more information

For backward compatability reasons the old and new config both work.

using one or more SearchIndex => new config

# app/config/config.yml
ewz_search:
    indices:
        indexFoo:
            path:                 %kernel.root_dir%/EwzLuceneIndices/%kernel.environment%/myIndexFoo
            analyzer:             Zend\Search\Lucene\Analysis\Analyzer\Common\Utf8\CaseInsensitive
        indexBar:
            path:                 %kernel.root_dir%/EwzLuceneIndices/%kernel.environment%/myIndexBar
            analyzer:             Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive

    # deprecated
    analyzer:             Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive
    path:                 %kernel.root_dir%/cache/%kernel.environment%/lucene/index

using only one SearchIndex => old config

# app/config/config.yml
ewz_search:
    analyzer: Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive
    path:     %kernel.root_dir%/cache/%kernel.environment%/lucene/index

Congratulations! You're ready!

Basic Usage

Getting the index

Depending on you configuration you can get access to the LuceneSearch object for your index in one of the following ways:

<?php

use EWZ\Bundle\SearchBundle\Lucene\LuceneSearch;

// with the new configuration-style
$luceneSearchForFooIndex = $this->get('ewz_search.lucene.manager')->getIndex('indexFoo');
$luceneSearchForBarIndex = $this->get('ewz_search.lucene.manager')->getIndex('indexBar');

// with the old configuration-style
$search = $this->get('ewz_search.lucene');

Use the index

To index an object use the following example:

<?php

use EWZ\Bundle\SearchBundle\Lucene\LuceneSearch;

$search = $this->get('ewz_search.lucene.manager')->getIndex('indexFoo');

$document = new Document();
$document->addField(Field::keyword('key', $story->getId()));
$document->addField(Field::text('title', $story->getTitle()));
$document->addField(Field::text('url', $story->getUrl()));
$document->addField(Field::unstored('body', $story->getDescription()));

$search->addDocument($document);
$search->updateIndex();

When you want to retrieve data, use:

<?php

use EWZ\Bundle\SearchBundle\Lucene\LuceneSearch;

$search = $this->get('ewz_search.lucene.manager')->getIndex('indexFoo');
$query = 'Symfony2';

$results = $search->find($query);

NOTE: See the Zend documentation for more information.

Copyright (c) 2010-2011 Michael H. Arieli

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
ewz_search:
indices:

# Prototype
name:
path: %kernel.root_dir%/EwzLuceneIndices/%kernel.environment%/defaultIndex
analyzer: Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive
analyzer: Zend\Search\Lucene\Analysis\Analyzer\Common\TextNum\CaseInsensitive
path: %kernel.root_dir%/cache/%kernel.environment%/lucene/index
  • Merge pull request #2 from azine/master
    By excelwebzone, 3 years ago
  • minimize changes for pull-request
    By dominik, 4 years ago
  • update the README.md
    By dominik, 4 years ago
  • update README.md
    By dominik, 4 years ago
  • update the README.md
    By dominik, 4 years ago
  • updated README.md
    By dominik, 4 years ago
  • fixed Config-Definition
    By dominik, 4 years ago
  • added the option to define multiple search indices and to customize the storage-location
    By dominik, 4 years ago
  • Revert "Updated to used "zendframework/zendsearch""
    By excelwebzone, 4 years ago
  • Merge branch 'master' of https://github.com/excelwebzone/EWZSearchBundle
    By excelwebzone, 4 years ago
  • Updated to used "zendframework/zendsearch"
    By excelwebzone, 4 years ago
  • Initial set of files
    By excelwebzone, 4 years ago
  • Initial commit
    By excelwebzone, 4 years ago
  • Updated README file
    By excelwebzone, 5 years ago
  • Added composer script
    By excelwebzone, 5 years ago
  • Merge pull request #4 from chrismckinnel/master
    By excelwebzone, 5 years ago
  • Changed find method to accept sort parameters
    By chrismckinnel, 6 years ago
  • Fixed bundle installation target path
    By excelwebzone, 6 years ago
  • Rename services - added "ewz_" prefix
    By excelwebzone, 6 years ago
  • Removed unused use class
    By excelwebzone, 6 years ago
  • Cleanup
    By excelwebzone, 6 years ago
  • Added license
    By excelwebzone, 6 years ago
  • Fix and add some phpDoc
    By excelwebzone, 6 years ago
  • Renamed "symfony.com" namespace to "excelwebzone.com"
    By excelwebzone, 6 years ago
  • Updated REAME
    By excelwebzone, 6 years ago
  • Fixed configuration class
    By excelwebzone, 6 years ago
  • Refactored DI Extension
    By excelwebzone, 6 years ago
  • Moved the bundle to EWZ\Bundle\SearchBundle
    By excelwebzone, 6 years ago
  • Moved the bundle to EWZ\Bundle\SearchBundle
    By excelwebzone, 6 years ago
  • Replaced symfony-project.org by symfony.com
    By excelwebzone, 6 years ago