@@ -4,6 +4,7 @@ module Mongo
44 module SearchIndex
55 # A class representing a view of search indexes.
66 class View
7+ extend Forwardable
78 include Enumerable
89 include Retryable
910 include Collection ::Helpers
@@ -21,6 +22,8 @@ class View
2122 # when querying the available indexes.
2223 attr_reader :aggregate_options
2324
25+ def_delegators :@collection , :tracer
26+
2427 # Create the new search index view.
2528 #
2629 # @param [ Collection ] collection The collection.
@@ -51,7 +54,10 @@ def initialize(collection, options = {})
5154 #
5255 # @return [ String ] the name of the new search index.
5356 def create_one ( definition , name : nil , type : 'search' )
54- create_many ( [ { name : name , definition : definition , type : type } ] ) . first
57+ spec = { definition : definition , type : type } . tap do |sp |
58+ sp [ :name ] = name unless name . nil?
59+ end
60+ create_many ( [ spec ] ) . first
5561 end
5662
5763 # Create multiple search indexes with a single command.
@@ -64,8 +70,12 @@ def create_one(definition, name: nil, type: 'search')
6470 # @return [ Array<String> ] the names of the new search indexes.
6571 def create_many ( indexes )
6672 spec = spec_with ( indexes : indexes . map { |v | validate_search_index! ( v ) } )
67- result = Operation ::CreateSearchIndexes . new ( spec ) . execute ( next_primary , context : execution_context )
68- result . first [ 'indexesCreated' ] . map { |idx | idx [ 'name' ] }
73+ operation = Operation ::CreateSearchIndexes . new ( spec )
74+ context = execution_context
75+ tracer . trace_operation ( operation , context , op_name : 'createSearchIndexes' ) do
76+ result = operation . execute ( next_primary , context : context )
77+ result . first [ 'indexesCreated' ] . map { |idx | idx [ 'name' ] }
78+ end
6979 end
7080
7181 # Drop the search index with the given id, or name. One or the other must
@@ -81,11 +91,14 @@ def drop_one(id: nil, name: nil)
8191
8292 spec = spec_with ( index_id : id , index_name : name )
8393 op = Operation ::DropSearchIndex . new ( spec )
94+ context = execution_context
8495
85- # per the spec:
86- # Drivers MUST suppress NamespaceNotFound errors for the
87- # ``dropSearchIndex`` helper. Drop operations should be idempotent.
88- do_drop ( op , nil , execution_context )
96+ tracer . trace_operation ( op , context , op_name : 'dropSearchIndex' ) do
97+ # per the spec:
98+ # Drivers MUST suppress NamespaceNotFound errors for the
99+ # ``dropSearchIndex`` helper. Drop operations should be idempotent.
100+ do_drop ( op , nil , context )
101+ end
89102 end
90103
91104 # Iterate over the search indexes.
@@ -127,7 +140,11 @@ def update_one(definition, id: nil, name: nil)
127140 validate_id_or_name! ( id , name )
128141
129142 spec = spec_with ( index_id : id , index_name : name , index : definition )
130- Operation ::UpdateSearchIndex . new ( spec ) . execute ( next_primary , context : execution_context )
143+ op = Operation ::UpdateSearchIndex . new ( spec )
144+ context = execution_context
145+ tracer . trace_operation ( op , context , op_name : 'updateSearchIndex' ) do
146+ op . execute ( next_primary , context : context )
147+ end
131148 end
132149
133150 # The following methods are to make the view act more like an array,
0 commit comments