MCPcopy Index your code
hub / github.com/O365/python-o365 / search

Method search

O365/drive.py:1173–1237  ·  view source on GitHub ↗

Search for DriveItems under this folder The search API uses a search service under the covers, which requires indexing of content. As a result, there will be some time between creation of an item and when it will appear in search results. :param str search_

(self, search_text, limit=None, *, query=None, order_by=None,
               batch=None)

Source from the content-addressed store, hash-verified

1171 item.download(to_folder)
1172
1173 def search(self, search_text, limit=None, *, query=None, order_by=None,
1174 batch=None):
1175 """ Search for DriveItems under this folder
1176 The search API uses a search service under the covers,
1177 which requires indexing of content.
1178
1179 As a result, there will be some time between creation of an item
1180 and when it will appear in search results.
1181
1182 :param str search_text: The query text used to search for items.
1183 Values may be matched across several fields including filename,
1184 metadata, and file content.
1185 :param int limit: max no. of folders to get. Over 999 uses batch.
1186 :param query: applies a OData filter to the request
1187 :type query: Query or str
1188 :param order_by: orders the result set based on this condition
1189 :type order_by: Query or str
1190 :param int batch: batch size, retrieves items in
1191 batches allowing to retrieve more items than the limit.
1192 :return: items in this folder matching search
1193 :rtype: generator of DriveItem or Pagination
1194 """
1195 if not isinstance(search_text, str) or not search_text:
1196 raise ValueError('Provide a valid search_text')
1197
1198 url = self.build_url(
1199 self._endpoints.get('search').format(id=self.object_id,
1200 search_text=search_text))
1201
1202 if limit is None or limit > self.protocol.max_top_value:
1203 batch = self.protocol.max_top_value
1204
1205 params = {'$top': batch if batch else limit}
1206
1207 if order_by:
1208 params['$orderby'] = order_by
1209
1210 if query:
1211 if isinstance(query, str):
1212 params['$filter'] = query
1213 else:
1214 if query.has_filters:
1215 warnings.warn(
1216 'Filters are not allowed by the Api '
1217 'Provider in this method')
1218 query.clear_filters()
1219 params.update(query.as_params())
1220
1221 response = self.con.get(url, params=params)
1222 if not response:
1223 return iter(())
1224
1225 data = response.json()
1226
1227 # Everything received from cloud must be passed as self._cloud_data_key
1228 items = (
1229 self._classifier(item)(parent=self, **{self._cloud_data_key: item})
1230 for item in data.get('value', []))

Callers

nothing calls this directly

Calls 8

PaginationClass · 0.85
build_urlMethod · 0.80
as_paramsMethod · 0.80
jsonMethod · 0.80
getMethod · 0.45
clear_filtersMethod · 0.45
updateMethod · 0.45
_classifierMethod · 0.45

Tested by

no test coverage detected