Download the PHP package becklyn/search-bundle without Composer

On this page you can find all versions of the php package becklyn/search-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 search-bundle

Search Bundle

Installation

  1. First install the bundle via composer:

  2. Load the bundle in your AppKernel

Configuration

Entity annotations

Marking a class for indexing

For regular entities just mark the class with the annotation and implement the SearchableEntityInterface interface:

For localized entities, mark the class and implement the LocalizedSearchableEntityInterface interface:

Note: you will need the LanguageInterface from the becklyn/interfaces package.

@Search\Item() annotation

Property Description
index The name of the index. If none is given, the name is automatically generated from the FQCN of the class.
loader The custom entity loader. Please refer to the chapter about entity loaders to learn more.
autoIndex (Default true) Whether the searchable item should be indexed automatically whenever it's persisted or updated in Doctrine. Learn more

Marking a field / getter for indexing

Please note that a protected / private property test needs to have a way to access it, either via getter getTest(), isser isTest() or hasser hasTest().

@Search\Field() annotation

Property Description
weight The value with which this field is boosted when searching.
fragments The number of highlight fragments returned when searching. null returns the complete text of the hit.
format The format of this field. Defines which format_processor is used to manipulate the property/getter value.

App configuration

The config belongs in app/config.yml.

A full configuration example:

Key Description
server (required) The DSN to connect to the server.
index (required) The pattern with which the index names are generated. The {language} placeholder must be included and will be replace with the language code.
format_processors Processors for different text formats. If a field with a given processor is indexed, the processor is called and html_post_processed, if it is selected. This will clean up the HTML (a better version of strip_tags), so that the processor can transform the format to HTML (and have it transformed to plain text afterwards). Default for html_post_process is false.
analyzers A list of custom analyzers. The syntax mirrors the Elasticsearch API.
filters A list of custom filters. The syntax mirrors the Elasticsearch API.
unlocalized The definition for all unlocalized entities. Currently only the selection of custom analyzers is possible.
localized The configuration for localized entities in every language. Currently only the selection of custom analyzers is possible.

Usage

Searching

Just get the becklyn.search.client service and search with it:

The method has three parameters:

Argument Type Description
query string The query string to search for.
language LanguageInterface|null The language with which the items should be searched. If at least one item is localized, this parameter is required.
itemClasses string[] The FQCN of the entities, that should be searched. If no explicit entity class is given, all (indexed) entities are searched.
filters string[] The filter values. See the chapter about Filtering for details.

Indexing

You can either index an entity manually via a CLI command, by calling a concrete service, or automatically by using the built-in doctrine event listeners.

Automatic indexing

Doctrine-managed entities are by default automatically indexed upon persistence/updating due to an built-in doctrine lifecycle event listener.

Disabling automatic indexing

The Becklyn\SearchBundle\Mapping\Item annotation allows you to configure how a search item is indexed. By default annotated classes will be indexed automatically whenever it's persisted or updated in Doctrine.

For use cases where you don't want your entities to be indexed immediatelly, e.g. when it needs further processing, you can set Becklyn\SearchBundle\Mapping\Item#autoIndex to false. This will force the Doctrine lifecycle handler to skip the automatic index update for this entity.

Warning This shifts the responsibility of indexing an entity from the bundle's code into the application's code by invoking the becklyn.search.indexer.

Or by running the Symfony CLI becklyn:search:index command. The index command isn't affected by this option.

Manual indexing

CLI command indexing

To (re-)index your entities from the CLI, the becklyn/search-bundle exposes the becklyn:search:index command. For more commands please see the CLI commands section.

The becklyn:search:index command indexes all entities irregardless of the autoIndex setting.

Programatic indexing

If you want to index programatically, just retrieve an instance of the becklyn.search.indexer service and call the index method:

Modifying the indexed data

The indexed data can be modified by listening to the "becklyn_search.index" event (or Becklyn\SearchBundle\Event\IndexEntityEvent::EVENT).

Your listener receives an Becklyn\SearchBundle\Event\IndexEntityEvent with the already serialized data and the entity to serialize:

For now, the listener has to know the internal field name, unfortunately. This will be improved in a future version.

Entity Loader

A search item can define a custom entity loader:

If a custom loader is defined, the service is fetched and the method called. The loader syntax translates to a call like this:

The method must have an optional array parameter. If the loader is called with null, all entities should be returned. If the loader is called with int[], only the entities with an id in the int array have to be loaded.

It is not required to load entities for all provided ids, as the missing search results will just be removed from the result list.

The loader must return an EntityLoaderResult.

Filtering

In some cases the searched items should be filtered by a field other than the language.

The annotation has a single required attribute: the name of the filter. This name needs to be unique across the app.

When searching, you can filter for hits with this specific filter values like this:

CLI Commands

The bundle exposes multiple CLI commands.

Command Description
becklyn:search:client Search directly from the CLI
becklyn:search:debug Shows various debug output and tests connection to the ElasticSearch
becklyn:search:index (Re-)indexes all entities
becklyn:search:metadata (Re-)generates and caches entity metadata

For additional parameters and options for each command, please directly consult the commands help, e.g. php bin/console becklyn:search:client --help.


All versions of search-bundle with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
becklyn/search-text-transformer Version ^2.0.0
doctrine/common Version ^3.4.2
doctrine/doctrine-bundle Version ^2.7.0
doctrine/orm Version ^2.13.4
elasticsearch/elasticsearch Version v8.5.3
symfony/cache Version ^v6.2.0
symfony/console Version v6.2.1
symfony/dependency-injection Version v6.2.1
symfony/event-dispatcher Version v6.2.0
symfony/framework-bundle Version v6.2.1
symfony/monolog-bundle Version ^v3.8.0
symfony/property-access Version ^v6.2.0
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 becklyn/search-bundle contains the following files

Loading the files please wait ....