├── .devcontainer ├── Dockerfile └── devcontainer.json ├── .editorconfig ├── .github └── workflows │ └── psalm.yml ├── .gitignore ├── .prettierrc ├── .styleci.yml ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── composer.json ├── config └── scout-solr.php ├── deploy.sh ├── docs ├── .vuepress │ ├── config.js │ └── theme-config.js ├── README.md ├── api │ └── .gitkeep └── usage.md ├── package-lock.json ├── package.json ├── phpdoc.xml ├── psalm.xml ├── ruleset.xml └── src ├── Builder.php ├── Engines └── SolrEngine.php ├── HasSolrResults.php ├── ScoutSolrServiceProvider.php ├── Searchable.php └── SolrCollection.php /.devcontainer/Dockerfile: -------------------------------------------------------------------------------- 1 | # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/php/.devcontainer/base.Dockerfile 2 | 3 | # [Choice] PHP version: 8, 8.0, 7, 7.4, 7.3 4 | ARG VARIANT="8.0" 5 | FROM mcr.microsoft.com/vscode/devcontainers/php:0-${VARIANT} 6 | 7 | # [Choice] Node.js version: none, lts/*, 16, 14, 12, 10 8 | ARG NODE_VERSION="none" 9 | RUN if [ "${NODE_VERSION}" != "none" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi 10 | 11 | # [Optional] Uncomment this section to install additional OS packages. 12 | RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add - \ 13 | && echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list \ 14 | &&apt-get update && export DEBIAN_FRONTEND=noninteractive \ 15 | && apt-get -y install --no-install-recommends bash-completion -------------------------------------------------------------------------------- /.devcontainer/devcontainer.json: -------------------------------------------------------------------------------- 1 | // For format details, see https://aka.ms/devcontainer.json. For config options, see the README at: 2 | // https://github.com/microsoft/vscode-dev-containers/tree/v0.194.0/containers/php 3 | { 4 | "name": "Solr Engine for Laravel Scout", 5 | "build": { 6 | "dockerfile": "Dockerfile", 7 | "args": { 8 | // Update VARIANT to pick a PHP version: 8, 8.0, 7, 7.4, 7.3 9 | "VARIANT": "7", 10 | "NODE_VERSION": "lts/*" 11 | } 12 | }, 13 | // Set *default* container specific settings.json values on container create. 14 | "customizations": { 15 | "vscode": { 16 | "settings": { 17 | "php.validate.executablePath": "/usr/local/bin/php" 18 | }, 19 | // Add the IDs of extensions you want installed when the container is created. 20 | "extensions": [ 21 | "felixfbecker.php-debug", 22 | "neilbrayfield.php-docblocker", 23 | "bmewburn.vscode-intelephense-client", 24 | "esbenp.prettier-vscode" 25 | ] 26 | } 27 | }, 28 | // Use 'forwardPorts' to make a list of ports inside the container available locally. 29 | "forwardPorts": [8080], 30 | // Use 'postCreateCommand' to run commands after the container is created. 31 | // "postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html" 32 | "postCreateCommand": "npm install && composer install", 33 | // Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root. 34 | "remoteUser": "vscode" 35 | } 36 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | [*] 2 | end_of_line = lf 3 | insert_final_newline = true 4 | indent_style = space 5 | 6 | [*.php] 7 | indent_size = 4 8 | 9 | [*.js] 10 | indent_size = 2 -------------------------------------------------------------------------------- /.github/workflows/psalm.yml: -------------------------------------------------------------------------------- 1 | name: Psalm Static analysis 2 | 3 | on: [push, pull_request] 4 | 5 | jobs: 6 | psalm: 7 | name: Psalm 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout code 11 | uses: actions/checkout@v2 12 | - name: Psalm 13 | uses: docker://vimeo/psalm-github-actions 14 | with: 15 | security_analysis: true 16 | report_file: results.sarif 17 | - name: Upload Security Analysis results to GitHub 18 | uses: github/codeql-action/upload-sarif@v1 19 | with: 20 | sarif_file: results.sarif 21 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor 2 | composer.lock 3 | docs/.vuepress/dist 4 | node_modules 5 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 100, 3 | "tabWidth": 2, 4 | "singleQuote": true, 5 | "trailingComma": "es5", 6 | "overrides": [ 7 | { 8 | "files": "*.php", 9 | "options": { 10 | "tabWidth": 4, 11 | "singleQuote": true, 12 | "trailingCommaPHP": true 13 | } 14 | } 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /.styleci.yml: -------------------------------------------------------------------------------- 1 | preset: laravel 2 | 3 | disabled: 4 | - binary_operator_spaces 5 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to making participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account, or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at wskruse@gmail.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Will Kruse 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Solr Engine for Scout # 2 | 3 | [![Latest Stable Version](https://poser.pugx.org/pxslip/laravel-scout-solr/version?format=flat)](https://packagist.org/packages/pxslip/laravel-scout-solr) 4 | [![Latest Unstable Version](https://poser.pugx.org/pxslip/laravel-scout-solr/v/unstable?format=flat)](//packagist.org/packages/pxslip/laravel-scout-solr) 5 | [![Total Downloads](https://poser.pugx.org/pxslip/laravel-scout-solr/downloads?format=flat)](https://packagist.org/packages/pxslip/laravel-scout-solr) 6 | 7 | This engine provides the interface between Laravel Scout and a Solr instance. 8 | 9 | ## Installation ## 10 | 11 | `composer require pxslip/laravel-scout-solr` 12 | 13 | For Laravel <= 5.4 the service provider should be registered in `config/app.php` 14 | 15 | ```php 16 | 'providers' => [ 17 | // ...other providers 18 | Scout\Solr\ScoutSolrServiceProvider::class, 19 | ] 20 | ``` 21 | 22 | ## Usage ## 23 | 24 | As the engine uses some functionality that is not fully compatible with `Laravel\Scout\Builder` and `Laravel\Scout\Searchable` you will need to use the `Scout\Solr\Builder` and `Scout\Solr\Searchable` versions instead: 25 | 26 | ```php 27 | use Scout\Solr\Searchable; 28 | 29 | class MyModel extends Model { 30 | use Searchable; 31 | ... 32 | } 33 | 34 | // and then to perform a search 35 | 36 | MyModel::where(...) 37 | ->orWhere(...) 38 | ->facetField(...) 39 | ``` 40 | 41 | ## TO DO ## 42 | 43 | - [x] Add bindings instead of just passing the string for better escaping 44 | - [x] Add nested querying to Builder 45 | - [x] Add nested querying to ScoutEngine 46 | - [ ] Write tests 47 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "pxslip/laravel-scout-solr", 3 | "description": "A driver for the Laravel Scout search tools, using Apache Solr for the backend", 4 | "type": "library", 5 | "require": { 6 | "php": "^7.1", 7 | "laravel/scout": ">=5.0", 8 | "illuminate/support": ">=5.5", 9 | "solarium/solarium": "^4.2" 10 | }, 11 | "autoload": { 12 | "psr-4": { 13 | "Scout\\Solr\\": "src/", 14 | "Scout\\Solr\\Tests\\": "tests/" 15 | } 16 | }, 17 | "extra": { 18 | "laravel": { 19 | "providers": ["Scout\\Solr\\ScoutSolrServiceProvider"] 20 | } 21 | }, 22 | "license": "MIT", 23 | "authors": [ 24 | { 25 | "name": "Will Kruse", 26 | "email": "wskruse@gmail.com" 27 | } 28 | ], 29 | "require-dev": { 30 | "squizlabs/php_codesniffer": "^3.2", 31 | "vimeo/psalm": "^3.1" 32 | }, 33 | "minimum-stability": "stable", 34 | "prefer-stable": true 35 | } 36 | -------------------------------------------------------------------------------- /config/scout-solr.php: -------------------------------------------------------------------------------- 1 | 25, 16 | 17 | /* 18 | * Whether or not solr is enabled 19 | */ 20 | 'enabled' => env('SOLR_IMPORT', true), 21 | 22 | 'meta_key' => env('SOLR_META_KEY', 'meta'), 23 | 24 | /* 25 | |-------------------------------------------------------------------------- 26 | | Solr Endpoint 27 | |-------------------------------------------------------------------------- 28 | | 29 | | These values make up the endpoint of a given solr instance 30 | | The endpoint name should match the searchableAs value in a model 31 | | 32 | | 33 | */ 34 | 'endpoints' => [ 35 | 'endpoint_name' => [ 36 | 'host' => env('SOLR_HOST', 'localhost'), 37 | 'port' => env('SOLR_PORT', 8983), 38 | 'path' => env('SOLR_PATH', 'solr'), 39 | 'core' => env('SOLR_CORE', 'core'), 40 | ], 41 | ], 42 | ]; 43 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | # abort on errors 4 | set -e 5 | 6 | # build 7 | npm run docs:build 8 | 9 | # navigate into the build output directory 10 | cd docs/.vuepress/dist 11 | 12 | # if you are deploying to a custom domain 13 | # echo 'www.example.com' > CNAME 14 | 15 | git init 16 | git add -A 17 | git commit -m 'deploy' 18 | 19 | # if you are deploying to https://.github.io/ 20 | git push -f git@github.com:pxslip/laravel-scout-solr.git master:gh-pages 21 | 22 | cd - 23 | -------------------------------------------------------------------------------- /docs/.vuepress/config.js: -------------------------------------------------------------------------------- 1 | const themeConfig = require('./theme-config'); 2 | module.exports = { 3 | title: 'Laravel Scout Solr Engine', 4 | description: 'An implementation of a Scout engine for Apache Solr', 5 | themeConfig: themeConfig 6 | } 7 | -------------------------------------------------------------------------------- /docs/.vuepress/theme-config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | nav: [{ 3 | text: 'Home', 4 | link: '/' 5 | }, 6 | { 7 | text: 'Guide', 8 | link: '/guide' 9 | } 10 | ] 11 | } 12 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | --- 2 | home: true 3 | footer: MIT Licensed | Copyright © 2017-Present Will Kruse 4 | title: Home 5 | --- 6 | ## Introduction ## 7 | 8 | `laravel-scout-solr` provides a [Laravel Scout](https://github.com/laravel/scout) compatible engine for [Apache Solr](http://lucene.apache.org/solr/). 9 | 10 | ## Installation ## 11 | 12 | `laravel-scout-solr` is provided as a composer package so installation is as simple as 13 | 14 | ```bash 15 | composer require pxslip/laravel-scout-solr 16 | ``` 17 | 18 | For Laravel <= 5.4 register the Service provider in your `config/app.php` 19 | 20 | ```php 21 | 'providers' => [ 22 | ... 23 | Scout\Solr\ScoutSolrServiceProvider::class, 24 | ] 25 | ``` 26 | 27 | ## Usage ## 28 | 29 | As some functionality is not compatible with the base Scout Builder class, use the `Scout\Solr\Searchable` trait in place of the `Scout\Searchable` trait on your models 30 | 31 | ```php 32 | use Scout\Solr\Searchable; 33 | 34 | class MyModel extends Model { 35 | use Searchable; 36 | ... 37 | } 38 | ``` 39 | 40 | Searching is done the same as any other scout engine with some added functionality 41 | 42 | ```php 43 | MyModel::where(...) 44 | ->orWhere(...) 45 | ->facetField(...) 46 | ``` 47 | 48 | For more details take a look at [usage](/usage.html) 49 | -------------------------------------------------------------------------------- /docs/api/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/pxslip/laravel-scout-solr/56e2ca3ddfc096c88ddb55509ee1fc08f7b73126/docs/api/.gitkeep -------------------------------------------------------------------------------- /docs/usage.md: -------------------------------------------------------------------------------- 1 | --- 2 | footer: MIT Licensed | Copyright © 2017-Present Will Kruse 3 | title: Examples 4 | --- 5 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "laravel-scout-solr-site", 3 | "version": "0.1.0", 4 | "description": "", 5 | "main": "index.html", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1", 8 | "docs:dev": "vuepress dev docs", 9 | "docs:build": "vuepress build docs" 10 | }, 11 | "repository": { 12 | "type": "git", 13 | "url": "git+https://github.com/pxslip/laravel-scout-solr.git" 14 | }, 15 | "author": "Will Kruse ", 16 | "license": "MIT", 17 | "bugs": { 18 | "url": "https://github.com/pxslip/laravel-scout-solr/issues" 19 | }, 20 | "homepage": "https://pxslip.github.io/laravel-scout-solr", 21 | "devDependencies": { 22 | "eslint": "^7.28.0", 23 | "vuepress": "^1.8.2", 24 | "prettier": "^2.4.1", 25 | "@prettier/plugin-php": "^0.18.4" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /phpdoc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | Laravel Scout Solr Engine 4 | 5 | build 6 | 7 | 8 | docs 9 | 10 | 11 |