MCPcopy Create free account
hub / github.com/couchbase/couchbase-python-client / search

Method search

couchbase/scope.py:322–408  ·  view source on GitHub ↗

Executes an search against the scope. .. note:: The search is executed lazily in that it is executed once iteration over the :class:`~couchbase.result.SearchResult` begins. .. seealso:: * :class:`~couchbase.management.search.ScopeSearchIndexManag

(self,
               index,  # type: str
               request,  # type: SearchRequest
               *options,  # type: SearchOptions
               **kwargs,  # type: Dict[str, Any]
               )

Source from the content-addressed store, hash-verified

320 return self._impl.search(req)
321
322 def search(self,
323 index, # type: str
324 request, # type: SearchRequest
325 *options, # type: SearchOptions
326 **kwargs, # type: Dict[str, Any]
327 ) -> SearchResult:
328 """Executes an search against the scope.
329
330 .. note::
331 The search is executed lazily in that it is executed once iteration over the
332 :class:`~couchbase.result.SearchResult` begins.
333
334 .. seealso::
335 * :class:`~couchbase.management.search.ScopeSearchIndexManager`: for how to manage search indexes.
336 * :meth:`~couchbase.cluster.Cluster.search`: for how to execute cluster-level search
337
338 Args:
339 index (str): Name of the search index to use.
340 request (:class:`~couchbase.search.SearchRequest`): Type of search request to perform.
341 options (:class:`~couchbase.options.SearchOptions`): Optional parameters for the search query operation.
342 **kwargs (Dict[str, Any]): keyword arguments that can be used in place or to
343 override provided :class:`~couchbase.options.SearchOptions`
344
345 Returns:
346 :class:`~couchbase.result.SearchResult`: An instance of a
347 :class:`~couchbase.result.SearchResult` which provides access to iterate over the search
348 query results and access metadata and metrics about the search query.
349
350 Examples:
351
352 .. note::
353 Be sure to create a search index prior to executing a search. Also, if an application
354 desires to utilize search row locations, highlighting, etc. make sure the search index is
355 setup appropriately. See :search_create_idx:`Creating Indexes <>` in Couchbase Server docs.
356
357 Simple search::
358
359 import couchbase.search as search
360 from couchbase.options import SearchOptions
361
362 # ... other code ...
363
364 request = search.SearchRequest.create(search.TermQuery('home'))
365 q_res = scope.search('travel-sample-index', request, SearchOptions(limit=10))
366
367 for row in q_res.rows():
368 print(f'Found row: {row}')
369
370 Simple vector search::
371
372 import couchbase.search as search
373 from couchbase.options import SearchOptions
374 from couchbase.vector_search import VectorQuery, VectorSearch
375
376 # ... other code ...
377
378 # NOTE: the vector is expected to be type List[float], set the vector to the appropriate value, this is an example.
379 vector = [-0.014653487130999565, -0.008658270351588726, 0.017129190266132355, -0.015563474968075752]

Callers 5

__init__Method · 0.45
search_queryMethod · 0.45
mainFunction · 0.45
mainFunction · 0.45
mainFunction · 0.45

Calls 2

build_search_requestMethod · 0.45

Tested by

no test coverage detected