Module: Parse::AtlasSearch
- Defined in:
- lib/parse/atlas_search.rb,
lib/parse/atlas_search/result.rb,
lib/parse/atlas_search/session.rb,
lib/parse/atlas_search/index_manager.rb,
lib/parse/atlas_search/search_builder.rb,
lib/parse/atlas_search/protected_paths.rb
Overview
Requires the 'mongo' gem and a MongoDB Atlas cluster with Search enabled.
Also works with local Atlas deployments created via atlas deployments setup --type local.
Atlas Search module for MongoDB Atlas full-text search capabilities. Provides direct access to Atlas Search features bypassing Parse Server.
Defined Under Namespace
Modules: IndexManager, ProtectedPaths, Session Classes: ACLRequired, AutocompleteResult, FacetedResult, FacetedSearchNotACLSafe, IndexNotFound, InvalidSearchParameters, NotAvailable, SearchBuilder, SearchResult
Constant Summary collapse
- IndexCatalog =
Alias for IndexManager exposing the type-aware lookup surface (Parse::AtlasSearch::IndexManager.list_search_indexes, Parse::AtlasSearch::IndexManager.list_vector_indexes, Parse::AtlasSearch::IndexManager.find_vector_index). Backed by the same module, so the cache, mutex, and TTL are shared across both names — calling
IndexCatalog.clear_cacheandIndexManager.clear_cacheinvalidates the same store. IndexManager
Class Attribute Summary collapse
-
.allow_raw ⇒ Boolean
Whether
raw: trueis honored on AtlasSearch.search, AtlasSearch.autocomplete, and AtlasSearch.faceted_search. -
.default_index ⇒ String
Default search index name to use when none specified.
-
.enabled ⇒ Boolean
Feature flag to enable/disable Atlas Search.
-
.require_session_token ⇒ Boolean
When
true, AtlasSearch.search, AtlasSearch.autocomplete, and AtlasSearch.faceted_search raise ACLRequired unless the caller passes eithersession_token:ormaster: true.
Class Method Summary collapse
-
.authorization ⇒ Parse::Authorization::Context?
The default client's authorization context, or
nilwhen no client has been configured yet. -
.autocomplete_without_schema_snapshot ⇒ Parse::AtlasSearch::AutocompleteResult
Perform an autocomplete search for search-as-you-type functionality.
-
.available? ⇒ Boolean
Check if Atlas Search is available and enabled.
-
.compare_upstream_roles ⇒ Object
deprecated
Deprecated.
Use
client.authorization.compare_upstream_roles. - .compare_upstream_roles=(value) ⇒ Object
-
.configure(enabled: true, default_index: "default", allow_raw: nil, require_session_token: nil, session_cache_ttl: nil, role_cache_ttl: nil, upstream_role_reader: nil, compare_upstream_roles: nil) ⇒ Object
Configure Atlas Search (uses Parse::MongoDB connection).
-
.enabled? ⇒ Boolean
Check if Atlas Search is enabled.
-
.faceted_search_without_schema_snapshot ⇒ Parse::AtlasSearch::FacetedResult
Perform a faceted search with category counts.
-
.index_ready?(collection_name, index_name = nil) ⇒ Boolean
Check if a search index exists and is ready.
-
.indexes(collection_name) ⇒ Array<Hash>
List search indexes for a collection (cached).
-
.refresh_indexes(collection_name = nil) ⇒ Object
Force refresh the index cache for a collection.
-
.reset! ⇒ Object
Reset Atlas Search configuration to first-load defaults.
-
.role_cache ⇒ Object
deprecated
Deprecated.
Use
client.authorization.role_cache. - .role_cache=(value) ⇒ Object
-
.role_cache_ttl ⇒ Object
deprecated
Deprecated.
Use
client.authorization.role_cache_ttl. - .role_cache_ttl=(value) ⇒ Object
-
.search_with_stage_without_schema_snapshot ⇒ Parse::AtlasSearch::SearchResult
Execute a caller-supplied
$searchstage (built via a SearchBuilder) with the same ACL/CLP/protectedFields/ pointerFields enforcement as AtlasSearch.search, keeping$searchat stage 0. -
.search_without_schema_snapshot ⇒ Parse::AtlasSearch::SearchResult
Perform a full-text search using Atlas Search.
-
.session_cache ⇒ Object
deprecated
Deprecated.
Use
client.authorization.identity_cache. - .session_cache=(value) ⇒ Object
-
.session_cache_ttl ⇒ Object
deprecated
Deprecated.
Use
client.authorization.identity_cache_ttl. Renamed because it never stored sessions: it stores one user id per token, and the old name led readers to reason about_Sessionsemantics that were never involved. - .session_cache_ttl=(value) ⇒ Object
-
.upstream_role_reader ⇒ Object
deprecated
Deprecated.
Use
client.authorization.upstream_role_reader. - .upstream_role_reader=(value) ⇒ Object
Class Attribute Details
.allow_raw ⇒ Boolean
Whether raw: true is honored on search, autocomplete,
and faceted_search. When false (the default), raw: is
ignored and callers receive converted Parse-format
documents. Even when true, internal-fields denylist (cf.
PipelineSecurity::INTERNAL_FIELDS_DENYLIST) is
ALWAYS stripped — there is no path that returns
_hashed_password, _session_token, etc., regardless of
raw:.
80 81 82 |
# File 'lib/parse/atlas_search.rb', line 80 def allow_raw @allow_raw end |
.default_index ⇒ String
Default search index name to use when none specified.
68 69 70 |
# File 'lib/parse/atlas_search.rb', line 68 def default_index @default_index end |
.enabled ⇒ Boolean
Feature flag to enable/disable Atlas Search.
63 64 65 |
# File 'lib/parse/atlas_search.rb', line 63 def enabled @enabled end |
.require_session_token ⇒ Boolean
When true, search, autocomplete, and
faceted_search raise ACLRequired unless the caller
passes either session_token: or master: true. Default:
false, matching the pre-ACL behavior — a one-time
[Parse::AtlasSearch:SECURITY] banner is emitted instead
for missing-token calls, the same pattern used by
Parse::Agent for master-key construction.
New deployments are strongly encouraged to flip this to
true at startup. The next major release will flip the
default.
95 96 97 |
# File 'lib/parse/atlas_search.rb', line 95 def require_session_token @require_session_token end |
Class Method Details
.authorization ⇒ Parse::Authorization::Context?
The default client's authorization context, or nil when no client
has been configured yet.
Nil-tolerant on purpose. These delegators exist only for backward
compatibility, and the module-level API they replace worked in a
process that had never called Parse.setup (it kept its own
process-local caches). Raising ConnectionError from what used to be
a plain attribute reader would break configuration code that touches
these before setting up a client, and reset! is a test helper that
must not require a live client to run.
171 172 173 174 175 |
# File 'lib/parse/atlas_search.rb', line 171 def Parse.client&. rescue Parse::Error::ConnectionError nil end |
.autocomplete_without_schema_snapshot ⇒ Parse::AtlasSearch::AutocompleteResult
Perform an autocomplete search for search-as-you-type functionality.
1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 |
# File 'lib/parse/atlas_search.rb', line 1452 def autocomplete(collection_name, query, field:, **) require_available! raise InvalidSearchParameters, "field is required for autocomplete" if field.nil? raise InvalidSearchParameters, "query must be a non-empty string" if query.nil? || query.to_s.strip.empty? # Wave-3b READPREF-4: see #search for rationale. read_preference = .delete(:read_preference) resolution = resolve_scope!(, method_name: :autocomplete) # Enforce CLP `find` (and pointerFields requirement) on the same # collection autocomplete is about to scan. Without this an # autocomplete UI on a protected class would silently surface # the protected field's leading characters to any caller. assert_clp_find!(collection_name, resolution) pointer_fields = resolve_pointer_fields!(collection_name, resolution) # ATLAS-4: refuse autocomplete on a protected field. The # autocomplete operator returns the leading characters of the # indexed field value verbatim — running autocomplete on, say, # `email` when CLP marks `email` protected would defeat the # protectedFields contract. protected_fields = Parse::CLPScope.protected_fields_for( collection_name, resolution., client: Parse::MongoDB.clp_client_for(resolution), strict: true, ) field_str = field.to_s ProtectedPaths.assert_no_internal_paths!( paths: field_str, collection_name: collection_name, resolution: resolution, method_name: "Parse::AtlasSearch.autocomplete", what: "autocomplete field", ) if ProtectedPaths.enforce?(resolution, protected_fields) && ProtectedPaths.touches?(field_str, protected_fields) raise Parse::CLPScope::Denied.new( collection_name, :find, "Parse::AtlasSearch.autocomplete refused: field '#{field_str}' is in " \ "protectedFields for the current scope; autocompleting on it would " \ "leak the protected field's value.", ) end index_name = [:index] || @default_index limit = [:limit] || 10 # Build autocomplete search stage builder = SearchBuilder.new(index_name: index_name) builder.autocomplete( query: query.to_s, path: field_str, fuzzy: [:fuzzy], token_order: [:token_order], ) # CRITICAL: $search MUST be stage 0 of the pipeline (see # comments in #search). Build manually; do NOT route through # Parse::MongoDB.aggregate (which would prepend an ACL $match # at position 0 and break Atlas's invariant). pipeline = [builder.build] # Add score pipeline << { "$addFields" => { "_score" => { "$meta" => "searchScore" } } } # Inject ACL $match AFTER $search/$addFields and BEFORE the # caller-supplied filter; see {.search} for the rationale. unless resolution.master? acl_match = Parse::ACLScope.match_stage_for(resolution) pipeline << acl_match if acl_match pipeline << pointer_fields_match_stage(pointer_fields, resolution) if pointer_fields end # Add filter if provided if [:filter] mongo_filter = convert_filter_for_mongodb([:filter], collection_name, resolution: resolution) pipeline << { "$match" => mongo_filter } end # Sort by score and limit pipeline << { "$sort" => { "_score" => -1 } } pipeline << { "$limit" => limit } raw_results = run_atlas_pipeline!( collection_name, pipeline, [:max_time_ms], read_preference: read_preference, authorizing_client: Parse::ACLScope.client_of(resolution), ) unless resolution.master? Parse::ACLScope.redact_results!(raw_results, resolution) Parse::CLPScope.redact_protected_fields!(raw_results, protected_fields) if protected_fields.any? if pointer_fields raw_results = Parse::CLPScope.filter_by_pointer_fields( raw_results, pointer_fields, resolution.user_id, ) end end # Extract suggestions (the field values). Run after the # protectedFields strip / pointerFields filter so a redacted # row can't surface its field value through the suggestion list. suggestions = raw_results.map { |doc| doc[field_str] }.compact.uniq # Convert to full objects if needed class_name = [:class_name] || collection_name results = if raw_mode?([:raw]) sanitize_raw_results(raw_results) else parse_results = Parse::MongoDB.convert_documents_to_parse(raw_results, class_name) parse_results.map { |doc| build_parse_object(doc, class_name) }.compact end AutocompleteResult.new(suggestions: suggestions, results: results) end |
.available? ⇒ Boolean
Check if Atlas Search is available and enabled
239 240 241 242 |
# File 'lib/parse/atlas_search.rb', line 239 def available? return false unless defined?(Parse::MongoDB) Parse::MongoDB.available? && enabled? end |
.compare_upstream_roles ⇒ Object
Use client.authorization.compare_upstream_roles.
153 |
# File 'lib/parse/atlas_search.rb', line 153 def compare_upstream_roles = &.compare_upstream_roles || false |
.compare_upstream_roles=(value) ⇒ Object
155 156 157 |
# File 'lib/parse/atlas_search.rb', line 155 def compare_upstream_roles=(value) &.compare_upstream_roles = value end |
.configure(enabled: true, default_index: "default", allow_raw: nil, require_session_token: nil, session_cache_ttl: nil, role_cache_ttl: nil, upstream_role_reader: nil, compare_upstream_roles: nil) ⇒ Object
Configure Atlas Search (uses Parse::MongoDB connection)
200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/parse/atlas_search.rb', line 200 def configure(enabled: true, default_index: "default", allow_raw: nil, require_session_token: nil, session_cache_ttl: nil, role_cache_ttl: nil, upstream_role_reader: nil, compare_upstream_roles: nil) Parse::MongoDB.require_gem! @enabled = enabled @default_index = default_index @allow_raw = allow_raw.nil? ? default_allow_raw : allow_raw @require_session_token = require_session_token unless require_session_token.nil? # Authorization settings belong to the client, not to this module. # Forwarded rather than stored so there is exactly one copy. &.configure( identity_cache_ttl: session_cache_ttl, role_cache_ttl: role_cache_ttl, upstream_role_reader: upstream_role_reader, compare_upstream_roles: compare_upstream_roles, ) IndexManager.clear_cache end |
.enabled? ⇒ Boolean
Check if Atlas Search is enabled
246 247 248 |
# File 'lib/parse/atlas_search.rb', line 246 def enabled? @enabled == true end |
.faceted_search_without_schema_snapshot ⇒ Parse::AtlasSearch::FacetedResult
Perform a faceted search with category counts.
1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 |
# File 'lib/parse/atlas_search.rb', line 1457 def faceted_search(collection_name, query, facets, **) require_available! # Faceted search uses $searchMeta, which outputs a single # metadata document — bucket counts can't be retroactively # filtered by a post-$searchMeta $match because the matched # documents are not in the output stream. ACL-aware faceting # requires either tokenizing _rperm in the search index and # injecting a compound.filter inside $searchMeta, or running # two passes with manual aggregation. Both are deferred. # # Library-layer defense: refuse ANY scoped identity kwarg # (session_token:, acl_user:, acl_role:) unless the caller # explicitly accepts master-key semantics by also passing # `master: true`. The original code only checked # `session_token:`, leaving `acl_user:` / `acl_role:` callers # (ATLAS-10) silently downgraded to the unauthenticated/ # public-mode banner branch — which on $searchMeta produces # bucket counts that include rows the caller cannot read, # exfiltrating restricted document counts and category # values. Checking the raw options BEFORE resolve_scope! # pops them so the error path can name what the caller # actually passed. scoped_kwargs = %i[session_token acl_user acl_role] offending = scoped_kwargs.select { |k| ![k].nil? } if offending.any? && [:master] != true raise FacetedSearchNotACLSafe, "Parse::AtlasSearch.faceted_search cannot enforce per-row " \ "ACL on $searchMeta bucket counts (got #{offending.first}:). " \ "Pass `master: true` to run with master-key semantics and " \ "accept that bucket counts include all rows, or use " \ "#search for ACL-scoped results without facets." end # Inside Parse.without_master_key the only scope left is public, # and $searchMeta bucket counts are not ACL-filtered there either, # so they would count rows the block is meant to hide. Fail closed. if Parse::ACLScope.master_key_suppressed? raise FacetedSearchNotACLSafe, "Parse::AtlasSearch.faceted_search cannot run inside " \ "Parse.without_master_key: $searchMeta bucket counts include " \ "rows the caller cannot read. Wrap the call in " \ "Parse.with_master_key to accept master-key counts, or use " \ "#search for ACL-scoped results without facets." end # Wave-3b READPREF-4: see #search for rationale. Captured # before resolve_scope! pops the auth kwargs so the recursive # search() call below can re-thread it explicitly (resolve! # also strips it during that recursion). read_preference = .delete(:read_preference) resolution = resolve_scope!(, method_name: :faceted_search) acl = { master: resolution.master? } index_name = [:index] || @default_index limit = [:limit] || 100 skip_val = [:skip] || 0 # Build facet definitions for $searchMeta facet_definitions = build_facet_definitions(facets) = { "$searchMeta" => { "index" => index_name, "facet" => { "facets" => facet_definitions, }, }, } # Add operator for the search query if present if query.present? fields = normalize_fields([:fields]) if fields.present? should_clauses = fields.map do |field| { "text" => { "query" => query, "path" => field } } end ["$searchMeta"]["facet"]["operator"] = { "compound" => { "should" => should_clauses, "minimumShouldMatch" => 1 }, } else ["$searchMeta"]["facet"]["operator"] = { "text" => { "query" => query, "path" => { "wildcard" => "*" } }, } end end # No caller, master included, may facet on or search a Parse Server # internal column. ProtectedPaths.assert_no_internal_paths!( stage: , collection_name: collection_name, resolution: resolution, method_name: "Parse::AtlasSearch.faceted_search", what: "facet or search path", ) # A non-master caller (the public fallback when no auth kwargs are # passed) must not facet on, or text-match against, a protected # field: bucket values and counts would reveal it directly, and a # wildcard operator lets it decide which rows are counted. unless resolution.master? facet_protected = Parse::CLPScope.protected_fields_for( collection_name, resolution., client: Parse::MongoDB.clp_client_for(resolution), strict: true, ) ProtectedPaths.assert_search_stage_allowed!( , facet_protected, resolution, collection_name: collection_name, method_name: "Parse::AtlasSearch.faceted_search", ) end # Execute facet query. $searchMeta MUST be the only / first # stage of its pipeline — Atlas rejects anything prepended. # Bypass Parse::MongoDB.aggregate (which would prepend a # public-mode ACL $match at position 0 under the no-auth-kwargs # fallthrough) and call the collection directly. At this point # the call is master-only by construction (the offending-kwargs # check above ensures any scoped caller bailed out), so no # ACL/CLP enforcement runs here either. facet_pipeline = [] facet_results_raw = run_atlas_pipeline!( collection_name, facet_pipeline, [:max_time_ms], read_preference: read_preference, authorizing_client: Parse::ACLScope.client_of(resolution), ) # Extract facet results facet_data = {} total_count = 0 if facet_results_raw.first raw = facet_results_raw.first total_count = raw.dig("count", "total") || 0 if raw["facet"] facets.keys.each do |facet_name| bucket_key = facet_name.to_s if raw["facet"][bucket_key] facet_data[facet_name] = raw["facet"][bucket_key]["buckets"].map do |bucket| { value: bucket["_id"], count: bucket["count"] } end end end end end # Get actual results with regular $search. Forward master: # explicitly because resolve_acl_options! popped it from the # options hash; without re-adding it the recursive call would # take the unauthenticated path and emit the banner a second # time (or raise ACLRequired under strict mode). Re-thread # read_preference: the same way for the same reason — the # outer faceted_search popped it before delegating. results = if limit > 0 && query.present? search_opts = .merge(limit: limit, skip: skip_val) search_opts[:master] = true if acl[:master] search_opts[:read_preference] = read_preference if read_preference # Re-thread the client for the same reason as the auth kwargs # above: the outer faceted_search popped it in resolve_scope!, so # this inner search would otherwise resolve and read as the # default application. search_opts[:client] = Parse::ACLScope.client_of(resolution) if Parse::ACLScope.client_of(resolution) search(collection_name, query, **search_opts).results else [] end FacetedResult.new(results: results, facets: facet_data, total_count: total_count) end |
.index_ready?(collection_name, index_name = nil) ⇒ Boolean
Check if a search index exists and is ready
282 283 284 |
# File 'lib/parse/atlas_search.rb', line 282 def index_ready?(collection_name, index_name = nil) IndexManager.index_ready?(collection_name, index_name || @default_index) end |
.indexes(collection_name) ⇒ Array<Hash>
List search indexes for a collection (cached)
274 275 276 |
# File 'lib/parse/atlas_search.rb', line 274 def indexes(collection_name) IndexManager.list_indexes(collection_name) end |
.refresh_indexes(collection_name = nil) ⇒ Object
Force refresh the index cache for a collection
288 289 290 |
# File 'lib/parse/atlas_search.rb', line 288 def refresh_indexes(collection_name = nil) IndexManager.clear_cache(collection_name) end |
.reset! ⇒ Object
Reset Atlas Search configuration to first-load defaults. Clears the session/role caches as well; this is primarily a test helper.
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 |
# File 'lib/parse/atlas_search.rb', line 253 def reset! @enabled = false @default_index = "default" @allow_raw = default_allow_raw @require_session_token = false &.configure( identity_cache_ttl: Parse::Authorization::Context::DEFAULT_IDENTITY_TTL, role_cache_ttl: Parse::Authorization::Context::DEFAULT_ROLE_TTL, identity_cache: Parse::Authorization::MemoryCache.new, role_cache: Parse::Authorization::MemoryCache.new, upstream_role_reader: false, compare_upstream_roles: false, ) &.upstream_role_reader = nil @master_warned = false IndexManager.clear_cache end |
.role_cache ⇒ Object
Use client.authorization.role_cache.
139 |
# File 'lib/parse/atlas_search.rb', line 139 def role_cache = &.role_cache |
.role_cache=(value) ⇒ Object
141 142 143 |
# File 'lib/parse/atlas_search.rb', line 141 def role_cache=(value) &.role_cache = value end |
.role_cache_ttl ⇒ Object
Use client.authorization.role_cache_ttl.
125 |
# File 'lib/parse/atlas_search.rb', line 125 def role_cache_ttl = &.role_cache_ttl || Parse::Authorization::Context::DEFAULT_ROLE_TTL |
.role_cache_ttl=(value) ⇒ Object
127 128 129 |
# File 'lib/parse/atlas_search.rb', line 127 def role_cache_ttl=(value) &.role_cache_ttl = value end |
.search_with_stage_without_schema_snapshot ⇒ Parse::AtlasSearch::SearchResult
Execute a caller-supplied $search stage (built via a
SearchBuilder) with the same ACL/CLP/protectedFields/
pointerFields enforcement as search, keeping $search at
stage 0. This is the entry point for Parse::Query#atlas_search's
builder-block mode, which constructs its own $search stage
instead of going through the query/fields/fuzzy options.
Auth is resolved from options exactly like search:
session_token: / master: true / acl_user: / acl_role:
(mutually exclusive). Without one, behavior follows
require_session_token (public-only fallback, or ACLRequired).
1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 |
# File 'lib/parse/atlas_search.rb', line 1447 def search_with_stage(collection_name, search_stage, **) require_available! assert_search_stage_safe!(search_stage) read_preference = .delete(:read_preference) resolution = resolve_scope!(, method_name: :search) assert_clp_find!(collection_name, resolution) pointer_fields = resolve_pointer_fields!(collection_name, resolution) protected_fields = Parse::CLPScope.protected_fields_for( collection_name, resolution., client: Parse::MongoDB.clp_client_for(resolution), strict: true, ) assert_highlight_field_allowed!([:highlight_field], protected_fields, resolution) # The caller built this stage, so any operator path, sort key, or # highlight inside it may name a protected field. Walk it and # refuse before it runs: a protected field that decides matches # or ranking leaks its value even though the output strips it. ProtectedPaths.assert_search_stage_allowed!( search_stage, protected_fields, resolution, collection_name: collection_name, method_name: "Parse::AtlasSearch.search_with_stage", ) search_pipeline!( collection_name, search_stage, resolution: resolution, protected_fields: protected_fields, pointer_fields: pointer_fields, highlight_field: [:highlight_field], filter: [:filter], sort: [:sort], skip: [:skip] || 0, limit: [:limit] || 100, max_time_ms: [:max_time_ms], read_preference: read_preference, class_name: [:class_name] || collection_name, raw: [:raw], ) end |
.search_without_schema_snapshot ⇒ Parse::AtlasSearch::SearchResult
Perform a full-text search using Atlas Search.
1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 |
# File 'lib/parse/atlas_search.rb', line 1442 def search(collection_name, query, **) require_available! validate_search_params!(query) # Wave-3b READPREF-4: read-preference is consumed at the # collection-with-read-preference step inside run_atlas_pipeline!. # Pop it here so it doesn't surface in `options` for any # downstream consumer (SearchBuilder, recursive search() # call from faceted_search) that iterates the hash. read_preference = .delete(:read_preference) resolution = resolve_scope!(, method_name: :search) # Enforce CLP `find` (and pointerFields requirement) BEFORE # we build / execute the pipeline. Without this, a scoped # caller can issue $search against a collection whose CLP # would refuse them on the equivalent REST find. assert_clp_find!(collection_name, resolution) pointer_fields = resolve_pointer_fields!(collection_name, resolution) # Compute the protectedFields strip set early so we can # refuse a highlight_field that's in it (ATLAS-4). Avoids # the awkward "we return objects but secretly drop their # highlights" state — fail loudly instead. protected_fields = Parse::CLPScope.protected_fields_for( collection_name, resolution., client: Parse::MongoDB.clp_client_for(resolution), strict: true, ) assert_highlight_field_allowed!([:highlight_field], protected_fields, resolution) index_name = [:index] || @default_index fields = normalize_fields([:fields]) assert_search_fields_allowed!(fields, protected_fields, resolution) limit = [:limit] || 100 skip_val = [:skip] || 0 # Build the $search stage builder = SearchBuilder.new(index_name: index_name) if fields.present? fields.each do |field| builder.text(query: query, path: field, fuzzy: [:fuzzy]) end else builder.text(query: query, path: { "wildcard" => "*" }, fuzzy: [:fuzzy]) end if [:highlight_field] builder.with_highlight(path: [:highlight_field]) end # $search MUST be stage 0 of an Atlas Search pipeline (MongoDB # rejects any other first stage), so we must NOT route through # Parse::MongoDB.aggregate — that helper prepends the ACL $match # to position 0. Execution plus the full SDK-side enforcement # chain (ACL $match placed AFTER $search, protectedFields strip, # pointerFields filter, sub-doc redaction) lives in # `search_pipeline!`, shared with the builder-block path # (`search_with_stage` / Parse::Query#atlas_search). search_pipeline!( collection_name, builder.build, resolution: resolution, protected_fields: protected_fields, pointer_fields: pointer_fields, highlight_field: [:highlight_field], filter: [:filter], sort: [:sort], skip: skip_val, limit: limit, max_time_ms: [:max_time_ms], read_preference: read_preference, class_name: [:class_name] || collection_name, raw: [:raw], ) end |
.session_cache ⇒ Object
Use client.authorization.identity_cache.
132 |
# File 'lib/parse/atlas_search.rb', line 132 def session_cache = &.identity_cache |
.session_cache=(value) ⇒ Object
134 135 136 |
# File 'lib/parse/atlas_search.rb', line 134 def session_cache=(value) &.identity_cache = value end |
.session_cache_ttl ⇒ Object
Use client.authorization.identity_cache_ttl.
Renamed because it never stored sessions: it stores one user id per
token, and the old name led readers to reason about _Session
semantics that were never involved.
118 |
# File 'lib/parse/atlas_search.rb', line 118 def session_cache_ttl = &.identity_cache_ttl || Parse::Authorization::Context::DEFAULT_IDENTITY_TTL |
.session_cache_ttl=(value) ⇒ Object
120 121 122 |
# File 'lib/parse/atlas_search.rb', line 120 def session_cache_ttl=(value) &.identity_cache_ttl = value end |
.upstream_role_reader ⇒ Object
Use client.authorization.upstream_role_reader.
146 |
# File 'lib/parse/atlas_search.rb', line 146 def upstream_role_reader = &.upstream_role_reader |
.upstream_role_reader=(value) ⇒ Object
148 149 150 |
# File 'lib/parse/atlas_search.rb', line 148 def upstream_role_reader=(value) &.upstream_role_reader = value end |