Giter Site home page Giter Site logo

the-cc-dev / acf-elasticsearch Goto Github PK

View Code? Open in Web Editor NEW

This project forked from makeandship/acf-elasticsearch

0.0 1.0 0.0 951 KB

Plugin for Elasticsearch indexing and searching of Wordpress sites using ACF

Home Page: https://www.makeandship.com

License: MIT License

PHP 93.50% Shell 1.39% CSS 2.93% JavaScript 2.18%

acf-elasticsearch's Introduction

acf-elasticsearch

Improve wordpress search performance/accuracy and enable secure search against ElasticSearch server with searchguard plugin.

Installation

  1. Upload plugin folder to the /wp-content/plugins/ directory
  2. Activate the plugin through the 'Plugins' menu in WordPress
  3. Click the 'ElasticSearch' menu item and follow the instructions on each section to configure the plugin. (be sure to save on each section)
  4. If you are using searchguard, define your private username and password.
  5. Select "Save" on "Server Settings" when you are ready for it to go live.

Tests

  1. Install phpunit
wget https://phar.phpunit.de/phpunit-6.2.phar
chmod +x phpunit-6.2.phar
sudo mv phpunit-6.2.phar /usr/local/bin/phpunit
  1. Create mysql test user
mysql -u root
CREATE USER 'es_plugin_test'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'es_plugin_test'@'localhost';
  1. Setup the test environment (Run it after each system restart)
bash bin/install-wp-tests.sh wordpress_test es_plugin_test 'password' 127.0.0.1 latest
  1. Start local elasticsearch server
brew services start elasticsearch
  1. Run the tests

    5.1. singlesite tests

    phpunit
    

    5.2. multisite tests

    phpunit -c phpunit-multisite.xml
    
  2. Configuration

In the wordpress admin console, go to Settings->ACF Elasticsearch to configure the plugin:

6.1. Enter the server address in Server field (address must be terminated by /) e.g. https://your-es-host:9200/

6.2. Enter the primary index to be created by the plugin in the Primary Index field

6.3. Enter the secondary index to be created by the plugin in the Secondary Index field (secondary index will be used when the primary is indexing)

6.4. Enter the private primary index to be created by the plugin in the Private Primary Index field (private primary index will contain all the data including private objects and fields).

6.5. Enter the private secondary index to be created by the plugin in the Private Secondary Index field (private secondary index will be used when the private primary is indexing).

6.6. Read/Write timeouts are configured in the Read Timeout and Write Timeout fields respectively.

6.7. If you are using searchguard or any other security plugin in your elasticsearch cluster, enter the username and password in the Username and Password fields.

6.8. Check the list of post types to be indexed and mapped, by default all post types are checked.

6.9. For each selected post type you can exclude fields from indexing by entering them in the "Exclude fields from indexing" textarea, fields are separated by new line.

6.10. For each selected post type you can indicate private fields to be added to the private index only in the "Fields for private searches only" textarea, fields are separated by new line.

6.11. Enter the capability name which grants access to the private indexes in the capability field, if the user role has this capability the search will be against private indexes only. Make sure the capability is added to your wordpress config and granted to the right roles.

6.12. Enter the list of searched fields in the Search Fields textarea, fields are separated by new line.

6.13. Enter the list of weightings in the Weightings textarea, fields are separated by new line and each line has a format of field^weight e.g. post_content^3.

6.14. Enter the fuzziness value in the Fuzziness field e.g 1.

Implementation in the theme

  1. Disable wp search

You need to disable default wordpress search which slows down your site, so use the following hook in your theme function:

function _cancel_query( $query ) {

    if ( !is_admin() && !is_feed() && is_search() ) {
        $query = false;
    }

    return $query;
}

add_action( 'posts_request', '_cancel_query' );
  1. Examples

    2.1. Posts search:

use makeandship\elasticsearch\queries\QueryBuilder;
use makeandship\elasticsearch\Searcher;

$searcher = new Searcher();

// search the first 10 posts with keyword foo
$query = new QueryBuilder();
$query = $query->freetext('foo')
    ->with_fuzziness()
    ->weighted()
    ->with_category_counts(array('category' => 10))
    ->paged(0, 10);

$result = $searcher->search($query->to_array());

2.2. Taxonomies search:

use makeandship\elasticsearch\queries\QueryBuilder;
use makeandship\elasticsearch\Searcher;

$searcher = new Searcher();

// search the first 10 taxonomies with keyword foo
$query = new QueryBuilder();
$query = $query->freetext('foo')
    ->for_taxonomies([....])
    ->paged(0, 10);

$result = $searcher->search($query->to_array());

2.3 Specific fields search:

use makeandship\elasticsearch\queries\QueryBuilder;
use makeandship\elasticsearch\Searcher;

$searcher = new Searcher();

// search only in post_title and post_content and return id, post_title and post_content
$query = new QueryBuilder();
$query = $query->freetext('foo')
    ->paged(0, 10)
    ->searching(['post_title', 'post_content'])
    ->returning(['id', 'post_title', 'post_content']);

$result = $searcher->search($query->to_array());

acf-elasticsearch's People

Contributors

mthomsit avatar yassire avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.