File tree Expand file tree Collapse file tree 4 files changed +21
-24
lines changed Expand file tree Collapse file tree 4 files changed +21
-24
lines changed Original file line number Diff line number Diff line change @@ -66,10 +66,9 @@ Search queries by using the Aggregation Builder:
66
66
To create a ``$search`` stage in your aggregation pipeline, perform the
67
67
following actions:
68
68
69
- 1. Create a ``Pipeline`` class instance to create the pipeline
69
+ 1. Create an array to store the pipeline stages
70
70
71
- #. Within the ``Pipeline`` instance, call the ``Stage::search()`` method
72
- to create the Atlas Search stage
71
+ #. Call the ``Stage::search()`` method to create the Atlas Search stage
73
72
74
73
#. Within the body of the ``search()`` method, use methods from the
75
74
``Search`` builder class to construct your Search query criteria
@@ -79,12 +78,12 @@ queries:
79
78
80
79
.. code-block:: php
81
80
82
- $pipeline = new Pipeline(
81
+ $pipeline = [
83
82
Stage::search(
84
83
/* Atlas Search query specifications
85
84
Search::compound(...) */
86
85
),
87
- ) ;
86
+ ] ;
88
87
89
88
Atlas Search Query Examples
90
89
---------------------------
Original file line number Diff line number Diff line change @@ -67,10 +67,10 @@ Search queries by using the Aggregation Builder:
67
67
To create a ``$vectorSearch`` stage in your aggregation pipeline, perform the
68
68
following actions:
69
69
70
- 1. Create a ``Pipeline`` class instance to create the pipeline
70
+ 1. Create an array to store the pipeline stages
71
71
72
- #. Within the ``Pipeline`` instance, call the `` Stage::vectorSearch()`` method
73
- to create the Atlas Vector Search stage
72
+ #. Call the ``Stage::vectorSearch()`` method to create the Atlas Vector
73
+ Search stage
74
74
75
75
#. Within the body of the ``vectorSearch()`` method, specify the
76
76
criteria for your vector query
@@ -80,13 +80,13 @@ queries:
80
80
81
81
.. code-block:: php
82
82
83
- $pipeline = new Pipeline(
83
+ $pipeline = [
84
84
Stage::vectorSearch(
85
85
/* Atlas Vector Search query specifications
86
86
index: '<index name>',
87
87
path: '<path to embeddings>', ...*/
88
88
),
89
- ) ;
89
+ ] ;
90
90
91
91
You must pass the following parameters to the ``vectorSearch()`` method:
92
92
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
// start-imports
4
- use MongoDB \Builder \Pipeline ;
5
4
use MongoDB \Builder \Search ;
6
5
use MongoDB \Builder \Stage ;
7
6
// end-imports
35
34
echo "\n" ;
36
35
37
36
// start-compound-search-query
38
- $ pipeline = new Pipeline (
37
+ $ pipeline = [
39
38
Stage::search (
40
39
Search::compound (
41
40
must: [
64
63
name: 1
65
64
),
66
65
Stage::limit (3 )
67
- ) ;
66
+ ] ;
68
67
69
- $ cursor = $ collection ->aggregate (iterator_to_array ( $ pipeline) );
68
+ $ cursor = $ collection ->aggregate ($ pipeline );
70
69
71
70
foreach ($ cursor as $ doc ) {
72
71
echo json_encode ($ doc ), PHP_EOL ;
110
109
echo "\n" ;
111
110
112
111
// start-autocomplete-search-query
113
- $ pipeline = new Pipeline (
112
+ $ pipeline = [
114
113
Stage::search (
115
114
Search::autocomplete (
116
115
query: 'Lucy ' ,
119
118
),
120
119
Stage::limit (3 ),
121
120
Stage::project (_id: 0 , name: 1 ),
122
- ) ;
121
+ ] ;
123
122
124
- $ cursor = $ collection ->aggregate (iterator_to_array ( $ pipeline) );
123
+ $ cursor = $ collection ->aggregate ($ pipeline );
125
124
126
125
foreach ($ cursor as $ doc ) {
127
126
echo json_encode ($ doc ), PHP_EOL ;
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
// start-imports
4
- use MongoDB \Builder \Pipeline ;
5
4
use MongoDB \Builder \Stage ;
6
5
// end-imports
7
6
43
42
echo "\n" ;
44
43
45
44
// start-basic-query
46
- $ pipeline = new Pipeline (
45
+ $ pipeline = [
47
46
Stage::vectorSearch (
48
47
index: 'vector ' ,
49
48
path: 'plot_embedding ' ,
55
54
_id: 0 ,
56
55
title: 1 ,
57
56
),
58
- ) ;
57
+ ] ;
59
58
60
- $ cursor = $ collection ->aggregate (iterator_to_array ( $ pipeline) );
59
+ $ cursor = $ collection ->aggregate ($ pipeline );
61
60
62
61
foreach ($ cursor as $ doc ) {
63
62
echo json_encode ($ doc ), PHP_EOL ;
64
63
}
65
64
// end-basic-query
66
65
67
66
// start-score-query
68
- $ pipeline = new Pipeline (
67
+ $ pipeline = [
69
68
Stage::vectorSearch (
70
69
index: 'vector ' ,
71
70
path: 'plot_embedding ' ,
78
77
title: 1 ,
79
78
score: ['$meta ' => 'vectorSearchScore ' ],
80
79
),
81
- ) ;
80
+ ] ;
82
81
83
- $ cursor = $ collection ->aggregate (iterator_to_array ( $ pipeline) );
82
+ $ cursor = $ collection ->aggregate ($ pipeline );
84
83
85
84
foreach ($ cursor as $ doc ) {
86
85
echo json_encode ($ doc ), PHP_EOL ;
You can’t perform that action at this time.
0 commit comments