@@ -63,48 +63,50 @@ The query also includes a:
63
63
- :pipeline:`$project` stage to exclude all fields except
64
64
``title`` and add a field named ``score``.
65
65
66
- .. code-block:: python
66
+ .. io- code-block::
67
67
:copyable: true
68
+
69
+ .. input:: python
68
70
69
- client = pymongo.MongoClient('<connection-string>')
70
- result = client['sample_mflix']['movies'].aggregate([
71
- {
72
- "$search": {
73
- "phrase": {
71
+ client = pymongo.MongoClient('<connection-string>')
72
+ result = client['sample_mflix']['movies'].aggregate([
73
+ {
74
+ "$search": {
75
+ "phrase": {
74
76
"path": "title",
75
77
"query": "new york"
76
78
}
77
79
}
78
80
},
79
81
{ $limit: 10 },
80
82
{
81
- $project: {
82
- "_id": 0,
83
- "title": 1,
84
- score: { $meta: "searchScore" }
83
+ $project: {
84
+ "_id": 0,
85
+ "title": 1,
86
+ score: { $meta: "searchScore" }
85
87
}
86
88
}
87
89
])
88
- for i in result:
89
- print(i)
90
-
91
- .. output::
92
- :language: shell
93
- :linenos:
94
- :visible: false
95
-
96
- [
97
- { title: 'New York, New York', score: 6.786321640014648 }
98
- { title: 'New York', score: 6.258549213409424 }
99
- { title: 'New York Stories', score: 5.3813982009887695 }
100
- { title: 'New York Minute', score: 5.3813982009887695 }
101
- { title: 'Synecdoche, New York', score: 5.3813982009887695 }
102
- { title: 'New York Doll', score: 5.3813982009887695 }
103
- { title: 'Little New York', score: 5.3813982009887695 }
104
- { title: 'Escape from New York', score: 4.719893455505371 }
105
- { title: 'Naked in New York', score: 4.719893455505371 }
106
- { title: 'Autumn in New York', score: 4.719893455505371 }
107
- ]
90
+ for i in result:
91
+ print(i)
92
+
93
+ .. output::
94
+ :language: shell
95
+ :linenos:
96
+ :visible: false
97
+
98
+ [
99
+ { title: 'New York, New York', score: 6.786321640014648 }
100
+ { title: 'New York', score: 6.258549213409424 }
101
+ { title: 'New York Stories', score: 5.3813982009887695 }
102
+ { title: 'New York Minute', score: 5.3813982009887695 }
103
+ { title: 'Synecdoche, New York', score: 5.3813982009887695 }
104
+ { title: 'New York Doll', score: 5.3813982009887695 }
105
+ { title: 'Little New York', score: 5.3813982009887695 }
106
+ { title: 'Escape from New York', score: 4.719893455505371 }
107
+ { title: 'Naked in New York', score: 4.719893455505371 }
108
+ { title: 'Autumn in New York', score: 4.719893455505371 }
109
+ ]
108
110
109
111
Next Steps
110
112
----------
0 commit comments