Skip to content

Commit

Permalink
Merge pull request #228 from pulibrary/104-typespecs
Browse files Browse the repository at this point in the history
Add and fix typespecs in solr.ex and coherence.ex
  • Loading branch information
hackartisan authored Nov 11, 2024
2 parents 1025500 + 9263d44 commit 3c75447
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/dpul_collections/indexing_pipeline/coherence.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule DpulCollections.IndexingPipeline.Coherence do
alias DpulCollections.Solr
alias DpulCollections.IndexingPipeline

@spec index_parity?() :: boolean()
def index_parity?() do
pms =
Application.fetch_env!(:dpul_collections, DpulCollections.IndexingPipeline)
Expand All @@ -14,6 +15,7 @@ defmodule DpulCollections.IndexingPipeline.Coherence do
version_sorted == date_sorted
end

@spec document_count_report() :: map()
def document_count_report() do
Application.fetch_env!(:dpul_collections, DpulCollections.IndexingPipeline)
|> Enum.map(fn pipeline ->
Expand Down
17 changes: 14 additions & 3 deletions lib/dpul_collections/solr.ex
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule DpulCollections.Solr do
# @spec document_count() :: integer()
@spec document_count(String.t()) :: integer()
def document_count(collection \\ read_collection()) do
{:ok, response} =
Req.get(
Expand All @@ -20,7 +20,7 @@ defmodule DpulCollections.Solr do
"image_service_urls_ss"
]

@spec query(map()) :: map()
@spec query(map(), String.t()) :: map()
def query(search_state, collection \\ read_collection()) do
fl = Enum.join(@query_field_list, ",")

Expand Down Expand Up @@ -67,6 +67,7 @@ defmodule DpulCollections.Solr do
max(page - 1, 0) * per_page
end

@spec latest_document(String.t()) :: map()
def latest_document(collection \\ read_collection()) do
{:ok, response} =
Req.get(
Expand All @@ -80,6 +81,7 @@ defmodule DpulCollections.Solr do
end
end

@spec find_by_id(String.t(), String.t()) :: map()
def find_by_id(id, collection \\ read_collection()) do
{:ok, response} =
Req.get(
Expand Down Expand Up @@ -130,6 +132,7 @@ defmodule DpulCollections.Solr do
|> Req.merge(url: "/solr/#{collection}/update")
end

@spec client() :: Req.Request.t()
def client() do
url_hash = Application.fetch_env!(:dpul_collections, :solr)

Expand All @@ -145,18 +148,21 @@ defmodule DpulCollections.Solr do
{:basic, "#{username}:#{password}"}
end

@spec read_collection() :: String.t()
def read_collection() do
Application.fetch_env!(:dpul_collections, :solr)[:read_collection]
end

@spec config_set() :: String.t()
def config_set() do
Application.fetch_env!(:dpul_collections, :solr)[:config_set]
end

####
# Solr management api wrappers
####
def list_collections do
@spec list_collections() :: list(String.t())
def list_collections() do
{:ok, response} =
client()
|> Req.merge(url: "/api/collections")
Expand All @@ -165,10 +171,12 @@ defmodule DpulCollections.Solr do
response.body["collections"]
end

@spec collection_exists?(String.t()) :: boolean()
def collection_exists?(collection) do
collection in list_collections()
end

@spec create_collection(String.t()) :: Req.Response.t()
def create_collection(collection) do
client()
|> Req.merge(url: "/api/collections")
Expand All @@ -185,12 +193,14 @@ defmodule DpulCollections.Solr do
)
end

@spec delete_collection(String.t()) :: Req.Response.t()
def delete_collection(collection) do
client()
|> Req.merge(url: "api/collections/#{collection}")
|> Req.delete!()
end

@spec get_alias() :: String.t()
def get_alias do
{:ok, response} =
client()
Expand All @@ -203,6 +213,7 @@ defmodule DpulCollections.Solr do
response.body["aliases"][read_collection()]
end

@spec set_alias(String.t()) :: Req.Response.t()
def set_alias(collection) do
client()
|> Req.merge(url: "api/c")
Expand Down

0 comments on commit 3c75447

Please sign in to comment.