class_docstr: Generic service for search records operations
class_docstr_tok: ["Generic","service","for","search","records","operations"]
code: def search(
      self,
      dataset: ServiceDataset,
      record_type: Type[ServiceRecord],
      query: Optional[ServiceRecordsQuery] = None,
      sort_config: Optional[ServiceSortConfig] = None,
      record_from: int = 0,
      size: int = 100,
      exclude_metrics: bool = True,
      metrics: Optional[List[ServiceMetric]] = None,
  ) -> ServiceSearchResults:
      if record_from > 0:
          metrics = None
  
      sort_config = sort_config or ServiceSortConfig()
      exclude_fields = ["metrics.*"] if exclude_metrics else None
      if query and query.vector and not query.vector.k:
          query.vector.k = size
      results = self.__dao__.search_records(
          dataset,
          search=DaoRecordsSearch(
              query=query,
              sort=sort_config,
          ),
          size=size,
          record_from=record_from,
          exclude_fields=exclude_fields,
          highligth_results=query is not None
          and query.query_text is not None
          and len(query.query_text) > 0,
      )
      metrics_results = {}
      for metric in metrics or []:
          try:
              metrics_ = self.__metrics__.summarize_metric(
                  dataset=dataset,
                  metric=metric,
                  record_class=record_type,
                  query=query,
              )
              metrics_results[metric.id] = metrics_
          except Exception as ex:
              self.__LOGGER__.warning(
                  "Cannot compute metric [%s]. Error: %s", metric.id, ex
              )
              metrics_results[metric.id] = {}
  
      return ServiceSearchResults(
          total=results.total,
          records=[record_type.parse_obj(r) for r in results.records],
          metrics=metrics_results if metrics_results else {},
      )
  
file_path: argilla/src/argilla/server/services/search/service.py
imports: import logging
  from typing import Iterable, List, Optional, Set, Type, Union
  from fastapi import Depends
  from argilla.server.daos.models.records import DaoRecordsSearch
  from argilla.server.daos.records import DatasetRecordsDAO
  from argilla.server.errors import RecordNotFound
  from argilla.server.services.datasets import ServiceDataset
  from argilla.server.services.metrics import MetricsService
  from argilla.server.services.metrics.models import ServiceMetric
  from argilla.server.services.search.model import ServiceRecord, ServiceRecordsQuery, ServiceSearchResults, ServiceSortConfig
label_desc: Use image node_id 3 for calling the SearchRecordsService obj's underlying member method code with example usage: obj.search(dataset, record_type, query, sort_config, record_from, size, exclude_metrics, metrics) and returns: ServiceSearchResults