Download the PHP package pdphilip/elasticlens without Composer

On this page you can find all versions of the php package pdphilip/elasticlens. 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 elasticlens

ElasticLens for Laravel

[![Latest Version on Packagist](https://img.shields.io/packagist/v/pdphilip/elasticlens.svg?style=flat-square)](https://packagist.org/packages/pdphilip/elasticlens) [![GitHub Tests Action Status](https://img.shields.io/github/actions/workflow/status/pdphilip/elasticlens/run-tests.yml?branch=main&label=tests&style=flat-square)](https://github.com/pdphilip/elasticlens/actions?query=workflow%3Arun-tests+branch%3Amain) [![GitHub Code Style Action Status](https://img.shields.io/github/actions/workflow/status/pdphilip/elasticlens/fix-php-code-style-issues.yml?branch=main&label=code%20style&style=flat-square)](https://github.com/pdphilip/elasticlens/actions?query=workflow%3A"Fix+PHP+code+style+issues"+branch%3Amain) [![Total Downloads](http://img.shields.io/packagist/dt/pdphilip/elasticlens.svg)](https://packagist.org/packages/pdphilip/elasticlens)

Search your Laravel models with the convenience of Eloquent and the power of Elasticsearch

ElasticLens for Laravel uses Elasticsearch to create and sync a searchable index of your Laravel models.

ElasticLens Migrate

Wait, isn't this what Laravel Scout does?

Yes, but mostly no.

ElasticLens is built from the ground up around Elasticsearch.

It integrates directly with the Laravel-Elasticsearch package (Elasticsearch using Eloquent), creating a dedicated Index-Model that is fully accessible and automatically synced with your Base-Model.

How? > The `Index-Model` acts as a separate Elasticsearch model managed by ElasticLens, yet you retain full control over it, just like any other Laravel model. In addition to working directly with the `Index-Model`, ElasticLens offers tools for > mapping fields (with embedding relationships) during the build process, and managing index migrations. > For Example, a base `User` Model will sync with an Elasticsearch `IndexedUser` Model that provides all the features from [Laravel-Elasticsearch](https://github.com/pdphilip/laravel-elasticsearch) to search your `Base-Model`.

Requirements

Installation

NB: Before you start, set the Laravel-Elasticsearch DB Config (click to expand) > See [Laravel-Elasticsearch](https://github.com/pdphilip/laravel-elasticsearch) for more details > > Update `.env` > Update `config/database.php`

Install the package via composer:

Publish the config file:

Run the migrations to create the index build and migration logs indexes:

Read the Documentation

Features

Example Usage

The Walkthrough below will demonstrate all the features by way of an example. In this example, we'll index a User model.

Step 1: Zero config setup

Docs → Indexing your Base-Model

1. Add the Indexable Trait to Your Base-Model:

2. Create an Index-Model for Your Base-Model:

ElasticLens expects the Index-Model to be named as Indexed + BaseModelName and located in the App\Models\Indexes directory.

2(a) Create the User index with artisan:

2(b) or create the User index directly:

Step 2: Search your models

Docs → Full-text base-model search

Perform quick and easy full-text searches:

Search for the phrase loves espressos across all fields and return the base User models

Cute. But that's not why we're here...

To truly harness the power of Laravel-Elasticsearch for eloquent-like querying, you can use more advanced queries:

Examples:

1. Basic Term Search:

This searches all users who are active for the term 'nara' across all fields and returns the top 3 results.

2. Phrase Search:

Searches all fields for the phrase 'Ice bathing' and returns the three newest results. Phrases match exact words in order.

3. Boosting Terms fields:

Searches for the term 'David', boosts the first_name field by 3, last_name by 2, and checks the bio field. Results are ordered by score.

4. Geolocation Filtering:

Finds all active users within a 5km radius from the coordinates [0, 0], ordering them from closest to farthest. Not kidding.

5. Regex Search:

Finds all users whose favourite colour is blue or black.

6. Pagination:

Paginate search results.

7. Nested Object Search:

Searches nested user_logs for users who logged in from Norway within the last week. Whoa.

8. Fuzzy Search:

No spell, no problem. Search Fuzzy.

9. Highlighting Search Results:

Searches for 'espresso' across all fields and highlights where it was found.

10. Phrase prefix search:

Searches for the phrase prefix 'loves espr' across all fields and highlights where it was found.

Note on Index-Model vs Base-Model Results

To search and return results as Base-Models:

1. use asBase()

2. use getBase() instead of get()->asBase()

To search and paginate results as Base-Models use: paginateBase()

Step 3: Create a field Map

Docs → Index-model field mapping

You can define the fieldMap() method in your Index-Model to control how the index is built during synchronisation.

Notes:

Step 4: Update fieldMap() to include relationships as embedded fields

Docs → Relationships as embedded fields

You can further customise indexing by embedding relationships as nested objects within your Index-Model. The builder allows you to define fields and embed relationships, enabling more complex data structures in your Elasticsearch index.

Examples:

  1. If a User has many Profiles

  2. If a Profile has one ProfileStatus

  3. If a User belongs to an Account

  4. If a User belongs to a Country and you don't need to observe the Country model:

  5. If a User has Many UserLogs and you only want to embed the last 10:

IndexField $field Methods:

Note: For embeds the $whereRelatedField, $equalsLocalField, $query parameters are optional.

Embedded Relationship Builder Methods:

Step 5: Define your Index-Model's migrationMap()

Docs → Index-model migrations

Elasticsearch automatically indexes new fields it encounters, but it might not always index them in the way you need. To ensure the index is structured correctly, you can define a migrationMap() in your Index-Model.

Since the Index-Model utilises the Laravel-Elasticsearch package, you can use IndexBlueprint to customise your migrationMap()

Notes:

This command will delete the existing index, run the migration, and rebuild all records.

Step 6: Fine-tune the Observers

Docs → Base Model Observers

By default, the Base Model is observed for changes (saves) and deletions. When the Base Model is deleted, the corresponding Index Model will also be deleted, even in cases of soft deletion.

Handling Embedded Models

The related models are also observed when you define a fieldMap() with embedded fields. For example:

However, to ensure these observers are loaded, you need to reference the User model explicitly:

Customising Observers

If you want ElasticLens to observe ProfileStatus without requiring a reference to User, follow these steps:

  1. Add the HasWatcher Trait to ProfileStatus:

  2. Define the Watcher in the elasticlens.php Config File:

Disabling Base-Model Observation

If you want to disable the automatic observation of the Base-Model, include the following in your Index-Model:


Step 7: Monitor and administer all your indexes with Artisan commands

Docs → Artisan CLI Tools

Use the following Artisan commands to manage and monitor your Elasticsearch indexes:

  1. Check Overall Status:

Displays the overall status of all your indexes and the ElasticLens configuration.

ElasticLens Build
  1. Check Index Health:
ElasticLens Build

Provides a comprehensive state of a specific index, in this case, for the User model.

  1. Migrate and Build/Rebuild an Index:

Deletes the existing User index, runs the migration, and rebuilds all records.

ElasticLens Migrate
  1. Create a New Index-Model for a Base-Model:

Generates a new index for the Profile model.

ElasticLens Build
  1. Bulk (Re)Build Indexes for a Base-Model:

Rebuilds all the IndexedProfile records for the Profile model.

ElasticLens Build

Step 8: Optionally access the built-in IndexableBuild model to track index build states

Docs → Accessing IndexableBuild model

ElasticLens includes a built-in IndexableBuild model that allows you to monitor and track the state of your index builds. This model records the status of each index build, providing you with insights into the indexing process.

Fields ### Model Fields: - string `$model`: The Base-Model being indexed. - string `$model_id`: The ID of the Base-Model. - string `$index_model`: The corresponding Index-Model. - string `$last_source`: The last source of the build state. - IndexableStateType `$state`: The current state of the index build. - array `$state_data`: Additional data related to the build state. - array `$logs`: Logs of the indexing process. - Carbon `$created_at`: Timestamp of when the build state was created. - Carbon `$updated_at`: Timestamp of the last update to the build state. ### Attributes: - @property-read string `$state_name`: The name of the current state. - @property-read string `$state_color`: The colour associated with the current state.

Built-in methods include:

Note: While you can query the IndexableBuild model directly, avoid writing or deleting records within it manually, as this can interfere with the health checks and overall integrity of the indexing process. The model should be used for reading purposes only to ensure accurate monitoring and reporting.


Step 9: Optionally Access the Built-in IndexableMigrationLog Model for Index Migration Status

Docs → Access IndexableMigrationLog model

ElasticLens includes a built-in IndexableMigrationLog model for monitoring and tracking the state of index migrations. This model logs each migration related to an Index-Model.

Fields - string `$index_model`: The migrated Index-Model. - IndexableMigrationLogState `$state`: State of the migration - array `$map`: Migration map passed to Elasticsearch. - int `$version_major`: Major version of the indexing process. - int `$version_minor`: Minor version of the indexing process. - Carbon `$created_at`: Timestamp of when the migration was created. ### Attributes: - @property-read string `$version`: Parsed version, ex v2.03 - @property-read string `$state_name`: Current state name. - @property-read string `$state_color`: Colour representing the current state.

Built-in methods include:

Note: While you can query the IndexableMigrationLog model directly, avoid writing or deleting records within it manually, as this can interfere with versioning of the migrations. The model should be used for reading purposes only, to ensure accuracy.


Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of elasticlens with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^10.0||^11.0||^12.0
pdphilip/elasticsearch Version ^5.0.2
pdphilip/omniterm Version ^1.0.5
spatie/laravel-package-tools Version ^1.16
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 pdphilip/elasticlens contains the following files

Loading the files please wait ....