Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UINT_SET attribute type support + Fix tests and CI #144

Merged
merged 69 commits into from
Mar 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
c2c2b31
fix composer.json
vjik Mar 20, 2024
bc778c6
try fix action
vjik Mar 20, 2024
46167c6
fix sphinx
vjik Mar 20, 2024
6c12744
fix
vjik Mar 20, 2024
b869ba8
fix
vjik Mar 20, 2024
7b3e9a3
fix
vjik Mar 20, 2024
e82921f
fix
vjik Mar 20, 2024
ce26ec6
fix
vjik Mar 20, 2024
03e68c4
fix
vjik Mar 20, 2024
f292f0b
fix
vjik Mar 20, 2024
63f145e
fix
vjik Mar 20, 2024
84c2cbf
fix
vjik Mar 20, 2024
e9cd236
fix
vjik Mar 20, 2024
f53e03b
fix
vjik Mar 20, 2024
a108d50
fix
vjik Mar 20, 2024
c731851
fix
vjik Mar 20, 2024
175b615
fix
vjik Mar 20, 2024
ccca747
fix
vjik Mar 20, 2024
ffc761b
fix
vjik Mar 20, 2024
8797c10
fix
vjik Mar 20, 2024
7b9b39f
fix
vjik Mar 20, 2024
4737146
fix
vjik Mar 20, 2024
8d1a9e8
fix
vjik Mar 20, 2024
0d674cb
fix
vjik Mar 20, 2024
8d0f38b
fix
vjik Mar 20, 2024
588e56c
fix test
vjik Mar 20, 2024
9ef00f0
improve
vjik Mar 20, 2024
763ee9f
improve
vjik Mar 20, 2024
a7dab7b
try 3.5.1
vjik Mar 20, 2024
488affb
fix
vjik Mar 20, 2024
f5ec11f
fix
vjik Mar 20, 2024
b05e4c8
fix
vjik Mar 20, 2024
3ae84b5
fix
vjik Mar 20, 2024
eefa742
fix
vjik Mar 20, 2024
6de8523
fix
vjik Mar 20, 2024
b8da18c
fix
vjik Mar 20, 2024
9755659
fix
vjik Mar 20, 2024
f22deae
fix
vjik Mar 20, 2024
3b15e3d
fix
vjik Mar 20, 2024
9d0c49c
fix
vjik Mar 20, 2024
00bfb8a
fix
vjik Mar 20, 2024
e17f52b
fix
vjik Mar 20, 2024
7943f7a
fix
vjik Mar 20, 2024
8ffcf01
changelog
vjik Mar 20, 2024
873bc93
fix
vjik Mar 20, 2024
31da9f3
fix
vjik Mar 20, 2024
f9ec77d
fix
vjik Mar 20, 2024
a712712
fix
vjik Mar 20, 2024
26396e9
fix
vjik Mar 20, 2024
0bd135f
improve
vjik Mar 20, 2024
4aea790
fix
vjik Mar 20, 2024
9884aaa
fix
vjik Mar 20, 2024
8472f50
fix
vjik Mar 20, 2024
0a1c598
fix
vjik Mar 20, 2024
c8483de
fix
vjik Mar 20, 2024
ed1a9f8
fix
vjik Mar 20, 2024
8b98ca8
fix
vjik Mar 20, 2024
585c130
fix
vjik Mar 20, 2024
1863030
fix
vjik Mar 20, 2024
2208e0b
fix
vjik Mar 20, 2024
d5320ee
fix
vjik Mar 20, 2024
85f9c19
fix
vjik Mar 20, 2024
616cce1
fix
vjik Mar 20, 2024
f854199
fix
vjik Mar 20, 2024
7319886
fix
vjik Mar 20, 2024
200f913
fix
vjik Mar 20, 2024
97f04aa
fix
vjik Mar 20, 2024
b064d35
improve
vjik Mar 20, 2024
9113b4a
fix
vjik Mar 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 33 additions & 10 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
on:
- pull_request
- push
pull_request:
push:
branches:
- master

name: build

jobs:
tests:
name: PHP ${{ matrix.php }}-${{ matrix.os }}
name: PHP ${{ matrix.php }}-sphinx-${{ matrix.sphinx }}-${{ matrix.os }}

env:
extensions: pdo, pdo_mysql
Expand All @@ -17,8 +19,7 @@ jobs:
strategy:
matrix:
os:
- ubuntu-18.04

- ubuntu-20.04
php:
- "5.4"
- "5.5"
Expand All @@ -28,6 +29,18 @@ jobs:
- "7.2"
- "7.3"
- "7.4"
sphinx:
- "2.2.11"
- "3.5.1"

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: yiitest
ports:
- 3306:3306

steps:
- name: Checkout
Expand All @@ -53,14 +66,24 @@ jobs:
if: matrix.php == '8.0'
run: composer update --ignore-platform-reqs --prefer-dist --no-interaction --no-progress --optimize-autoloader --ansi

