Skip to content

Commit

Permalink
Misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
renatonascalves committed Jun 29, 2024
1 parent 24e80b2 commit 9ae41f5
Show file tree
Hide file tree
Showing 27 changed files with 185 additions and 170 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Changelog
All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [0.1.0-alpha]

- Still in development. [#1](https://github.com/renatonascalves/elasticsearch-buddypress/issues/1)
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Elasticsearch BuddyPress

[![Project Status: Active.](https://www.repostatus.org/badges/latest/concept.svg)](https://www.repostatus.org/#concept)

Elasticsearch BuddyPress is an integration of the BuddyPress plugin with Elasticsearch using the common/popular plugins: [ElasticPress](https://github.com/10up/ElasticPress), [SearchPress](https://github.com/alleyinteractive/searchpress), and [VIP Enterprise Search](https://docs.wpvip.com/enterprise-search/).

## Overview

Currently, the goal of this plugin is purely educational. Joining my experience with BuddyPress and Elasticsearch to create something useful. But it is also mostly an experiment at this point. Not ready for live sites/communities, yet.

I'm currently working on the implementation design (by using an Adapter, also known as Wrapper, Design pattern), by adding support for the Groups components for the [ElasticPress](https://github.com/10up/ElasticPress) plugin.

## Requirements

* [PHP](https://www.php.net/) >= 8.3+
* [WordPress](https://wordpress.org/) >= 6.5+
* [BuddyPress](https://buddypress.org/) >= latest
* [ElasticPress](https://github.com/10up/ElasticPress) >= latest
* [Elasticsearch](https://www.elastic.co/) >= 7.15+

## Example

Here is an example of how to query groups using the `ep_integrate` parameter:

```php
$args = [ "ep_integrate" => true ];

BP_Groups_Group::get( $args );
```
7 changes: 3 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,12 @@
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan": "^1.10",
"szepeviktor/phpstan-wordpress": "^1.3",
"wpackagist-plugin/elasticpress": "^4.6"
"wpackagist-plugin/elasticpress": "^5.0"
},
"scripts": {
"phpcs": "phpcs . --basepath=.",
"phpcbf": "phpcbf . --basepath=.",
"phpstan": [
"phpstan analyze --ansi --memory-limit=1G"
],
"phpstan": "phpstan analyze --ansi --memory-limit=1G",
"phpunit": "pest",
"test_multi": "WP_MULTISITE=1 pest"
},
Expand Down Expand Up @@ -110,6 +108,7 @@
"*.xml",
"*.dist",
"*.cache",
"CHANGELOG.md",
".editorconfig",
".gitignore",
".deployignore",
Expand Down
4 changes: 2 additions & 2 deletions elasticsearch-buddypress.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
* Requires PHP: 8.3
* Requires WP: 6.1
* Tested up to: 6.5.2
* Requires Plugins: buddypress
* Requires Plugins: buddypress, elasticpress
* License: GPL-3.0-or-later
* License URI: https://www.gnu.org/licenses/gpl-3.0.html
*/

declare( strict_types=1 );
declare(strict_types=1);

namespace Elasticsearch\BuddyPress;

Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ parameters:
paths:
- elasticsearch-buddypress.php
- src/
- tests/
scanDirectories:
- ../buddypress/
- ../elasticpress/
2 changes: 1 addition & 1 deletion src/Adapters/Adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Elasticsearch\BuddyPress
*/

declare( strict_types=1 );
declare(strict_types=1);

namespace Elasticsearch\BuddyPress\Adapters;

Expand Down
4 changes: 2 additions & 2 deletions src/Adapters/ElasticPress/ElasticPress.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Elasticsearch\BuddyPress
*/

declare( strict_types=1 );
declare(strict_types=1);

namespace Elasticsearch\BuddyPress\Adapters\ElasticPress;

Expand Down Expand Up @@ -66,7 +66,7 @@ public function missing_notice(): void {
<div class="notice notice-error">
<p>
<strong><?php esc_html_e( 'Elasticsearch BuddyPress:', 'elasticsearch-buddypress' ); ?></strong>
<?php esc_html_e( 'the ElasticPress adapter is active but the lastest version of ElasticPress plugin is not installed or active.', 'elasticsearch-buddypress' ); ?>
<?php esc_html_e( 'the ElasticPress adapter is active but the latest version of ElasticPress plugin is not installed or active.', 'elasticsearch-buddypress' ); ?>
</p>
</div>
<?php
Expand Down
9 changes: 1 addition & 8 deletions src/Adapters/ElasticPress/Features/Groups/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Elasticsearch\BuddyPress
*/

declare( strict_types=1 );
declare(strict_types=1);

namespace Elasticsearch\BuddyPress\Adapters\ElasticPress\Features\Groups;

Expand Down Expand Up @@ -79,11 +79,4 @@ public function integrate_search_queries( $enabled, $query ): bool {
default => $enabled,
};
}

/**
* Output feature box long.
*
* @todo Implement this method.
*/
public function output_feature_box_long(): void {}
}
82 changes: 42 additions & 40 deletions src/Adapters/ElasticPress/Features/Groups/GroupFormatArgs.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @package Elasticsearch\BuddyPress
*/

declare( strict_types=1 );
declare(strict_types=1);

namespace Elasticsearch\BuddyPress\Adapters\ElasticPress\Features\Groups;

Expand All @@ -20,10 +20,49 @@
*/
class GroupFormatArgs extends FormatArgs {

/**
* Format query args.
*
* @return array<mixed>
*/
public function format(): array {

// Bail if no query args.
if ( empty( $this->query_args ) ) {
return [];
}

$es_query_args = [
'from' => (int) ( $this->query_args['per_page'] * ( $this->query_args['page'] - 1 ) ),
'size' => (int) $this->query_args['per_page'] ?: 20,
'track_total_hits' => true,
];

$this->parse_sort();
$this->maybe_set_filters();
$this->maybe_set_search_fields();
$this->maybe_set_fields();

if ( $this->query ) {
$es_query_args['query'] = $this->query->toArray();
}

if ( $this->sorts ) {
$es_query_args['sort'] = $this->sorts->toArray();
}

if ( $this->fields ) {
$es_query_args['_source'] = $this->fields;
}

return $es_query_args;
}

/**
* Parse sort options.
*/
private function parse_sort(): void {
// phpcs:disable Squiz.PHP.CommentedOutCode.Found
// @todo support randon query.
/**
* Order by 'rand' support
Expand Down Expand Up @@ -140,9 +179,9 @@ private function maybe_set_filters(): void {
// @todo add support.
if ( ! empty( $this->query_args['meta_query'] ) ) {
/**
* Filters the meta keys to be excluded from group searches .
* Filters the meta keys to be excluded from group searches.
*
* @param array $exclude_meta_keys Meta keys to be excluded .
* @param string[] $exclude_meta_keys Meta keys to be excluded.
*/
$exclude_meta_keys = apply_filters( 'elasticsearch_buddypress_group_query_excluded_meta_keys', [] );

Expand Down Expand Up @@ -177,44 +216,7 @@ private function maybe_set_fields(): void {
case 'ids':
$this->fields( [ 'ID' ] );
break;
}
}

/**
* Format query args.
*
* @return array<mixed>
*/
public function format(): array {

// Bail if no query args.
if ( empty( $this->query_args ) ) {
return [];
}

$es_query_args = [
'from' => (int) ( $this->query_args['per_page'] * ( $this->query_args['page'] - 1 ) ),
'size' => (int) $this->query_args['per_page'] ?: 20,
'track_total_hits' => true,
];

$this->parse_sort();
$this->maybe_set_filters();
$this->maybe_set_search_fields();
$this->maybe_set_fields();

if ( $this->query ) {
$es_query_args['query'] = $this->query->toArray();
}

if ( $this->sorts ) {
$es_query_args['sort'] = $this->sorts->toArray();
}

if ( $this->fields ) {
$es_query_args['_source'] = $this->fields;
}

return $es_query_args;
}
}
Loading

0 comments on commit 9ae41f5

Please sign in to comment.