Skip to content

Commit

Permalink
Merge pull request #1 from trendwerk/base
Browse files Browse the repository at this point in the history
Base development
  • Loading branch information
haroldangenent committed Feb 16, 2017
2 parents 1ba7509 + 5d2f3d2 commit c123f12
Show file tree
Hide file tree
Showing 17 changed files with 826 additions and 163 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -22,7 +22,6 @@ matrix:
env: WP_VERSION=latest WP_MULTISITE=1

before_script:
- bash bin/install-wp-tests.sh wordpress_test root '' localhost $WP_VERSION
- composer install

script:
Expand Down
75 changes: 73 additions & 2 deletions README.md
@@ -1,2 +1,73 @@
# search
Basic extensions for searching in WordPress.
# Search
[![Build Status](https://travis-ci.org/trendwerk/search.svg?branch=master)](https://travis-ci.org/trendwerk/search) [![codecov](https://codecov.io/gh/trendwerk/search/branch/master/graph/badge.svg)](https://codecov.io/gh/trendwerk/search)

Basic extensions for searching in WordPress. Currently only supports searching in `postmeta`.

Quick links: [Install](#install) | [Usage](#usage) | [Dimensions](#dimensions) | [Example](#example)

_Note: This basic extension is not very scalable and meant for smaller databases. This package could get slow for complex meta searches. In that case, [Elasticsearch](https://www.elastic.co/) would be a better solution._

## Install
```sh
composer require trendwerk/search
```

## Usage

1. [Initialize package](#initialize)
2. [Add search dimension(s)](#dimensions)

### Initialize

```php
$search = new \Trendwerk\Search\Search();
$search->init();
```

This code should be run when bootstrapping your theme.

### Dimensions
Currently this package only supports metadata as a search dimension. Dimensions can be added by using `addDimension`:

```php
$search->addDimension($dimension);
```

| Parameter | Default | Required | Description |
| :--- | :--- | :--- | :--- |
| `$dimension` | `null` | Yes | Should be an instance of a class that implements [`Dimension\Dimension`](https://github.com/trendwerk/search/blob/master/src/Dimension/Dimension.php).

### Meta
```php
$metaDimension = new \Trendwerk\Search\Dimension\Meta([
'key' => 'firstName',
]);

$search->addDimension($metaDimension);
```

Available options for constructing an instance of `Meta`:

| Parameter | Default | Required | Description |
| :--- | :--- | :--- | :--- |
| `key` | `null` | Yes | The `meta_key` to search for
| `compare` | `=` | No | The database comparison that should be made for the meta key. Currently supports `LIKE` and `=`. When using `LIKE`, make sure to include a percent symbol (`%`) in your `key` parameter as a wildcard. See [Example](#example)

## Example

```php
use Trendwerk\Search\Dimension\Meta;
use Trendwerk\Search\Search;

$search = Search();
$search->init();

$search->addDimension(new Meta($wpdb, [
'compare' => 'LIKE',
'key' => 'lastNames%',
]));

$search->addDimension(new Meta($wpdb, [
'key' => 'firstName',
]));
```
127 changes: 0 additions & 127 deletions bin/install-wp-tests.sh

This file was deleted.

3 changes: 2 additions & 1 deletion composer.json
Expand Up @@ -24,6 +24,7 @@
},
"require-dev": {
"phpunit/phpunit": "5.7.*",
"squizlabs/php_codesniffer": "2.*"
"squizlabs/php_codesniffer": "2.*",
"10up/wp_mock": "dev-master"
}
}

0 comments on commit c123f12

Please sign in to comment.