- name: Install sphinx
run: sh tests/data/actions/sphinx-setup-${{ matrix.sphinx }}.sh

- name: Setup source database
run: |
sudo /etc/init.d/mysql start
mysql -uroot -proot -e 'CREATE DATABASE `yiitest`;'
mysql -D yiitest -uroot -proot < tests/data/source.sql
mysql -h127.0.0.1 -D yiitest -uroot -proot < tests/data/source.sql

- name: Install sphinx
run: cd tests/data/actions && sh sphinx-setup.sh
- name: Run sphinx 2.2.11
if: matrix.sphinx == '2.2.11'
run: |
indexer --config tests/data/sphinx-${{ matrix.sphinx }}.conf --all
searchd --config tests/data/sphinx-${{ matrix.sphinx }}.conf

- name: Run sphinx 3
if: matrix.sphinx != '2.2.11'
run: |
/opt/sphinx/sphinx-${{ matrix.sphinx }}/bin/indexer --config tests/data/sphinx-${{ matrix.sphinx }}.conf --all
/opt/sphinx/sphinx-${{ matrix.sphinx }}/bin/searchd --config tests/data/sphinx-${{ matrix.sphinx }}.conf

- name: Run tests with phpunit
if: matrix.php != '7.4'
Expand Down
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yii Framework 2 sphinx extension Change Log
2.0.16 under development
------------------------

- no changes in this release.
- Enh #144: Add `UINT_SET` attribute type support (@vjik)


2.0.15 November 18, 2022
Expand Down
6 changes: 6 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,11 @@
"branch-alias": {
"dev-master": "2.0.x-dev"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"yiisoft/yii2-composer": true
}
}
}
3 changes: 2 additions & 1 deletion src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ class Schema extends BaseObject
'bool' => self::TYPE_BOOLEAN,
'float' => self::TYPE_FLOAT,
'mva' => self::TYPE_INTEGER,
'uint_set' => self::TYPE_INTEGER,
];

