Skip to content

Commit a5da4c3

Browse files
committed
docs: fully refresh docs with extensive real examples
1 parent f1552c9 commit a5da4c3

File tree

13 files changed

+1354
-771
lines changed

13 files changed

+1354
-771
lines changed

README.md

Lines changed: 253 additions & 562 deletions
Large diffs are not rendered by default.

docs/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
copyright = f"2012-{date.today().year}, {author}"
66

77
# We track release notes in CHANGELOG.md and do not hardcode package versions here.
8-
version = "4.x"
8+
version = "current"
99
release = version
1010

1111
extensions = [

docs/config.rst

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
Configuration
44
=============
55

6-
Creating a Connection
7-
---------------------
6+
Driver Setup
7+
------------
88

9-
Use one of the supported drivers:
9+
MySQLi driver:
1010

1111
.. code-block:: php
1212
@@ -15,12 +15,15 @@ Use one of the supported drivers:
1515
use Foolz\SphinxQL\Drivers\Mysqli\Connection;
1616
1717
$conn = new Connection();
18-
$conn->setParams(array(
18+
$conn->setParams([
1919
'host' => '127.0.0.1',
2020
'port' => 9306,
21-
));
21+
'options' => [
22+
MYSQLI_OPT_CONNECT_TIMEOUT => 2,
23+
],
24+
]);
2225
23-
You can also use the PDO driver:
26+
PDO driver:
2427

2528
.. code-block:: php
2629
@@ -29,25 +32,57 @@ You can also use the PDO driver:
2932
use Foolz\SphinxQL\Drivers\Pdo\Connection;
3033
3134
$conn = new Connection();
32-
$conn->setParams(array(
35+
$conn->setParams([
3336
'host' => '127.0.0.1',
3437
'port' => 9306,
35-
));
38+
'charset' => 'utf8',
39+
]);
3640
3741
Connection Parameters
3842
---------------------
3943

40-
``setParams()`` and ``setParam()`` accept:
44+
``setParams()`` and ``setParam()`` support:
4145

4246
- ``host`` (string, default ``127.0.0.1``)
4347
- ``port`` (int, default ``9306``)
44-
- ``socket`` (string|null, default ``null``)
45-
- ``username`` (string|null, optional)
46-
- ``password`` (string|null, optional)
47-
- ``options`` (array, driver-specific client options)
48+
- ``socket`` (string|null)
49+
- ``username`` (string|null)
50+
- ``password`` (string|null)
51+
- ``charset`` (PDO DSN option)
52+
- ``options`` (array, driver-specific options)
53+
54+
Notes:
55+
56+
- Setting ``host`` to ``localhost`` is normalized to ``127.0.0.1``.
57+
- Socket notation like ``unix:/path/to/socket`` is converted to ``socket``.
58+
59+
Escaping and Quoting
60+
--------------------
61+
62+
Value escaping and quoting are connection-driven.
63+
64+
.. code-block:: php
65+
66+
<?php
67+
68+
$quotedText = $conn->quote('hello'); // 'hello'
69+
$quotedInt = $conn->quote(42); // 42
70+
$quotedNull = $conn->quote(null); // null
71+
$quotedList = $conn->quote([1, 2, 3]); // (1,2,3)
72+
73+
For raw SQL fragments, use ``SphinxQL::expr()``.
74+
75+
.. code-block:: php
76+
77+
<?php
78+
79+
use Foolz\SphinxQL\SphinxQL;
4880
49-
Strict Validation Notes
50-
-----------------------
81+
$sql = (new SphinxQL($conn))
82+
->select()
83+
->from('rt')
84+
->option('field_weights', SphinxQL::expr('(title=80, content=35)'))
85+
->compile()
86+
->getCompiled();
5187
52-
The query builder validates critical inputs at runtime in 4.0.
53-
Prefer explicit values over implicit coercion.
88+
// SELECT * FROM rt OPTION field_weights = (title=80, content=35)

docs/contribute.rst

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
11
Contribute
22
==========
33

4+
Thanks for improving SphinxQL Query Builder.
5+
46
Pull Requests
57
-------------
68

7-
1. Fork `SphinxQL Query Builder <https://github.com/FoolCode/SphinxQL-Query-Builder>`_
8-
2. Create a new branch for each feature or improvement
9-
3. Submit a pull request with your branch against the default branch
9+
1. Fork `SphinxQL Query Builder <https://github.com/FoolCode/SphinxQL-Query-Builder>`_.
10+
2. Create a branch for your change.
11+
3. Open a pull request against the default branch.
1012

11-
It is very important that you create a new branch for each feature, improvement, or fix so that may review the changes and merge the pull requests in a timely manner.
13+
Please keep each pull request focused on one logical change.
1214

13-
Coding Style
14-
------------
15+
Development Guidelines
16+
----------------------
1517

16-
All pull requests should follow modern PHP style conventions (PSR-12 compatible formatting).
18+
- Follow PSR-12 style.
19+
- Add/update tests for behavior changes.
20+
- Update docs when public API behavior changes.
1721

1822
Testing
1923
-------
2024

21-
All pull requests must be accompanied with passing tests and code coverage. The SphinxQL Query Builder uses `PHPUnit <https://github.com/sebastianbergmann/phpunit/>`_ for testing.
25+
Run the Docker-based matrix used in CI:
2226

23-
Documentation
24-
-------------
27+
.. code-block:: bash
28+
29+
./scripts/run-tests-docker.sh
2530
26-
Documentation is built with Sphinx and the Furo theme.
31+
This runs PHPUnit for both mysqli and PDO configurations.
2732

28-
Build locally:
33+
Build Docs Locally
34+
------------------
2935

3036
.. code-block:: bash
3137
@@ -35,4 +41,5 @@ Build locally:
3541
Issue Tracker
3642
-------------
3743

38-
You can find our issue tracker at our `SphinxQL Query Builder <https://github.com/FoolCode/SphinxQL-Query-Builder>`_ repository.
44+
Use the GitHub issue tracker:
45+
`github.com/FoolCode/SphinxQL-Query-Builder/issues <https://github.com/FoolCode/SphinxQL-Query-Builder/issues>`_.

docs/features/facet.rst

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,89 @@
11
Facets
22
======
3+
4+
``Facet`` builds ``FACET`` clauses for grouped aggregations.
5+
6+
Building a Facet
7+
----------------
8+
9+
.. code-block:: php
10+
11+
<?php
12+
13+
use Foolz\SphinxQL\Facet;
14+
15+
$facet = (new Facet($conn))
16+
->facet(['gid'])
17+
->orderBy('gid', 'ASC');
18+
19+
Common compiled outputs from tests:
20+
21+
- ``facet(['gid'])`` -> ``FACET gid``
22+
- ``facet(['gid', 'title', 'content'])`` -> ``FACET gid, title, content``
23+
- ``facet(['alias' => 'gid'])`` -> ``FACET gid AS alias``
24+
- ``facetFunction('COUNT', 'gid')`` -> ``FACET COUNT(gid)``
25+
- ``facetFunction('INTERVAL', ['price', 200, 400, 600, 800])`` -> ``FACET INTERVAL(price,200,400,600,800)``
26+
27+
Using FACET with SELECT
28+
-----------------------
29+
30+
FACET is returned as an extra result set, so use ``executeBatch()``.
31+
32+
.. code-block:: php
33+
34+
<?php
35+
36+
use Foolz\SphinxQL\Facet;
37+
use Foolz\SphinxQL\SphinxQL;
38+
39+
$batch = (new SphinxQL($conn))
40+
->select()
41+
->from('rt')
42+
->facet(
43+
(new Facet($conn))
44+
->facet(['gid'])
45+
->orderBy('gid', 'ASC')
46+
)
47+
->executeBatch()
48+
->getStored();
49+
50+
// $batch[0] => SELECT rows
51+
// $batch[1] => FACET rows with gid + count(*)
52+
53+
Advanced Facet Options
54+
----------------------
55+
56+
Add ``BY``:
57+
58+
.. code-block:: php
59+
60+
$facet = (new Facet($conn))
61+
->facet(['gid', 'title', 'content'])
62+
->by('gid');
63+
64+
Sort by expression:
65+
66+
.. code-block:: php
67+
68+
$facet = (new Facet($conn))
69+
->facet(['gid', 'title'])
70+
->orderByFunction('COUNT', '*', 'DESC');
71+
72+
Paginate facet rows:
73+
74+
.. code-block:: php
75+
76+
$facet = (new Facet($conn))
77+
->facet(['gid', 'title'])
78+
->orderByFunction('COUNT', '*', 'DESC')
79+
->limit(5, 5);
80+
81+
Validation Notes
82+
----------------
83+
84+
``Facet`` throws ``SphinxQLException`` for invalid inputs such as:
85+
86+
- empty ``facet()`` columns
87+
- invalid order directions
88+
- invalid ``limit()`` / ``offset()``
89+
- ``facetFunction()`` without parameters

docs/features/match-builder.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
MatchBuilder
2+
============
3+
4+
``MatchBuilder`` helps compose advanced ``MATCH()`` expressions.
5+
6+
Use it directly, or pass a callback to ``SphinxQL::match()``.
7+
8+
Standalone Build
9+
----------------
10+
11+
.. code-block:: php
12+
13+
<?php
14+
15+
use Foolz\SphinxQL\MatchBuilder;
16+
use Foolz\SphinxQL\SphinxQL;
17+
18+
$sq = new SphinxQL($conn);
19+
20+
$match = (new MatchBuilder($sq))
21+
->field('content')
22+
->match('directly')
23+
->orMatch('lazy')
24+
->compile()
25+
->getCompiled();
26+
27+
// @content directly | lazy
28+
29+
Inline with Query Builder
30+
-------------------------
31+
32+
.. code-block:: php
33+
34+
$rows = (new SphinxQL($conn))
35+
->select()
36+
->from('rt')
37+
->match(function ($m) {
38+
$m->field('content')
39+
->match('directly')
40+
->orMatch('lazy');
41+
})
42+
->execute()
43+
->getStored();
44+
45+
Real Compiled Examples from Tests
46+
---------------------------------
47+
48+
- ``match('test case')`` -> ``(test case)``
49+
- ``match('test')->orMatch('case')`` -> ``test | case``
50+
- ``phrase('test case')`` -> ``"test case"``
51+
- ``proximity('test case', 5)`` -> ``"test case"~5``
52+
- ``quorum('this is a test case', 3)`` -> ``"this is a test case"/3``
53+
- ``field('body', 50)->match('test')`` -> ``@body[50] test``
54+
- ``ignoreField('title', 'body')->match('test')`` -> ``@!(title,body) test``
55+
- ``zone(['h3', 'h4'])`` -> ``ZONE:(h3,h4)``
56+
- ``zonespan('th', 'test')`` -> ``ZONESPAN:(th) test``
57+
58+
Expressions and Escaping
59+
------------------------
60+
61+
Raw expression bypass:
62+
63+
.. code-block:: php
64+
65+
use Foolz\SphinxQL\SphinxQL;
66+
67+
$expr = (new MatchBuilder($sq))
68+
->match(SphinxQL::expr('test|case'))
69+
->compile()
70+
->getCompiled();
71+
72+
// test|case
73+
74+
Without ``Expression``, special characters are escaped.

0 commit comments

Comments
 (0)