{"id":13396204,"url":"https://github.com/mmanos/laravel-search","last_synced_at":"2025-04-13T00:48:48.822Z","repository":{"id":16885328,"uuid":"19645937","full_name":"mmanos/laravel-search","owner":"mmanos","description":"A search package for Laravel 5.","archived":false,"fork":false,"pushed_at":"2017-06-29T20:13:47.000Z","size":56,"stargazers_count":352,"open_issues_count":20,"forks_count":57,"subscribers_count":28,"default_branch":"master","last_synced_at":"2025-04-13T00:48:41.314Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mmanos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-05-10T16:19:27.000Z","updated_at":"2024-10-16T21:37:30.000Z","dependencies_parsed_at":"2022-08-25T11:50:43.981Z","dependency_job_id":null,"html_url":"https://github.com/mmanos/laravel-search","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmanos%2Flaravel-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmanos%2Flaravel-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmanos%2Flaravel-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mmanos%2Flaravel-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mmanos","download_url":"https://codeload.github.com/mmanos/laravel-search/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248650436,"owners_count":21139672,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-07-30T18:00:42.346Z","updated_at":"2025-04-13T00:48:48.804Z","avatar_url":"https://github.com/mmanos.png","language":"PHP","funding_links":[],"categories":["Popular Packages"],"sub_categories":[],"readme":"# Search Package for Laravel 5\n\nThis package provides a unified API across a variety of different full text search services. It currently supports drivers for [Elasticsearch](http://www.elasticsearch.org/), [Algolia](https://www.algolia.com/), and [ZendSearch](https://github.com/zendframework/ZendSearch) (good for local use).\n\n## Installation Via Composer\n\nAdd this to you composer.json file, in the require object:\n\n```javascript\n\"mmanos/laravel-search\": \"dev-master\"\n```\n\nAfter that, run composer install to install the package.\n\nAdd the service provider to `app/config/app.php`, within the `providers` array.\n\n```php\n'providers' =\u003e array(\n\t// ...\n\t'Mmanos\\Search\\SearchServiceProvider',\n)\n```\n\nAdd a class alias to `app/config/app.php`, within the `aliases` array.\n\n```php\n'aliases' =\u003e array(\n\t// ...\n\t'Search' =\u003e 'Mmanos\\Search\\Facade',\n)\n```\n\n## Laravel 4\n\nUse the `0.0` branch or the `v0.*` tags for Laravel 4 support.\n\n## Configuration\n\nPublish the default config file to your application so you can make modifications.\n\n```console\n$ php artisan vendor:publish\n```\n\n#### Dependencies\n\nThe following dependencies are needed for the listed search drivers:\n\n* ZendSearch: `zendframework/zendsearch`\n* Elasticsearch: `elasticsearch/elasticsearch`\n* Algolia: `algolia/algoliasearch-client-php`\n\n#### Default Index\n\nThis package provides a convenient syntax for working with a \"default\" index. Edit the `default_index` field in the config file to change this value. If you need to work with more than one index, see *Working With Multiple Indicies* below.\n\n## Indexing Operations\n\nIndexing is very easy with this package. Simply provide a unique identifier for the document and an associative array of fields to index.\n\nThe index will be **created automatically** if it does not exist the first time you access it.\n\n#### Index A Document\n\nAdd a document to the \"default\" index with an `id` of \"1\".\n\n```php\nSearch::insert(1, array(\n\t'title' =\u003e 'My title',\n\t'content' =\u003e 'The quick brown fox...',\n\t'status' =\u003e 'published',\n));\n```\n\n\u003e **Note:** `id` may be a string or an integer. This id is used to delete records and is also returned in search results.\n\n#### Store Extra Parameters With A Document\n\nYou may store extra parameters with a document so they can be retrieved at a later point from search results. This can be useful for referencing timestamps or other record identifiers.\n\n```php\nSearch::insert(\n\t\"post-1\",\n\tarray(\n\t\t'title' =\u003e 'My title',\n\t\t'content' =\u003e 'The quick brown fox...',\n\t\t'status' =\u003e 'published',\n\t),\n\tarray(\n\t\t'created_at' =\u003e time(),\n\t\t'creator_id' =\u003e 5,\n\t)\n);\n```\n\n\u003e **Note:** Extra parameters are not indexed but are stored in the index for future retrieval.\n\n#### Delete A Document\n\nDelete a document from the \"default\" index with an `id` of \"1\":\n\n```php\nSearch::delete(1);\n```\n\n#### Delete An Index\n\n```php\nSearch::deleteIndex();\n```\n\n## Search Operations\n\n#### Search For A Document\n\nSearch the \"default\" index for documents who's `content` field contains the word \"fox\":\n\n```php\n$results = Search::search('content', 'fox')-\u003eget();\n```\n\n#### Search More Than One Field\n\n```php\n$results = Search::search(array('title', 'content'), 'fox')-\u003eget();\n```\n\n#### Search All Fields\n\n```php\n$results = Search::search(null, 'fox')-\u003eget();\n```\n\n#### Perform A Fuzzy Search\n\nPerform a fuzzy search to find results with similar, but not exact, spelling. For example, you want to return documents containing the word \"updates\" by searching for the word \"update\":\n\n```php\n$results = Search::search('content', 'update', array('fuzzy'=\u003etrue))-\u003eget();\n```\n\n\u003e **Note:** You may also pass a numeric value between 0 and 1 for the fuzzy parameter, where a value closer to 1 requires a higher similarity. Defaults to 0.5.\n\n#### Apply A Filter To Your Query\n\nYou can apply filters to your search queries as well. Filters attempt to match the value you specify as an entire \"phrase\". \n\n```php\n$results = Search::search('content', 'fox')\n\t-\u003ewhere('status', 'published')\n\t-\u003eget();\n```\n\n\u003e **Note:** Filters do not guarantee an exact match of the entire field value if the value contains multiple words.\n\n#### Geo-Search\n\nSome drivers support location-aware searching:\n\n```php\n$results = Search::search('content', 'fox')\n\t-\u003ewhereLocation(36.16781, -96.023561, 10000)\n\t-\u003eget();\n```\n\nWhere the parameters are `latitude`, `longitude`, and `distance` (in meters).\n\n\u003e **Note:** Currently, only the `algolia` driver supports geo-searching. Ensure each indexed record contains the location information: `_geoloc =\u003e ['lat' =\u003e 1.23, 'lng' =\u003e 1.23]`.\n\n#### Limit Your Result Set\n\n```php\n$results = Search::search('content', 'fox')\n\t-\u003ewhere('status', 'published')\n\t-\u003elimit(10) // Limit 10\n\t-\u003eget();\n\n$results = Search::search('content', 'fox')\n\t-\u003ewhere('status', 'published')\n\t-\u003elimit(10, 30) // Limit 10, offset 30\n\t-\u003eget();\n```\n\n#### Paginate Your Result Set\n\nYou can also paginate your result set using a Laravel paginator instance.\n\n```php\n$paginator = Search::search('content', 'fox')-\u003epaginate(15);\n```\n\n#### Limit The Fields You Want Back From The Response\n\n```php\n$results = Search::select('id', 'created_at')\n\t-\u003esearch('content', 'fox')\n\t-\u003eget();\n```\n\n#### Chain Multiple Searches And Filters\n\n```php\n$results = Search::select('id', 'created_at')\n\t-\u003ewhere('title', 'My title')\n\t-\u003ewhere('status', 'published')\n\t-\u003esearch('content', 'fox')\n\t-\u003esearch('content', 'quick')\n\t-\u003elimit(10)\n\t-\u003eget();\n```\n\n\u003e **Note:** Chained filters/searches are constructed as boolean queries where each **must** provide a match.\n\n#### Delete All Documents That Match A Query\n\n```php\nSearch::search('content', 'fox')-\u003edelete();\n```\n\n## Working With Multiple Indicies\n\nIf you need to work with more than one index, you may access all of the same methods mentioned above after you specify the index name.\n\nAdd a document to an index called \"posts\":\n\n```php\nSearch::index('posts')-\u003einsert(1, array(\n\t'title' =\u003e 'My title',\n\t'content' =\u003e 'The quick brown fox...',\n\t'status' =\u003e 'published',\n));\n```\n\nSearch the \"posts\" index for documents who's `content` field contains the word \"fox\" and who's `status` is \"published\":\n\n```php\n$results = Search::index('posts')-\u003esearch('content', 'fox')\n\t-\u003ewhere('status', 'published')\n\t-\u003eget();\n```\n\nDelete a document from the \"posts\" index with an `id` of \"1\":\n\n```php\nSearch::index('posts')-\u003edelete(1);\n```\n\nDelete the entire \"posts\" index:\n\n```php\nSearch::index('posts')-\u003edeleteIndex();\n```\n\n## Advanced Query Callbacks\n\nIf you need more control over a search query you may add a callback function which will be called after all conditions have been added to the query but before the query has been executed. You can then make changes to the native query instance and return it to be executed.\n\n```php\n$results = Search::index('posts')-\u003eselect('id', 'created_at')\n\t-\u003esearch('content', 'fox')\n\t-\u003eaddCallback(function ($query) {\n\t\t// Make changes to $query...\n\t\treturn $query;\n\t})\n\t-\u003eget();\n```\n\nSince each driver has it's own native `$query` object/array, you may only want to execute your callback for one of the drivers:\n\n```php\n$results = Search::index('posts')-\u003eselect('id', 'created_at')\n\t-\u003esearch('content', 'fox')\n\t-\u003eaddCallback(function ($query) {\n\t\t// Adjust pagination for an elasticsearch query array.\n\t\t$query['from'] = 0;\n\t\t$query['size'] = 20;\n\t\treturn $query;\n\t}, 'elasticsearch')\n\t-\u003eget();\n```\n\n\u003e **Note:** You may also pass an array of drivers as the second parameter.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmanos%2Flaravel-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmmanos%2Flaravel-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmmanos%2Flaravel-search/lists"}