/**
Expand Down Expand Up @@ -538,7 +539,7 @@ protected function loadColumnSchema($info)
$column->isField = ($type === 'field');
$column->isAttribute = !$column->isField;

$column->isMva = ($type === 'mva');
$column->isMva = $type === 'mva' || $type === 'uint_set';

$column->phpType = $this->getColumnPhpType($column);

Expand Down
44 changes: 31 additions & 13 deletions tests/QueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function testSelect()
$query = new Query();
$query->select('*');
$this->assertEquals(['*' => '*'], $query->select);
$this->assertNull($query->distinct);
$this->assertFalse($query->distinct);
$this->assertEquals(null, $query->selectOption);

$query = new Query();
Expand Down Expand Up @@ -458,6 +458,9 @@ public function testFacets()
{
$connection = $this->getConnection();

$rawSphinxVersion = $connection->createCommand("SHOW GLOBAL VARIABLES LIKE 'version'")->queryOne();
$sphinxVersion = isset($rawSphinxVersion['Value']) ? $rawSphinxVersion['Value'] : '';

$query = new Query();
$results = $query->from('yii2_test_article_index')
->match('about')
Expand All @@ -480,18 +483,33 @@ public function testFacets()
$this->assertNotEmpty($results['hits'], 'Unable to query with complex facet');
$this->assertNotEmpty($results['facets']['author_id'], 'Unable to fill up complex facet');

$query = new Query();
$results = $query->from('yii2_test_article_index')
->match('about')
->facets([
'range' => [
'select' => 'INTERVAL(author_id,200,400,600,800) AS range',
],
'authorId' => [
'select' => [new Expression('author_id AS authorId')],
],
])
->search($connection);
$query = (new Query())
->from('yii2_test_article_index')
->match('about');

if (strpos($sphinxVersion, '3.') === 0) {
$query = $query
->select(new Expression('INTERVAL(author_id,200,400,600,800) AS range'))
->facets([
'range' => [
'select' => 'range',
],
'authorId' => [
'select' => [new Expression('author_id AS authorId')],
],
]);
} else {
$query = $query
->facets([
'range' => [
'select' => 'INTERVAL(author_id,200,400,600,800) AS range',
],
'authorId' => [
'select' => [new Expression('author_id AS authorId')],
],
]);
}
$results = $query->search($connection);
$this->assertNotEmpty($results['hits'], 'Unable to query with facet using custom select');
$this->assertNotEmpty($results['facets']['range'], 'Unable to fill up facet using function in select');
$this->assertNotEmpty($results['facets']['authorId'], 'Unable to fill up facet using `Expression` in select');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
SCRIPT=$(readlink -f "$0")
CWD=$(dirname "$SCRIPT")

# https://askubuntu.com/a/1337909
echo 'deb http://security.ubuntu.com/ubuntu xenial-security main' | sudo tee /etc/apt/sources.list.d/xenial-security.list
sudo apt update
sudo apt install libmysqlclient20

# install sphinx from https://sphinxsearch.com/downloads/release/
wget http://sphinxsearch.com/files/sphinxsearch_2.2.11-release-1~xenial_amd64.deb
sudo dpkg -i sphinxsearch_2.2.11-release-1~xenial_amd64.deb

# make dir that is used in sphinx config
mkdir -p sphinx
sed -i s\~SPHINX_BASE_DIR~$PWD/sphinx~g $CWD/../sphinx.conf

# setup test Sphinx indexes:
indexer --config $CWD/../sphinx.conf --all

# run searchd:
searchd --config $CWD/../sphinx.conf
sed -i s\~SPHINX_BASE_DIR~$PWD/sphinx~g $CWD/../sphinx-2.2.11.conf
12 changes: 12 additions & 0 deletions tests/data/actions/sphinx-setup-3.5.1.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/sh -e
SCRIPT=$(readlink -f "$0")
CWD=$(dirname "$SCRIPT")

wget https://sphinxsearch.com/files/sphinx-3.5.1-82c60cb-linux-amd64.tar.gz -O /tmp/sphinxsearch.tar.gz
sudo mkdir /opt/sphinx
cd /opt/sphinx && sudo tar -zxf /tmp/sphinxsearch.tar.gz
rm /tmp/sphinxsearch.tar.gz

# make dir that is used in sphinx config
mkdir -p $PWD/sphinx
sed -i s\~SPHINX_BASE_DIR~$PWD/sphinx~g $CWD/../sphinx-3.5.1.conf
2 changes: 1 addition & 1 deletion tests/data/source.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1056,4 +1056,4 @@ INSERT INTO `yii2_test_article_tag` (`article_id`, `tag_id`) VALUES
(1, 2),
(1, 3),
(2, 3),
(2, 4);
(2, 4);
4 changes: 2 additions & 2 deletions tests/data/sphinx.conf → tests/data/sphinx-2.2.11.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ source yii2_test_article_src
{
type = mysql

sql_host = localhost
sql_host = 127.0.0.1
sql_user = root
sql_pass = root
sql_db = yiitest
Expand All @@ -34,7 +34,7 @@ source yii2_test_item_src
{
type = mysql

sql_host = localhost
sql_host = 127.0.0.1
sql_user = root
sql_pass = root
sql_db = yiitest
Expand Down
116 changes: 116 additions & 0 deletions tests/data/sphinx-3.5.1.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# Sphinx configuration for the unit tests
#
# Setup test environment:
# - initialize test database source:
# mysql -D yiitest -u test < /path/to/yii/tests/unit/data/sphinx/source.sql
# - setup test Sphinx indexes:
# indexer --config /path/to/yii/tests/unit/data/sphinx/sphinx.conf --all [--rotate]
# - run the "searchd" daemon:
# searchd --config /path/to/yii/tests/unit/data/sphinx/sphinx.conf


source yii2_test_article_src
{
type = mysql

sql_host = 127.0.0.1
sql_user = root
sql_pass = root
sql_db = yiitest
sql_port = 3306 # optional, default is 3306

sql_query = \
SELECT *, UNIX_TIMESTAMP(create_date) AS add_date \
FROM yii2_test_article

sql_attr_uint = author_id
sql_attr_uint = add_date
sql_attr_multi = uint tag from query; SELECT article_id AS id, tag_id AS tag FROM yii2_test_article_tag
}


source yii2_test_item_src
{
type = mysql

sql_host = 127.0.0.1
sql_user = root
sql_pass = root
sql_db = yiitest
sql_port = 3306 # optional, default is 3306

sql_query = \
SELECT *, CURRENT_TIMESTAMP() AS add_date \
FROM yii2_test_item \
WHERE id <= 100

sql_attr_uint = category_id
sql_attr_float = price
sql_attr_uint = add_date
}


source yii2_test_item_delta_src : yii2_test_item_src
{
sql_query = \
SELECT *, CURRENT_TIMESTAMP() AS add_date \
FROM yii2_test_item \
WHERE id > 100
}


index yii2_test_article_index
{
source = yii2_test_article_src
}


index yii2_test_item_index
{
source = yii2_test_item_src
}


index yii2_test_item_delta_index : yii2_test_item_index
{
source = yii2_test_item_delta_src
}


index yii2_test_rt_index
{
type = rt
rt_field = title
rt_attr_string = title
rt_field = content
rt_attr_uint = type_id
rt_attr_multi = category
}


index yii2_test_distributed
{
type = distributed
local = yii2_test_article_index
}

common {
datadir = SPHINX_BASE_DIR
}

indexer
{
mem_limit = 32M
}

searchd
{
#listen = 127.0.0.1:9312
listen = 19306:mysql41
read_timeout = 5
max_children = 30
seamless_rotate = 1
preopen_indexes = 1
unlink_old = 1
workers = threads # for RT to work
}
Loading