Skip to content

Commit

Permalink
update core to work with new rc.1
Browse files Browse the repository at this point in the history
  • Loading branch information
yujonglee committed Sep 20, 2024
1 parent 0432dcf commit befa8a2
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 55 deletions.
16 changes: 8 additions & 8 deletions core/assets/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion core/assets/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"typescript": "^5.4.5"
},
"dependencies": {
"@getcanary/web": "^1.0.0-rc.0",
"@getcanary/web": "^1.0.0-rc.1",
"chart.js": "^4.4.4",
"clipboard": "^2.0.11",
"clsx": "^2.1.1",
Expand Down
5 changes: 1 addition & 4 deletions core/lib/canary/interactions/responder.ex
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,7 @@ defmodule Canary.Interactions.Responder.Default do
defp search_results_to_docs(results) do
doc_ids =
results
|> Enum.flat_map(fn %Canary.Searcher.Result{} = result ->
result.hits
|> Enum.flat_map(fn hit -> Enum.map(hit.sub_results, & &1.document_id) end)
end)
|> Enum.flat_map(fn result -> Enum.map(result.sub_results, & &1.document_id) end)
|> Enum.uniq()

Canary.Sources.Document
Expand Down
49 changes: 17 additions & 32 deletions core/lib/canary/searcher.ex
Original file line number Diff line number Diff line change
@@ -1,18 +1,5 @@
defmodule Canary.Searcher.Result do
@derive Jason.Encoder
defstruct [:name, :type, :hits]

@type t :: %__MODULE__{
name: String.t(),
type: String.t(),
hits: list(any())
}
end

defmodule Canary.Searcher do
@callback run(list(any()), String.t()) ::
{:ok, list(Canary.Searcher.Result.t())} | {:error, any()}

@callback run(list(any()), String.t()) :: {:ok, list(map())} | {:error, any()}
def run(sources, query, opts \\ []) do
if opts[:cache] do
with {:error, _} <- get_cache(sources, query),
Expand Down Expand Up @@ -77,28 +64,26 @@ defmodule Canary.Searcher.Default do

defp transform(sources, search_results) do
search_results
|> Enum.map(fn %{source_id: source_id, hits: hits} ->
|> Enum.flat_map(fn %{source_id: source_id, hits: hits} ->
%Canary.Sources.Source{
name: name,
config: %Ash.Union{type: type}
} = sources |> Enum.find(&(&1.id == source_id))

hits =
hits
|> Enum.group_by(& &1.document_id)
|> Enum.map(fn {_, chunks} ->
first = chunks |> Enum.at(0)

%{
# TODO: duplicated, and too many subresults
url: first.url,
title: first.title,
excerpt: first.excerpt,
sub_results: chunks
}
end)

%Canary.Searcher.Result{name: name, type: type, hits: hits}
hits
|> Enum.group_by(& &1.document_id)
|> Enum.map(fn {_, chunks} ->
first = chunks |> Enum.at(0)

%{
# TODO: duplicated, and too many subresults
type: type,
meta: %{},
url: first.url,
title: first.title,
excerpt: first.excerpt,
sub_results: chunks
}
end)
end)
end
end
2 changes: 2 additions & 0 deletions core/lib/canary/sources/document/document.ex
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ defmodule Canary.Sources.Document do
^arg(:chunk_index_ids)
)
)

prepare build(select: [:meta])
end

create :create_webpage do
Expand Down
9 changes: 1 addition & 8 deletions core/lib/canary_web/live/home_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,11 @@ defmodule CanaryWeb.HomeLive do
<canary-provider-cloud
api-key={Enum.at(@current_account.keys, 0).value}
api-base={CanaryWeb.Endpoint.url()}
sources={
@current_account.sources
|> Enum.map(& &1.name)
|> Enum.join(",")
}
>
<canary-content>
<canary-input slot="input"></canary-input>
<canary-search slot="mode">
<canary-search-suggestions slot="body"></canary-search-suggestions>
<canary-search-results group slot="body"></canary-search-results>
<canary-search-empty slot="body"></canary-search-empty>
<canary-search-results slot="body"></canary-search-results>
</canary-search>
</canary-content>
</canary-provider-cloud>
Expand Down
4 changes: 2 additions & 2 deletions core/lib/canary_web/operations_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ defmodule CanaryWeb.OperationsController do
sources = find_sources(conn, sources)

case Canary.Searcher.run(sources, query, cache: cache?()) do
{:ok, search_result} ->
{:ok, matches} ->
data = %{
sources: search_result,
matches: matches,
suggestion: %{questions: Canary.Query.Sugestor.run!(query)}
}

Expand Down

0 comments on commit befa8a2

Please sign in to comment.