forked from AkkomaGang/akkoma
add hashtag indexing
This commit is contained in:
parent
6bb19454fd
commit
8547cefaff
4 changed files with 43 additions and 1 deletions
|
@ -9,6 +9,7 @@ defmodule Mix.Tasks.Pleroma.Search do
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Pagination
|
alias Pleroma.Pagination
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
alias Pleroma.Hashtag
|
||||||
|
|
||||||
@shortdoc "Manages elasticsearch"
|
@shortdoc "Manages elasticsearch"
|
||||||
|
|
||||||
|
@ -29,8 +30,16 @@ def run(["import", "users" | _rest]) do
|
||||||
|> get_all(:users)
|
|> get_all(:users)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def run(["import", "hashtags" | _rest]) do
|
||||||
|
start_pleroma()
|
||||||
|
|
||||||
|
from(h in Hashtag)
|
||||||
|
|> Pleroma.Repo.all()
|
||||||
|
|> Pleroma.Elasticsearch.bulk_post(:hashtags)
|
||||||
|
end
|
||||||
|
|
||||||
defp get_all(query, index, max_id \\ nil) do
|
defp get_all(query, index, max_id \\ nil) do
|
||||||
params = %{limit: 2000}
|
params = %{limit: 1000}
|
||||||
|
|
||||||
params =
|
params =
|
||||||
if max_id == nil do
|
if max_id == nil do
|
||||||
|
|
10
lib/pleroma/elasticsearch/document_mappings/hashtag.ex
Normal file
10
lib/pleroma/elasticsearch/document_mappings/hashtag.ex
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
defmodule Pleroma.Elasticsearch.DocumentMappings.Hashtag do
|
||||||
|
def id(obj), do: obj.id
|
||||||
|
|
||||||
|
def encode(hashtag) do
|
||||||
|
%{
|
||||||
|
hashtag: hashtag.name,
|
||||||
|
timestamp: hashtag.inserted_at
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
|
@ -85,6 +85,25 @@ def bulk_post(data, :users) do
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def bulk_post(data, :hashtags) do
|
||||||
|
d =
|
||||||
|
data
|
||||||
|
|> Enum.map(fn d ->
|
||||||
|
[
|
||||||
|
%{index: %{_id: DocumentMappings.Hashtag.id(d)}},
|
||||||
|
DocumentMappings.Hashtag.encode(d)
|
||||||
|
]
|
||||||
|
end)
|
||||||
|
|> List.flatten()
|
||||||
|
|
||||||
|
Elastix.Bulk.post(
|
||||||
|
url(),
|
||||||
|
d,
|
||||||
|
index: "hashtags",
|
||||||
|
type: "hashtag"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
def search_activities(q) do
|
def search_activities(q) do
|
||||||
Elastix.Search.search(
|
Elastix.Search.search(
|
||||||
url(),
|
url(),
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
{
|
{
|
||||||
"properties": {
|
"properties": {
|
||||||
|
"timestamp": {
|
||||||
|
"type": "date",
|
||||||
|
"index": true
|
||||||
|
},
|
||||||
"hashtag": {
|
"hashtag": {
|
||||||
"type": "text"
|
"type": "text"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue