Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Aug 19, 2024
0 parents commit 071cedb
Show file tree
Hide file tree
Showing 23 changed files with 854 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false

[*.{yml,yaml}]
indent_size = 2

[docker-compose.yml]
indent_size = 4

[*.{js,vue}]
indent_size = 4
33 changes: 33 additions & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: '🐛 Bug Report'
description: "Found a bug or something that's not quite working like it should? Open an issue."
labels: [bug]
body:
- type: markdown
attributes:
value: Thanks for taking the time to submit a bug report! Please fill out the fields with as much detail as possible, so we can get to the bottom of the issue as quickly as possible.
- type: textarea
attributes:
label: Description
description: "What's happening? What are you expecting to happen?"
validations:
required: true
- type: textarea
attributes:
label: Steps to reproduce
placeholder: |
1. Do this thing...
2. Then do that thing...
3. And finally, do something else...
validations:
required: true
- type: textarea
attributes:
label: Environment
description: Copy & paste the output of `php please support:details` here.
validations:
required: true
- type: input
attributes:
label: Typesense Version
validations:
required: true
8 changes: 8 additions & 0 deletions .github/ISSUE_TEMPLATE/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
blank_issues_enabled: false
contact_links:
- name: '🙏 Help'
url: https://github.com/statamic-rad-pack/typesense/discussions/new
about: 'Have a question? Need help troubleshooting? Open a discussion.'
- name: '💡 Feature Requests'
url: https://github.com/statamic-rad-pack/typesense/discussions/new
about: 'Have any idea for a new feature or enhancements to an existing one? Open a discussion.'
28 changes: 28 additions & 0 deletions .github/workflows/pint-fix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Fix PHP code style issues

on:
push:
paths:
- '**.php'

permissions:
contents: write

jobs:
fix-php-code-styling:
runs-on: ubuntu-latest
if: github.repository_owner == 'statamic-rad-pack'

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Fix PHP code style issues
uses: aglipanci/[email protected]

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
20 changes: 20 additions & 0 deletions .github/workflows/pint-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Lint PHP code style issues

on:
pull_request:
paths:
- '**.php'

jobs:
lint-php-code-styling:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Check PHP code style issues
uses: aglipanci/[email protected]
with:
testMode: true
verboseMode: true
75 changes: 75 additions & 0 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
name: Tests

on: [push, pull_request]

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
runs-on: ${{ matrix.os }}

services:
typesense:
image: typesense/typesense:27.0.rc21
ports:
- 8108:8108/tcp
volumes:
- /tmp/typesense-server-data:/data
env:
TYPESENSE_DATA_DIR: /data
TYPESENSE_API_KEY: xyz
TYPESENSE_ENABLE_CORS: true

strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
php: [8.2, 8.1]
laravel: [10.*, 9.*]
statamic: [4.*, 3.4.*, 3.3.*]
dependency-version: [prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 9.*
testbench: 7.*
exclude:
- laravel: 10.*
statamic: 3.4.*
- laravel: 10.*
statamic: 3.3.*
php: 8.2
- laravel: 10.*
statamic: 3.3.*
php: 8.1
- laravel: 9.*
statamic: 3.3.*
php: 8.2

name: P${{ matrix.php }} - L${{ matrix.laravel }} - S${{ matrix.statamic }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: fileinfo, dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, bcmath, soap, intl, gd, exif, iconv, imagick
coverage: none

- name: Setup Problem Matches
run: |
echo "::add-matcher::${{ runner.tool_cache }}/php.json"
echo "::add-matcher::${{ runner.tool_cache }}/phpunit.json"
- name: Install dependencies
run: |
composer require "statamic/cms:${{ matrix.statamic }}" "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench-core:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction
- name: Execute tests
run: vendor/bin/phpunit
29 changes: 29 additions & 0 deletions .github/workflows/update-changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: "Update Changelog"

on:
release:
types: [released]

jobs:
update:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v2
with:
ref: main

- name: Update Changelog
uses: stefanzweifel/changelog-updater-action@v1
with:
latest-version: ${{ github.event.release.name }}
release-notes: ${{ github.event.release.body }}
compare-url-target-revision: ${{ github.event.release.target_commitish }}

- name: Commit updated CHANGELOG
uses: stefanzweifel/git-auto-commit-action@v4
with:
branch: main
commit_message: Update CHANGELOG
file_pattern: CHANGELOG.md
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.idea
/vendor
.DS_Store
composer.lock
.php-cs-fixer.cache
build/report.junit.xml
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Changelog

All notable changes to this project will be documented in this file.

## v1.0.0 (2024-08-19)

1. Initial release
32 changes: 32 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Contributing

Contributions are **welcome** and will be fully **credited**.

We accept contributions via Pull Requests on [Github](https://github.com/statamic-rad-pack/typesense).


## Pull Requests

- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

- **Add tests!** - Your patch won't be accepted if it doesn't have tests.

- **Document any change in behaviour** - Make sure the `README.md` and any other relevant documentation are kept up-to-date.

- **Consider our release cycle** - I try to follow [SemVer v2.0.0](http://semver.org/). Randomly breaking public APIs is not an option.

- **Create feature branches** - Don't ask me to pull from your master branch.

- **One pull request per feature** - If you want to do more than one thing, send multiple pull requests.

- **Send coherent history** - Make sure each individual commit in your pull request is meaningful. If you had to make multiple intermediate commits while developing, please [squash them](http://www.git-scm.com/book/en/v2/Git-Tools-Rewriting-History#Changing-Multiple-Commit-Messages) before submitting.


## Running Tests

``` bash
vendor/bin/phpunit
```


**Happy coding**!
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Statamic Rad Pack

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
99 changes: 99 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# Statamic Typesense Driver

This addon provides a [Typesense](https://typesense.org) search driver for Statamic sites.

## Requirements

* PHP 8.2+
* Laravel 10+
* Statamic 5
* Typesense 0.2+

### Installation

```bash
composer require statamic-rad-pack/typesense
```

Add the following variables to your env file:

```txt
TYPESENSE_HOST=http://127.0.0.1
TYPESENSE_API_KEY=
```

Add the new driver to the `statamic/search.php` config file:

```php
'drivers' => [

// other drivers

'typesense' => [
'drivers' => [

// other drivers

'typesense' => [
'client' => [
'api_key' => env('TYPESENSE_API_KEY', 'xyz'),
'nodes' => [
[
'host' => env('TYPESENSE_HOST', 'localhost'),
'port' => env('TYPESENSE_PORT', '8108'),
'path' => env('TYPESENSE_PATH', ''),
'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
],
],
'nearest_node' => [
'host' => env('TYPESENSE_HOST', 'localhost'),
'port' => env('TYPESENSE_PORT', '8108'),
'path' => env('TYPESENSE_PATH', ''),
'protocol' => env('TYPESENSE_PROTOCOL', 'http'),
],
'connection_timeout_seconds' => env('TYPESENSE_CONNECTION_TIMEOUT_SECONDS', 2),
'healthcheck_interval_seconds' => env('TYPESENSE_HEALTHCHECK_INTERVAL_SECONDS', 30),
'num_retries' => env('TYPESENSE_NUM_RETRIES', 3),
'retry_interval_seconds' => env('TYPESENSE_RETRY_INTERVAL_SECONDS', 1),
],
],
],
```

You can optionally publish the config file for this package using:

```
php artisan vendor:publish --tag=statamic-typesense-config
```

### Search Settings

Any additional settings you want to define per index can be included in the `statamic/search.php` config file. The settings will be updated when the index is created.

```php
'articles' => [
'driver' => 'typesense',
'searchables' => ['collection:articles'],
'fields' => ['id', 'title', 'url', 'type', 'content', 'locale'],
'settings' => [
'schema' => [
/* pass an optional schema, see: https://typesense.org/docs/26.0/api/collections.html#with-pre-defined-schema
'fields' => [
[
'name' => 'company_name',
'type' => 'string'
],
[
'name' => 'num_employees',
'type' => 'int32'
],
[
'name' => 'country',
'type' => 'string',
'facet' => true
],
], */
],
],
],
```
Loading

0 comments on commit 071cedb

Please sign in to comment.