Skip to content

Commit

Permalink
New quick search concept (#311)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkis committed Aug 12, 2024
1 parent 9c365c2 commit d114adc
Show file tree
Hide file tree
Showing 16 changed files with 582 additions and 281 deletions.
140 changes: 130 additions & 10 deletions Tekst-API/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -1576,7 +1576,14 @@
"in": "query",
"required": false,
"schema": {
"type": "integer",
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"description": "Structure level to find locations for",
"title": "Lvl"
},
Expand All @@ -1587,7 +1594,14 @@
"in": "query",
"required": false,
"schema": {
"type": "integer",
"anyOf": [
{
"type": "integer"
},
{
"type": "null"
}
],
"description": "Position value of locations to find",
"title": "Pos"
},
Expand All @@ -1598,8 +1612,15 @@
"in": "query",
"required": false,
"schema": {
"type": "string",
"example": "5eb7cf5a86d9755df3a6c593",
"anyOf": [
{
"type": "string",
"example": "5eb7cf5a86d9755df3a6c593"
},
{
"type": "null"
}
],
"description": "ID of parent location to find children of",
"title": "Parent"
},
Expand Down Expand Up @@ -1656,6 +1677,78 @@
}
}
},
"/locations/by-alias": {
"get": {
"tags": [
"locations"
],
"summary": "Find locations by alias",
"operationId": "findLocationsByAlias",
"parameters": [
{
"name": "txt",
"in": "query",
"required": true,
"schema": {
"type": "string",
"example": "5eb7cf5a86d9755df3a6c593",
"description": "ID of text to find locations for",
"title": "Txt"
},
"description": "ID of text to find locations for"
},
{
"name": "alias",
"in": "query",
"required": true,
"schema": {
"type": "string",
"description": "Alias of location(s) to find",
"title": "Alias"
},
"description": "Alias of location(s) to find"
},
{
"name": "limit",
"in": "query",
"required": false,
"schema": {
"type": "integer",
"description": "Return at most <limit> locations (maximum returned is 10)",
"default": 10,
"title": "Limit"
},
"description": "Return at most <limit> locations (maximum returned is 10)"
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"type": "array",
"items": {
"$ref": "#/components/schemas/LocationRead"
},
"title": "Response Find Locations By Alias Locations By Alias Get"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
},
"/locations/first-last-paths": {
"get": {
"tags": [
Expand Down Expand Up @@ -9570,6 +9663,12 @@
},
"GeneralPlainTextResourceConfig": {
"properties": {
"defaultCollapsed": {
"type": "boolean",
"title": "Defaultcollapsed",
"description": "Whether contents of this resource should be collapsed by default",
"default": false
},
"font": {
"anyOf": [
{
Expand All @@ -9582,12 +9681,6 @@
"title": "Font",
"description": "Name of the font to use for this resource."
},
"defaultCollapsed": {
"type": "boolean",
"title": "Defaultcollapsed",
"description": "Whether contents of this resource should be collapsed by default",
"default": false
},
"reducedView": {
"allOf": [
{
Expand Down Expand Up @@ -10706,6 +10799,15 @@
"minLength": 1,
"title": "Label",
"description": "Label for identifying this text location in level context"
},
"aliases": {
"items": {
"type": "string"
},
"type": "array",
"title": "Aliases",
"description": "List of aliases for this location",
"default": []
}
},
"type": "object",
Expand Down Expand Up @@ -10803,6 +10905,15 @@
"minLength": 1,
"title": "Label",
"description": "Label for identifying this text location in level context"
},
"aliases": {
"items": {
"type": "string"
},
"type": "array",
"title": "Aliases",
"description": "List of aliases for this location",
"default": []
}
},
"additionalProperties": true,
Expand Down Expand Up @@ -10880,6 +10991,15 @@
}
],
"title": "Label"
},
"aliases": {
"items": {
"type": "string"
},
"type": "array",
"title": "Aliases",
"description": "List of aliases for this location",
"default": []
}
},
"type": "object",
Expand Down
7 changes: 7 additions & 0 deletions Tekst-API/tekst/models/location.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class Location(ModelBase, ModelFactoryMixin):
description="Label for identifying this text location in level context",
),
]
aliases: Annotated[
list[str],
Field(
description="List of aliases for this location",
),
] = []


class LocationDocument(Location, DocumentBase):
Expand All @@ -64,6 +70,7 @@ class Settings(DocumentBase.Settings):
"parent_id",
"level",
"position",
"aliases",
]


Expand Down
65 changes: 59 additions & 6 deletions Tekst-API/tekst/routers/locations.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,20 +129,37 @@ async def create_location(su: SuperuserDep, location: LocationCreate) -> Locatio
async def find_locations(
text_id: Annotated[
PydanticObjectId,
Query(alias="txt", description="ID of text to find locations for"),
Query(
alias="txt",
description="ID of text to find locations for",
),
],
level: Annotated[
int, Query(alias="lvl", description="Structure level to find locations for")
int | None,
Query(
alias="lvl",
description="Structure level to find locations for",
),
] = None,
position: Annotated[
int, Query(alias="pos", description="Position value of locations to find")
int | None,
Query(
alias="pos",
description="Position value of locations to find",
),
] = None,
parent_id: Annotated[
PydanticObjectId,
Query(alias="parent", description="ID of parent location to find children of"),
PydanticObjectId | None,
Query(
alias="parent",
description="ID of parent location to find children of",
),
] = None,
limit: Annotated[
int, Query(description="Return at most <limit> locations")
int,
Query(
description="Return at most <limit> locations",
),
] = 16384,
) -> list[LocationDocument]:
if level is None and parent_id is None:
Expand All @@ -162,6 +179,42 @@ async def find_locations(
return await LocationDocument.find(example).limit(limit).to_list()


@router.get(
"/by-alias",
response_model=list[LocationRead],
status_code=status.HTTP_200_OK,
)
async def find_locations_by_alias(
text_id: Annotated[
PydanticObjectId,
Query(
alias="txt",
description="ID of text to find locations for",
),
],
alias: Annotated[
str,
Query(
description="Alias of location(s) to find",
),
],
limit: Annotated[
int,
Query(
description="Return at most <limit> locations (maximum returned is 10)",
),
] = 10,
) -> list[LocationDocument]:
return (
await LocationDocument.find(
LocationDocument.text_id == text_id,
LocationDocument.aliases == alias,
)
.limit(min(limit, 10))
.to_list()
)


@router.get(
"/first-last-paths",
response_model=Annotated[
Expand Down
Loading

0 comments on commit d114adc

Please sign in to comment.