-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Advanced searching with elasticsearch π₯π - PHASE 1 (basic) (#350)
This PR adds - elasticsearch integration for product search - updates product search API. - updates docker build to work with webpack.
- Loading branch information
Showing
26 changed files
with
938 additions
and
186 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.git | ||
.scripts | ||
_build | ||
cover | ||
erl_crash.dump | ||
uploads | ||
.elixir_ls | ||
.github | ||
deps | ||
vendor | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,3 +25,6 @@ erl_crash.dump | |
|
||
/env/local.env | ||
/env/prod.env | ||
|
||
/vendor/ | ||
/uploads/images/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
apps/snitch_api/lib/snitch_api_web/views/elasticsearch/product_view.ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
defmodule SnitchApiWeb.Elasticsearch.ProductView do | ||
use SnitchApiWeb, :view | ||
use JaSerializer.PhoenixView | ||
|
||
attributes([ | ||
:id, | ||
# :parent_id, | ||
# :has_parent, | ||
:slug, | ||
:name, | ||
:updated_at, | ||
:images, | ||
:rating_summary, | ||
:selling_price, | ||
:max_retail_price, | ||
:brand | ||
]) | ||
|
||
defp source(product), do: product["_source"] | ||
|
||
|
||
defp id(product) do | ||
[_, id] = String.split(product["_id"], "_") | ||
String.to_integer(id) | ||
end | ||
|
||
# defp parent_id(product), do: source(product)["parent_id"] | ||
|
||
# defp has_parent(product), do: parent_id(product) == id(product) | ||
|
||
defp slug(product), do: source(product)["slug"] | ||
|
||
defp name(product), do: source(product)["name"] | ||
|
||
defp updated_at(product), do: source(product)["updated_at"] | ||
|
||
defp images(product), do: source(product)["images"] | ||
|
||
defp rating_summary(product), do: source(product)["rating_summary"] | ||
|
||
defp selling_price(product), do: source(product)["selling_price"] | ||
|
||
defp max_retail_price(product), do: source(product)["max_retail_price"] | ||
|
||
defp brand(product), do: source(product)["brand"] | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use Mix.Config | ||
|
||
config :snitch_core, Snitch.Tools.ElasticsearchCluster, | ||
# The URL where Elasticsearch is hosted on your system | ||
url: System.get_env("ELASTIC_HOST"), | ||
|
||
# If your Elasticsearch cluster uses HTTP basic authentication, | ||
# specify the username and password here: | ||
# username: "username", | ||
# password: "password", | ||
|
||
# If you want to mock the responses of the Elasticsearch JSON API | ||
# for testing or other purposes, you can inject a different module | ||
# here. It must implement the Elasticsearch.API behaviour. | ||
api: Elasticsearch.API.HTTP, | ||
|
||
# Customize the library used for JSON encoding/decoding. | ||
# or Jason | ||
json_library: Poison, | ||
|
||
# You should configure each index which you maintain in Elasticsearch here. | ||
# This configuration will be read by the `mix elasticsearch.build` task, | ||
# described below. | ||
indexes: %{ | ||
# This is the base name of the Elasticsearch index. Each index will be | ||
# built with a timestamp included in the name, like "products-5902341238". | ||
# It will then be aliased to "products" for easy querying. | ||
products: %{ | ||
# This file describes the mappings and settings for your index. It will | ||
# be posted as-is to Elasticsearch when you create your index, and | ||
# therefore allows all the settings you could post directly. | ||
settings: "priv/elasticsearch/products.json", | ||
|
||
# This store module must implement a store behaviour. It will be used to | ||
# fetch data for each source in each indexes' `sources` list, below: | ||
store: Snitch.Tools.ElasticSearch.ProductStore, | ||
|
||
# This is the list of data sources that should be used to populate this | ||
# index. The `:store` module above will be passed each one of these | ||
# sources for fetching. | ||
# | ||
# Each piece of data that is returned by the store must implement the | ||
# Elasticsearch.Document protocol. | ||
sources: [Snitch.Data.Schema.Product], | ||
|
||
# When indexing data using the `mix elasticsearch.build` task, | ||
# control the data ingestion rate by raising or lowering the number | ||
# of items to send in each bulk request. | ||
bulk_page_size: 5000, | ||
|
||
# Likewise, wait a given period between posting pages to give | ||
# Elasticsearch time to catch up. | ||
# 15 seconds | ||
bulk_wait_interval: 15_000 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.