|
| 1 | +.. _kotlin-sync-atlas-search: |
| 2 | + |
| 3 | +============ |
| 4 | +Atlas Search |
| 5 | +============ |
| 6 | + |
| 7 | +.. facet:: |
| 8 | + :name: genre |
| 9 | + :values: reference |
| 10 | + |
| 11 | +.. meta:: |
| 12 | + :keywords: full text, text analyzer, pipeline |
| 13 | + :description: Learn about how to use Atlas Search in the {+driver-long+}. |
| 14 | + |
| 15 | +.. contents:: On this page |
| 16 | + :local: |
| 17 | + :backlinks: none |
| 18 | + :depth: 2 |
| 19 | + :class: singlecol |
| 20 | + |
| 21 | +Overview |
| 22 | +-------- |
| 23 | + |
| 24 | +In this guide, you can learn how to use the {+driver-short+} to |
| 25 | +run Atlas Search queries on a collection. Atlas Search enables you to perform |
| 26 | +full-text searches on collections hosted on MongoDB Atlas. |
| 27 | + |
| 28 | +For more information about Atlas Search queries, see the :atlas:`Atlas Search |
| 29 | +documentation </atlas-search/>` in the Atlas manual. |
| 30 | + |
| 31 | +Atlas search queries are different than traditional database queries, as they |
| 32 | +are intended to meet more general information needs. Where a database query must |
| 33 | +follow a strict syntax, search queries can be for simple text matching, but can |
| 34 | +also look for similar phrases, number or date ranges, or use regular expressions |
| 35 | +or wildcards. They rely on Atlas Search indexes to specify the behavior of the |
| 36 | +search and which fields to index. |
| 37 | + |
| 38 | +For information about setting up indexes, see the :ref:`Atlas Search and Vector |
| 39 | +Search Indexes <kotlin-sync-atlas-search-index>` page. |
| 40 | + |
| 41 | +Building Queries |
| 42 | +---------------- |
| 43 | + |
| 44 | +Atlas Search queries take the form of an aggregation pipeline stage. Atlas |
| 45 | +Search provides ``$search`` and ``$searchMeta`` stages, both of which must be the first |
| 46 | +stage in any query pipeline |
| 47 | + |
| 48 | +For more information about pipelines in the {+driver-short+}, see the :ref:`kotlin-sync-aggregation` |
| 49 | +page. |
| 50 | + |
| 51 | +For more information about Atlas pipeline stages, see the :atlas:`Choose the |
| 52 | +Aggregation Pipeline Stage </atlas-search/query-syntax/>`__ page in the Atlas |
| 53 | +manual. |
| 54 | + |
| 55 | +.. sharedinclude:: dbx/jvm/atlas-search-operator-helpers.rst |
| 56 | + |
| 57 | + .. replacement:: atlas-query-operators-example |
| 58 | + |
| 59 | + .. code-block:: kotlin |
| 60 | + |
| 61 | + Bson searchStageFilters = Aggregates.search( |
| 62 | + SearchOperator.compound() |
| 63 | + .filter( |
| 64 | + List.of( |
| 65 | + SearchOperator.text(fieldPath("genres"), "Drama"), |
| 66 | + SearchOperator.phrase(fieldPath("cast"), "sylvester stallone"), |
| 67 | + SearchOperator.numberRange(fieldPath("year")).gtLt(1980, 1989), |
| 68 | + SearchOperator.wildcard(fieldPath("title"),"Rocky *") |
| 69 | + ))); |
| 70 | + |
| 71 | + .. replacement:: searchoperator-interface-api-docs |
| 72 | + |
| 73 | + the `SearchOperator Interface API documentation <{+core-api+}/com/mongodb/client/model/search/SearchOperator.html>`__ |
| 74 | + |
| 75 | + |
0 commit comments