Skip to content

Commit bec09ed

Browse files
committed
Node API updated.
1 parent b6accd7 commit bec09ed

File tree

3 files changed

+75
-5
lines changed

3 files changed

+75
-5
lines changed

src/moeralib/node/node.py

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,7 +1939,7 @@ def get_remote_sheriff_order(self, node_name: str, id: str) -> types.SheriffOrde
19391939
)
19401940
return types.SheriffOrderInfo.from_json(data)
19411941

1942-
def search_nodes(self, query: str | None = None, limit: int | None = None) -> List[types.SearchNodeInfo]:
1942+
def search_nodes(self, filter: types.SearchNodeFilter) -> types.SearchNodePageInfo:
19431943
"""
19441944
Search for Moera nodes matching the search ``query``. Every space-delimited word in the query must match
19451945
case-insensitively a beginning of the node's name or a beginning of any non-letter-delimited word in the node's
@@ -1950,13 +1950,36 @@ def search_nodes(self, query: str | None = None, limit: int | None = None) -> Li
19501950
The returned nodes are sorted by their relevance. The exact definition of this term is left to the search
19511951
engine's implementation.
19521952
1953+
:param filter:
1954+
"""
1955+
location = "/search/nodes"
1956+
data = self.call(
1957+
"search_nodes", location, method="POST", body=filter, schema=schemas.SEARCH_NODE_PAGE_INFO_SCHEMA
1958+
)
1959+
return types.SearchNodePageInfo.from_json(data)
1960+
1961+
def search_node_suggestions(
1962+
self, query: str | None = None, sheriff: str | None = None, limit: int | None = None
1963+
) -> List[types.SearchNodeInfo]:
1964+
"""
1965+
Search for Moera nodes matching the search ``query`` and return a short list of "smart suggestions" for the
1966+
user. Every space-delimited word in the query must match case-insensitively a beginning of the node's name or a
1967+
beginning of any non-letter-delimited word in the node's full name. The order of words is not significant.
1968+
1969+
The search engine may decide to return fewer nodes than the given ``limit``.
1970+
1971+
The returned nodes are sorted by their relevance. The exact definition of this term is left to the search
1972+
engine's implementation.
1973+
19531974
:param query: the search query
1975+
:param sheriff: filter out entries prohibited by the given sheriff
19541976
:param limit: maximum number of nodes returned
19551977
"""
1956-
location = "/search/nodes".format()
1957-
params = {"query": query, "limit": limit}
1978+
location = "/search/nodes/suggestions".format()
1979+
params = {"query": query, "sheriff": sheriff, "limit": limit}
19581980
data = self.call(
1959-
"search_nodes", location, method="GET", params=params, schema=schemas.SEARCH_NODE_INFO_ARRAY_SCHEMA
1981+
"search_node_suggestions", location, method="GET", params=params,
1982+
schema=schemas.SEARCH_NODE_INFO_ARRAY_SCHEMA
19601983
)
19611984
return structure_list(data, types.SearchNodeInfo)
19621985

src/moeralib/node/schemas.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1611,6 +1611,28 @@
16111611

16121612
SEARCH_NODE_INFO_ARRAY_SCHEMA = array_schema(SEARCH_NODE_INFO_SCHEMA)
16131613

1614+
SEARCH_NODE_PAGE_INFO_SCHEMA: Any = {
1615+
"type": "object",
1616+
"properties": {
1617+
"page": {
1618+
"type": "integer"
1619+
},
1620+
"total": {
1621+
"type": "integer"
1622+
},
1623+
"nodes": {
1624+
"type": "array",
1625+
"items": SEARCH_NODE_INFO_SCHEMA
1626+
},
1627+
},
1628+
"required": [
1629+
"page",
1630+
"total",
1631+
"nodes",
1632+
],
1633+
"additionalProperties": False
1634+
}
1635+
16141636
SEARCH_REPLIED_TO_SCHEMA: Any = {
16151637
"type": "object",
16161638
"properties": {
@@ -2902,6 +2924,9 @@
29022924
"bodyPreview": {
29032925
"type": "string"
29042926
},
2927+
"bodyFormat": {
2928+
"type": ["string", "null"]
2929+
},
29052930
"heading": {
29062931
"type": "string"
29072932
},

src/moeralib/node/types.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1759,6 +1759,17 @@ class SearchHashtagFilter(Structure):
17591759
"""maximum number of entries returned"""
17601760

17611761

1762+
class SearchNodeFilter(Structure):
1763+
query: str
1764+
"""the search query"""
1765+
sheriff_name: str | None = None
1766+
"""filter out nodes prohibited by the given sheriff"""
1767+
page: int | None = None
1768+
"""page number, 0 by default"""
1769+
limit: int | None = None
1770+
"""page size (maximum number of entries returned), the default is set by the search engine"""
1771+
1772+
17621773
class SearchNodeInfo(Structure):
17631774
node_name: str
17641775
full_name: str | None = None
@@ -1771,6 +1782,15 @@ class SearchNodeInfo(Structure):
17711782
"""social distance between the node and the client"""
17721783

17731784

1785+
class SearchNodePageInfo(Structure):
1786+
page: int
1787+
"""number of the page"""
1788+
total: int
1789+
"""total number of nodes found (this number may be approximate)"""
1790+
nodes: List[SearchNodeInfo]
1791+
"""the nodes"""
1792+
1793+
17741794
class SearchPostingUpdate(Structure):
17751795
feed_name: str
17761796
"""name of the feed where the posting is published"""
@@ -2965,6 +2985,8 @@ class SearchEntryInfo(Structure):
29652985
"""avatar of the entry's owner"""
29662986
body_preview: Body
29672987
"""preview of the entry's body, a string representation of a JSON structure"""
2988+
body_format: BodyFormat | None = None
2989+
"""format of the entry's body, may have any value meaningful for the client"""
29682990
heading: str
29692991
"""heading of the entry"""
29702992
image_count: int | None = None
@@ -2994,7 +3016,7 @@ class SearchTextPageInfo(Structure):
29943016
page: int
29953017
"""number of the page"""
29963018
total: int
2997-
"""total number of pages"""
3019+
"""total number of entries found"""
29983020
entries: List[SearchEntryInfo]
29993021
"""the entries"""
30003022

0 commit comments

Comments
 (0)