Download the PHP package winter/wn-search-plugin without Composer

On this page you can find all versions of the php package winter/wn-search-plugin. 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 wn-search-plugin

Search Plugin

Build Status MIT License Discord

Adds full-text searching capabilities to Winter, built on the foundations of Laravel Scout. The plugin acts primarily as a wrapper for Laravel Scout, and provides its entire suite of functionality within Winter's architecture, but also includes additional capabilities to make its use in Winter even easier.

Requirements

Getting started

To install the plugin, you may install it through the Winter CMS Marketplace, or you may install it using Composer:

Then, run the migrations to ensure the plugin is enabled:

Configuration

Configuration for this plugin is chiefly done through the search.php configuration file. You can publish this configuration into your project's config directory by running the following command:

This will create your own configuration file at config/winter/search/search.php, in which you will be able to override all default configuration values.

Preparing your models

As this is a wrapper, you can use all the base functionality that Laravel Scout provides. There are only a couple of subtle differences with the Search plugin's implementation:

To make a particular database model searchable, you simply add the Winter\Search\Behaviors\Searchable behavior to that model. This behavior will register a model observer that will automatically synchronise the model records to an index:

For Halcyon models, you must instead use the Winter\Search\Behaviors\Halcyon\Searchable behavior, in order to correctly hook into the unique functionality that Halcyon provides.

As the model is created, updated or deleted, the index will automatically be updated to reflect the state of that model record.

Configuring searchable data

By default, the entire model is converted to an array form and persisted in the search index. If you would like to limit the data that is stored in the index, you can provide a $searchable property in the model. This property will represent all the model attributes that you would like to store in the index:

If you want even more control over the data, you may override the toSearchableArray method:

Adding search to third-party models

You can add search functionality to third-party plugins through use of the Dynamic Class Extension functionality in Winter. This can be done through your Plugin.php registration file, generally within the boot() method.

When extending a model in this fashion, you will also likely need to specify the searchable data you wish to include in your search index, using the $searchable property or toSearchableArray() method specified previously.

Configuring the model ID

Normally, the primary key of the model will act as the model's unique ID that is stored in the search index. If you wish to use another column to act as the identifier for a model, you may override the getSearchKey and getSearchKeyName methods to customise this behaviour.

NOTE: Some search providers, such as Meilisearch, enforce restrictions on the characters allowed for IDs. To be safe, we recommend that you restrict IDs to using the following characters: A-Z, a-z, 0-9 and dashes and underscores. Any other characters may prevent some search providers from indexing your record.

Registering search handlers

Once your models are prepared for searching capabilities, you may register a search handler that allows the models to be searched by the included components.

Registration of a search handler takes place in your Plugin.php file by specifying a registerSearchHandlers method that returns an array.

Each array item should specify a key name that represents the ID of the search handler. The following properties can be specified as part of the handler:

Property Description
name The human-readable name of your search handler. This will be used for grouped results.
model The name of the class you wish to search with this handler.
record A handler for each record returned in the results. See below for more information on the valid configurations for this property.

Record handler

Each search handler may also provide a result handler to finely tune how you wish to display or filter the results. At its most simplest, the record handler simply expects an array to be returned for each record that contains 3 properties:

It may also optionally provide the following properties to provide more context:

You may, of course, define additional properties in your array.

The record handler can be configured in a number of different ways.

Array map of fields

You can simply return an array with the properties above that map to the corresponding fields within the model.

Array map with callbacks

Similar to the above, you may also specify some or all properties to use a callback method that will be fed two arguments: the model instance of each result, and the original query.

Callback method

You may also make the entire handler go through a callback method. This gives the greatest level of control, as you may also filter records out.

The callback method should always return an array with the main properties defined above, but you may include any additional properties as you wish.

The callback method may also return false to exclude the record from the results.

Result relevancy

By default, results in the Search plugin are not ordered in any particular way to account for the relevancy of the result. While this may be fine in cases where you are using index engines like Algolia or Meilisearch, which have their own relevancy algorithms (or can be configured as such), this may affect the results when using the Database and Collection index engines, which have no relevancy system.

In order to support a level of relevancy in these engines, results can be post-processed after being retrieved from the index to assign a relevancy score. Relevancy in this system is determined by the order of the property names in the $searchable definition for the index.

For example, with the below definition:

The title field will be the most relevant field, followed by the description and then keywords. A match in the title is given greater weight than a match in the description, which is given more weight than a match in the keywords.

The relevancy scoring also takes into account the words used in the query. For example, if the query install winter cms was used, the word install is given more weight than winter, which is then given more weight than the word cms.

To enable result relevancy, you may call the getWithRelevance() or firstRelevant() methods following any search:

getWithRelevance() will retrieve all records, ordered by relevancy score, whilst firstRelevant() will retrieve only the most relevant record.

If you wish to customise the relevancy scoring, you may also provide a callable to both methods. The callable must accept two arguments, a model instance, and an array of words from the query, and return a score as a float or an int, which will be used to order the results descendingly (higher score = more relevant). Each record found in the index will be run through this callable.


All versions of wn-search-plugin with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
composer/installers Version ~1.0
laravel/scout Version ^9.4.5
teamtnt/tntsearch Version ^4.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 winter/wn-search-plugin contains the following files

Loading the files please wait ....