Skip to content

Commit 3824211

Browse files
authored
3.10 changes to views, indexes and analyzers (#221)
1 parent ef48710 commit 3824211

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

arango/collection.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1294,6 +1294,75 @@ def add_ttl_index(
12941294

12951295
return self._add_index(data)
12961296

1297+
def add_inverted_index(
1298+
self,
1299+
fields: Json,
1300+
name: Optional[str] = None,
1301+
inBackground: Optional[bool] = None,
1302+
parallelism: Optional[int] = None,
1303+
primarySort: Optional[Json] = None,
1304+
storedValues: Optional[Sequence[Json]] = None,
1305+
analyzer: Optional[str] = None,
1306+
features: Optional[Sequence[str]] = None,
1307+
includeAllFields: Optional[bool] = None,
1308+
trackListPositions: Optional[bool] = None,
1309+
searchField: Optional[bool] = None,
1310+
) -> Result[Json]:
1311+
"""Create a new inverted index, introduced in version 3.10.
1312+
1313+
:param fields: Document fields to index.
1314+
:type fields: Json
1315+
:param name: Optional name for the index.
1316+
:type name: str | None
1317+
:param inBackground: Do not hold the collection lock.
1318+
:type inBackground: bool | None
1319+
:param parallelism:
1320+
:type parallelism: int | None
1321+
:param primarySort:
1322+
:type primarySort: Json | None
1323+
:param storedValues:
1324+
:type storedValues: Sequence[Json] | None
1325+
:param analyzer:
1326+
:type analyzer: str | None
1327+
:param features:
1328+
:type features: Sequence[str] | None
1329+
:param includeAllFields:
1330+
:type includeAllFields: bool | None
1331+
:param trackListPositions:
1332+
:type trackListPositions: bool | None
1333+
:param searchField:
1334+
:type searchField: bool | None
1335+
:return: New index details.
1336+
:rtype: dict
1337+
:raise arango.exceptions.IndexCreateError: If create fails.
1338+
"""
1339+
data: Json = {"type": "inverted", "fields": fields}
1340+
1341+
if name is not None:
1342+
data["name"] = name
1343+
if inBackground is not None:
1344+
data["inBackground"] = inBackground
1345+
if parallelism is not None:
1346+
data["parallelism"] = parallelism
1347+
if primarySort is not None:
1348+
data["primarySort"] = primarySort
1349+
if storedValues is not None:
1350+
data["storedValues"] = storedValues
1351+
if analyzer is not None:
1352+
data["analyzer"] = analyzer
1353+
if features is not None:
1354+
data["features"] = features
1355+
if includeAllFields is not None:
1356+
data["includeAllFields"] = includeAllFields
1357+
if trackListPositions is not None:
1358+
data["trackListPositions"] = trackListPositions
1359+
if searchField is not None:
1360+
data["searchField"] = searchField
1361+
if fields is not None:
1362+
data["fields"] = fields
1363+
1364+
return self._add_index(data)
1365+
12971366
def delete_index(self, index_id: str, ignore_missing: bool = False) -> Result[bool]:
12981367
"""Delete an index.
12991368

arango/database.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2113,7 +2113,7 @@ def create_view(
21132113
21142114
:param name: View name.
21152115
:type name: str
2116-
:param view_type: View type (e.g. "arangosearch").
2116+
:param view_type: View type (e.g. "arangosearch" or "search-alias").
21172117
:type view_type: str
21182118
:param properties: View properties. For more information see
21192119
https://www.arangodb.com/docs/stable/http/views-arangosearch.html

arango/formatter.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,6 +798,23 @@ def format_view_link(body: Json) -> Json:
798798
return verify_format(body, result)
799799

800800

801+
def format_view_index(body: Json) -> Json:
802+
"""Format view index data.
803+
804+
:param body: Input body.
805+
:type body: dict
806+
:return: Formatted body.
807+
:rtype: dict
808+
"""
809+
result: Json = {}
810+
if "collection" in body:
811+
result["collection"] = body["collection"]
812+
if "index" in body:
813+
result["index"] = body["index"]
814+
815+
return verify_format(body, result)
816+
817+
801818
def format_view_consolidation_policy(body: Json) -> Json:
802819
"""Format view consolidation policy data.
803820
@@ -868,6 +885,10 @@ def format_view(body: Json) -> Json:
868885
result["links"] = {
869886
name: format_view_link(link) for name, link in body["links"].items()
870887
}
888+
if "indexes" in body:
889+
result["indexes"] = {
890+
name: format_view_index(idx) for name, idx in body["indexes"].items()
891+
}
871892

872893
return verify_format(body, result)
873894

0 commit comments

Comments
 (0)