💬 Commented on "[13.12.0 beta.5]Meilisearchで導入以前の過去のノートを検索できるようにマイグレーションしたい": nakkaa "取り急ぎですが、自分のサーバーの全投稿(公開範囲がpublicかhome)をmeilisearchへ登録するpythonスクリプトを作りました。
うちの検証環境(misskey v13.12.1 on docker, meilisearch v1.1.1 on docker)では問題なさそうですが、利用は自己責任でお願いします。
以下のスクリプトを参考にしました。ありがとうございます。
- CyberRex0/さんの https://gist.github.com/CyberRex0/d481c4c2be6dc47fee4b50cefadf2074
- mattyatea/misskey-meilisearch-oldnote-index
```
# Register local notes on Misskey to Meilisearch
import psycopg2
import psycopg2.extras
import orjson
import requests
# postgresql config
db = psycopg2.connect(
host='localhost',
user='misskey-user',
password='password',
database='misskey',
port=5432,
cursor_factory=psycopg2.extras.DictCursor
)
# meilisearch config
api_key = "APIKEY"
url = "http://localhost:7700/indexes/notes/documents?primaryKey=id"
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
lmt = 100000
ofs = 0
notes = []
while True:
with db.cursor() as cur:
cur.execute('SELECT "id", "createdAt", "userId", "userHost", "channelId", "cw", "text" FROM "note" \
WHERE ("note"."visibility" = \'public\' OR "note"."visibility" = \'home\') AND\
("note"."text" IS NOT NULL) AND\
( "note"."uri" IS NULL) \
LIMIT ' + str(lmt) + ' OFFSET ' + str(ofs))
qnotes = cur.fetchall()
if not qnotes:
break
for note in qnotes:
notes.append({
'id': note['id'],
'text': note['text'],
'createdAt': int(note['createdAt'].timestamp() * 1000),
'userId': note['userId'],
'userHost': note['userHost'],
'channelId': note['channelId'],
'cw': note['cw'],
'text': note['text']
})
print(f'{ofs=} {lmt=} {len(notes)=}')
ofs = ofs + lmt
db.close()
response = requests.post(url, data=orjson.dumps(notes), headers=headers)
print(response.content)
```"
https://github.com/misskey-dev/misskey/issues/10789#issuecomment-1543258958
GitHub - mattyatea/misskey-meilisearch-oldnote-index
[13.12.0 beta.5]Meilisearchで導入以前の過去のノートを検索できるようにマイグレーションしたい · Issue #10789 · misskey-dev/misskey