[deploy] Remove ALL Algolia Code (#7577)
This commit is contained in:
parent
8407bf9b4e
commit
4c779be2ed
26 changed files with 112 additions and 315 deletions
|
|
@ -18,14 +18,6 @@ tasks:
|
|||
- command: /home/gitpod/elasticsearch-7.5.2/bin/elasticsearch
|
||||
- init: cp config/sample_application.yml config/application.yml
|
||||
command: >
|
||||
while [ -z "${ALGOLIASEARCH_APPLICATION_ID:=$(cat config/application.yml | grep ALGOLIASEARCH_APPLICATION_ID | sed 's/.*:\s*//')}" ] ||
|
||||
[ -z "${ALGOLIASEARCH_SEARCH_ONLY_KEY:=$(cat config/application.yml | grep ALGOLIASEARCH_SEARCH_ONLY_KEY | sed 's/.*:\s*//')}" ] ||
|
||||
[ -z "${ALGOLIASEARCH_API_KEY:=$(cat config/application.yml | grep ALGOLIASEARCH_API_KEY | sed 's/.*:\s*//')}" ] ; do
|
||||
gp open config/application.yml 2>/dev/null &&
|
||||
printf "\n❗ Dev.to requires free Algolia credentials.\n" &&
|
||||
printf "❗ To get them, please follow https://docs.dev.to/backend/algolia/#get-api-keys\n\n" &&
|
||||
read -p "Add them to config/application.yml, save the file, and press any key to continue... " -n 1 -r
|
||||
done ;
|
||||
gem install solargraph;
|
||||
bin/setup &&
|
||||
bin/startup
|
||||
|
|
|
|||
7
Envfile
7
Envfile
|
|
@ -65,13 +65,6 @@ variable :TWITTER_SECRET, :String, default: "Optional"
|
|||
variable :HONEYBADGER_API_KEY, :String, default: "Optional"
|
||||
variable :HONEYBADGER_JS_API_KEY, :String, default: "Optional"
|
||||
|
||||
# Algolia for search (not optional)
|
||||
# (https://www.algolia.com/doc/)
|
||||
only_in_test = proc { ENV["RACK_ENV"] == "test" ? "test-test" : nil }
|
||||
variable :ALGOLIASEARCH_API_KEY, :String, default: only_in_test
|
||||
variable :ALGOLIASEARCH_APPLICATION_ID, :String, default: only_in_test
|
||||
variable :ALGOLIASEARCH_SEARCH_ONLY_KEY, :String, default: only_in_test
|
||||
|
||||
# AWS for images storages
|
||||
variable :AWS_ID, :String, default: "Optional"
|
||||
variable :AWS_SECRET, :String, default: "Optional"
|
||||
|
|
|
|||
1
Gemfile
1
Gemfile
|
|
@ -17,7 +17,6 @@ gem "acts_as_follower", github: "thepracticaldev/acts_as_follower", branch: "mas
|
|||
gem "addressable", "~> 2.7" # A replacement for the URI implementation that is part of Ruby's standard library
|
||||
gem "administrate", "~> 0.13" # A Rails engine that helps you put together a super-flexible admin dashboard
|
||||
gem "ahoy_email", "~> 1.1" # Email analytics for Rails
|
||||
gem "algoliasearch-rails", "~> 1.24" # Algolia Search is a hosted search engine capable of delivering real-time results from the first keystroke
|
||||
gem "algorithmia", "~> 1.1" # Ruby Client for Algorithmia Algorithms and Data API
|
||||
gem "ancestry", "~> 3.0" # Ancestry allows the records of a ActiveRecord model to be organized in a tree structure
|
||||
gem "autoprefixer-rails", "~> 9.7" # Parse CSS and add vendor prefixes to CSS rules using values from the Can I Use website
|
||||
|
|
|
|||
|
|
@ -77,12 +77,6 @@ GEM
|
|||
addressable (>= 2.3.2)
|
||||
nokogiri
|
||||
safely_block (>= 0.1.1)
|
||||
algoliasearch (1.27.1)
|
||||
httpclient (~> 2.8, >= 2.8.3)
|
||||
json (>= 1.5.1)
|
||||
algoliasearch-rails (1.24.0)
|
||||
algoliasearch (>= 1.26.0, < 2.0.0)
|
||||
json (>= 1.5.1)
|
||||
algorithmia (1.1.0)
|
||||
httparty (~> 0.13)
|
||||
json (~> 2.0)
|
||||
|
|
@ -852,7 +846,6 @@ DEPENDENCIES
|
|||
addressable (~> 2.7)
|
||||
administrate (~> 0.13)
|
||||
ahoy_email (~> 1.1)
|
||||
algoliasearch-rails (~> 1.24)
|
||||
algorithmia (~> 1.1)
|
||||
amazing_print (~> 1.0)
|
||||
ancestry (~> 3.0)
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ import { h, render } from 'preact';
|
|||
/* global userData */
|
||||
|
||||
// This logic is similar to that in initScrolling.js.erb
|
||||
// that prevents the classic Algolia scrolling for the front page.
|
||||
const frontPageFeedPathNames = new Map([
|
||||
['/', ''],
|
||||
['/top/week', 'week'],
|
||||
|
|
@ -13,9 +12,7 @@ const frontPageFeedPathNames = new Map([
|
|||
['/latest', 'latest'],
|
||||
]);
|
||||
|
||||
const mainNavMoreTrigger = document.getElementById(
|
||||
'main-nav-more-trigger',
|
||||
);
|
||||
const mainNavMoreTrigger = document.getElementById('main-nav-more-trigger');
|
||||
function toggleMainNavMore() {
|
||||
document.getElementById('main-nav-more').classList.remove('hidden');
|
||||
mainNavMoreTrigger.classList.add('hidden');
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
<% end %>
|
||||
|
||||
<div class="home">
|
||||
<div class="item-list-container" id="reading-list" data-algolia-key="<%= @secured_algolia_key %>" data-view="<%= @view %>">
|
||||
<div class="item-list-container" id="reading-list" data-view="<%= @view %>">
|
||||
</div>
|
||||
</div>
|
||||
<%= javascript_packs_with_chunks_tag "readingList", defer: true %>
|
||||
|
|
|
|||
|
|
@ -3,12 +3,10 @@
|
|||
<head>
|
||||
<meta charset="utf-8">
|
||||
<% title = yield(:title) %>
|
||||
<title><%= title || "#{community_qualified_name}" %></title>
|
||||
<title><%= title || community_qualified_name.to_s %></title>
|
||||
<% unless internal_navigation? %>
|
||||
<meta name="last-updated" content="<%= Time.current %>">
|
||||
<meta name="user-signed-in" content="<%= user_signed_in? %>">
|
||||
<meta name="algolia-public-id" content="<%= ApplicationConfig["ALGOLIASEARCH_APPLICATION_ID"] %>">
|
||||
<meta name="algolia-public-key" content="<%= ALGOLIASEARCH_PUBLIC_SEARCH_ONLY_KEY %>">
|
||||
<meta name="environment" content="<%= Rails.env %>">
|
||||
<%= render "layouts/styles" %>
|
||||
<style>
|
||||
|
|
|
|||
|
|
@ -1,23 +0,0 @@
|
|||
AlgoliaSearch.configuration = {
|
||||
application_id: ApplicationConfig["ALGOLIASEARCH_APPLICATION_ID"],
|
||||
api_key: ApplicationConfig["ALGOLIASEARCH_API_KEY"]
|
||||
}
|
||||
|
||||
if Rails.env.test?
|
||||
::ALGOLIASEARCH_PUBLIC_SEARCH_ONLY_KEY = "test_test_test".freeze
|
||||
else
|
||||
# Restrict Access to private indices
|
||||
params = {
|
||||
restrictIndices: [
|
||||
"searchables_#{Rails.env}",
|
||||
"ordered_articles_#{Rails.env}",
|
||||
"ordered_articles_by_published_at_#{Rails.env}",
|
||||
"ordered_articles_by_positive_reactions_count_#{Rails.env}",
|
||||
].join(",")
|
||||
}
|
||||
secured_algolia_key = Algolia.generate_secured_api_key(
|
||||
ApplicationConfig["ALGOLIASEARCH_SEARCH_ONLY_KEY"], params
|
||||
)
|
||||
|
||||
::ALGOLIASEARCH_PUBLIC_SEARCH_ONLY_KEY = secured_algolia_key
|
||||
end
|
||||
|
|
@ -4,10 +4,6 @@ GITHUB_SECRET:
|
|||
TWITTER_KEY:
|
||||
TWITTER_SECRET:
|
||||
|
||||
ALGOLIASEARCH_APPLICATION_ID:
|
||||
ALGOLIASEARCH_SEARCH_ONLY_KEY:
|
||||
ALGOLIASEARCH_API_KEY:
|
||||
|
||||
PUSHER_APP_ID:
|
||||
PUSHER_KEY:
|
||||
PUSHER_SECRET:
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ then
|
|||
echo "|"
|
||||
echo "| Welcome to DEV.TO interactive docker demo setup guide."
|
||||
echo "|"
|
||||
echo "| For this container to work, we will need at minimum ALGOLIA API keys"
|
||||
echo "| For logins to work, we will need either GITHUB or TWITTER API keys"
|
||||
echo "|"
|
||||
echo "| See ( https://docs.dev.to/getting-started/config-env/ ) "
|
||||
|
|
@ -29,30 +28,6 @@ then
|
|||
echo "|"
|
||||
echo "|---"
|
||||
|
||||
echo "|---"
|
||||
echo "| Setting up ALGOLIASEARCH keys (required)"
|
||||
echo "|---"
|
||||
echo -n "| Please indicate your ALGOLIASEARCH_APPLICATION_ID : "
|
||||
read INPUT_KEY
|
||||
if [ ! -z "$INPUT_KEY" ]
|
||||
then
|
||||
export ALGOLIASEARCH_APPLICATION_ID="$INPUT_KEY"
|
||||
fi
|
||||
|
||||
echo -n "| Please indicate your ALGOLIASEARCH_SEARCH_ONLY_KEY : "
|
||||
read INPUT_KEY
|
||||
if [ ! -z "$INPUT_KEY" ]
|
||||
then
|
||||
export ALGOLIASEARCH_SEARCH_ONLY_KEY="$INPUT_KEY"
|
||||
fi
|
||||
|
||||
echo -n "| Please indicate your ALGOLIASEARCH_API_KEY (aka admin key) : "
|
||||
read INPUT_KEY
|
||||
if [ ! -z "$INPUT_KEY" ]
|
||||
then
|
||||
export ALGOLIASEARCH_API_KEY="$INPUT_KEY"
|
||||
fi
|
||||
|
||||
echo "|---"
|
||||
echo "| Setting up GITHUB keys"
|
||||
echo "| (OPTIONAL, leave blank and press enter to skip)"
|
||||
|
|
@ -115,7 +90,7 @@ echo "#"
|
|||
echo "# RUN_MODE can either be the following"
|
||||
echo "#"
|
||||
echo "# - 'DEV' : Start up the container into bash, with a quick start guide"
|
||||
echo "# - 'DEMO' : Start up the container, and run dev.to (requires ALGOLIA environment variables)"
|
||||
echo "# - 'DEMO' : Start up the container, and run dev.to"
|
||||
echo "# - 'RESET-DEV' : Resets postgresql and upload data directory for a clean deployment, before running as DEV mode"
|
||||
echo "# - 'RESET-DEMO' : Resets postgresql and upload data directory for a clean deployment, before running as DEMO mode"
|
||||
echo "# - 'INTERACTIVE-DEMO' : Runs this script in 'interactive' mode to setup the 'DEMO'"
|
||||
|
|
@ -123,9 +98,6 @@ echo "#"
|
|||
echo "# So for example to run a development container in bash it's simply"
|
||||
echo "# './docker-run.sh DEV'"
|
||||
echo "#"
|
||||
echo "# To run a simple demo, with some dummy data (replace <?> with the actual keys)"
|
||||
echo "# './docker-run.sh DEMO -e ALGOLIASEARCH_APPLICATION_ID=<?> -e ALGOLIASEARCH_SEARCH_ONLY_KEY=<?> -e ALGOLIASEARCH_API_KEY=<?>'"
|
||||
echo "#"
|
||||
echo "# Finally to run a working demo, you will need to provide either..."
|
||||
echo "# './docker-run.sh .... -e GITHUB_KEY=<?> -e GITHUB_SECRET=<?>"
|
||||
echo "#"
|
||||
|
|
@ -233,10 +205,6 @@ echo "#---"
|
|||
# ENV variables to support forwarding, and the compulsory list from bash script to docker (if detected)
|
||||
#
|
||||
ENV_FORWARDING_LIST=(
|
||||
# ALGOLIASEARCH (required for deployment)
|
||||
"ALGOLIASEARCH_APPLICATION_ID"
|
||||
"ALGOLIASEARCH_SEARCH_ONLY_KEY"
|
||||
"ALGOLIASEARCH_API_KEY"
|
||||
# login via GITHUB
|
||||
"GITHUB_KEY"
|
||||
"GITHUB_SECRET"
|
||||
|
|
@ -250,12 +218,6 @@ ENV_FORWARDING_LIST=(
|
|||
"PUSHER_CLUSTER"
|
||||
# @TODO : anything else to pass forward? S3<?>
|
||||
)
|
||||
ENV_FORWARDING_DEMO_COMPULSORY_LIST=(
|
||||
# ALGOLIASEARCH (required for deployment)
|
||||
"ALGOLIASEARCH_APPLICATION_ID"
|
||||
"ALGOLIASEARCH_SEARCH_ONLY_KEY"
|
||||
"ALGOLIASEARCH_API_KEY"
|
||||
)
|
||||
|
||||
#
|
||||
# dev.to docker command flags to pass forward
|
||||
|
|
@ -287,25 +249,6 @@ do
|
|||
echo "[skipped env variable] - $i"
|
||||
done
|
||||
|
||||
#
|
||||
# Check for DEMO compulsory list
|
||||
#
|
||||
if [[ "$RUN_MODE" == *"DEMO"* ]]
|
||||
then
|
||||
# Iterate compulsory list
|
||||
for i in "${ENV_FORWARDING_DEMO_COMPULSORY_LIST[@]}"
|
||||
do
|
||||
# Exit if not found
|
||||
if [[ $DEVTO_DOCKER_FLAGS != *"$i"* ]]
|
||||
then
|
||||
echo "#---"
|
||||
echo "# [FATAL ERROR] Missing required DEMO env setting / argument for $i (see example above)"
|
||||
echo "#---"
|
||||
exit 3
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
#
|
||||
# Stop and remove existing containers
|
||||
#
|
||||
|
|
|
|||
|
|
@ -14,22 +14,5 @@ docker run -d --name dev-to-postgres \
|
|||
# Wait about 30 seconds, to give the postgres container time to start
|
||||
sleep 30
|
||||
|
||||
#
|
||||
# Run the prebuilt dev.to container
|
||||
# binded to localhost:3000
|
||||
#
|
||||
# Algoliasearch key is a hard requirements,
|
||||
# for login do consider adding github/twitter keys
|
||||
# see : https://github.com/thepracticaldev/dev.to/blob/master/config/sample_application.yml
|
||||
#
|
||||
docker run -d -p 3000:3000 \
|
||||
--name dev-to-app \
|
||||
--link dev-to-postgres:db \
|
||||
-v "<DEVTO_UPLOAD_DIR>:/usr/src/app/public/uploads/" \
|
||||
-e ALGOLIASEARCH_APPLICATION_ID=<APP_ID> \
|
||||
-e ALGOLIASEARCH_SEARCH_ONLY_KEY=<SEARH_KEY> \
|
||||
-e ALGOLIASEARCH_API_KEY=<ADMIN_KEY> \
|
||||
uilicious/dev.to
|
||||
```
|
||||
|
||||
> PS : Someone from official dev.to team should create their own container namespace and update this segment after merger (if any)
|
||||
```
|
||||
|
|
|
|||
|
|
@ -1,67 +0,0 @@
|
|||
---
|
||||
title: Algolia
|
||||
---
|
||||
|
||||
## Algolia for Search
|
||||
|
||||
Algolia is a third party service that powers the search. When working with the
|
||||
API, you will likely need to utilize Algolia. You will need to sign up for a
|
||||
free-tier account, retrieve the keys, and provide those keys to the Rails
|
||||
application.
|
||||
|
||||
## Sign up
|
||||
|
||||
1. Go to the Algolia sign up [page](https://www.algolia.com/users/sign_up).
|
||||
|
||||
2. Choose one of the three methods of signing up: email, GitHub, or Google.
|
||||
|
||||
3. Fill in your information.
|
||||
|
||||

|
||||
|
||||
4. Select the datacenter's region.
|
||||
|
||||

|
||||
|
||||
5. Fill in or skip the project information.
|
||||
|
||||

|
||||
|
||||
6. Sign up complete! You can go to your dashboard now.
|
||||
|
||||

|
||||
|
||||
7. To avoid the trial period ending unexpectedly, you'll want to select a free
|
||||
plan. Go to the [Billing](https://www.algolia.com/billing) section.
|
||||
|
||||

|
||||
|
||||
8. Choose the _Community_ plan and submit.
|
||||
|
||||

|
||||
|
||||
9) You're all good! You can get your API keys now.
|
||||
|
||||

|
||||
|
||||
## Get API keys
|
||||
|
||||
1. [Sign up](#algolia-sign-up) or
|
||||
[Sign in](https://www.algolia.com/users/sign_in) to your Algolia account.
|
||||
|
||||
2. From your **Dashboard**, click on **API Keys**.
|
||||
|
||||

|
||||
|
||||
3. Change your keys accordingly (name of Algolia key -> name of our `ENV`
|
||||
variable):
|
||||
|
||||
```text
|
||||
Application ID -> ALGOLIASEARCH_APPLICATION_ID
|
||||
Search-Only API Key -> ALGOLIASEARCH_SEARCH_ONLY_KEY
|
||||
Admin API KEY -> ALGOLIASEARCH_API_KEY
|
||||
```
|
||||
|
||||

|
||||
|
||||
4. Done.
|
||||
92
docs/backend/elasticsearch.md
Normal file
92
docs/backend/elasticsearch.md
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
---
|
||||
title: Elasticsearch
|
||||
---
|
||||
|
||||
# What is [Elasticsearch](https://www.elastic.co/what-is/elasticsearch)?
|
||||
|
||||
> Elasticsearch is a distributed, open-source search and analytics engine for
|
||||
> all types of data, including textual, numerical, geospatial, structured, and
|
||||
> unstructured. Elasticsearch is built on Apache Lucene and was first released
|
||||
> in 2010 by Elastic.
|
||||
|
||||
# How DEV uses Elasticsearch
|
||||
|
||||
### Searchable Models
|
||||
|
||||
At DEV we use Elasticsearch for all of our user-facing searching needs. Models
|
||||
that are searched using Elasticsearch are:
|
||||
|
||||
- Tags
|
||||
- Classified Listings
|
||||
- Chat Channels
|
||||
- Users
|
||||
- Podcast Episodes
|
||||
- Comments
|
||||
- Articles
|
||||
|
||||
### Index Setup
|
||||
|
||||
The above models are organized in Elasticsearch in different
|
||||
[indexes](https://www.elastic.co/blog/what-is-an-elasticsearch-index) to make
|
||||
searching more accurate and performant. The index breakdown is:
|
||||
|
||||
- Tags index -> Tags
|
||||
- Classified Listings index -> Classified Listings
|
||||
- Chat Channel Membership index -> Chat Channels
|
||||
- User's index -> Users
|
||||
- Feed Content index -> Podcast Episodes, Comments, and Articles
|
||||
|
||||
You will notice that Podcast Episodes, Comments, and Articles all share the same
|
||||
index. This allows us to search and aggregate across all of these documents at
|
||||
the same time. These documents also share a lot of similar fields so putting
|
||||
them in the same index made sense. In the future, depending on our search needs
|
||||
this index structure might change.
|
||||
|
||||
Each index that is listed above has a corresponding
|
||||
[mapping](https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping.html)
|
||||
that defines what fields can and cannot be indexed to it. These mappings are
|
||||
similar to a db schema. In our case, all of our index mappings are defined as
|
||||
[`strict`](https://www.elastic.co/guide/en/elasticsearch/reference/current/dynamic.html#dynamic)
|
||||
which means if we try to index a field that is not defined it will throw an
|
||||
error. Mappings for each index can be found in
|
||||
`app/config/elasticsearch/mappings`.
|
||||
|
||||
### Indexing documents into Elasticsearch
|
||||
|
||||
In order to index the data from Postgres into Elasticsearch, we rely on
|
||||
callbacks in our ActiveRecord models. Whenever a model is created or updated we
|
||||
use an `after_commit` callback to enqueue a `Search::IndexToElasticsearchWorker`
|
||||
which handles indexing the document into Elasticsearch. In order to translate
|
||||
our ActiveRecord data to Elasticsearch we use serializers. Each model has its
|
||||
own serializer which can be found in `app/serializers/search`
|
||||
|
||||
### Searching Elasticsearch
|
||||
|
||||
Once the documents are in Elasticsearch then we can search for them. This is
|
||||
handled by code in our `app/services/search` directory. Here you will see a
|
||||
collection of classes used to help us index and search documents in
|
||||
Elasticsearch. The nested `query_builders` directory contains all the logic we
|
||||
need to help us build complex search queries to send to Elasticsearch.
|
||||
|
||||
# Working With Elasticsearch
|
||||
|
||||
## How to add a new field to Elasticsearch
|
||||
|
||||
When adding a new field to Elasticsearch here are the steps you have to follow:
|
||||
|
||||
1. Add field to mapping by editing the appropriate JSON file in
|
||||
`app/config/elasticsearch/mappings`. If you plan to test locally you will
|
||||
need to run `bin/setup` to update your local Elasticsearch mappings.
|
||||
2. Add field to serializer for model located in `app/serializers/search`.
|
||||
3. If the new field needs to be backfilled write a DataUpdateScript to reindex
|
||||
all affected models so the field is available and populated in Elasticsearch
|
||||
4. DEPLOY - Before you can start using a new field you need to ensure that it is
|
||||
added to Elasticsearch and populated properly. The worker that runs the
|
||||
DataUpdateScript will run 5 min after a deploy completes. This means you have
|
||||
to deploy the code for adding the field separate from the code that will use
|
||||
it.
|
||||
5. Add code to search for your new field. You likely will need to update the
|
||||
allowed params in the searches controller as well as the pertinent query
|
||||
builder.
|
||||
6. DEPLOY new search code
|
||||
7. DONE!
|
||||
|
|
@ -7,9 +7,9 @@ items:
|
|||
- authorization.md
|
||||
- configuration.md
|
||||
- data-update-scripts.md
|
||||
- elasticsearch.md
|
||||
- fastly.md
|
||||
- roles.md
|
||||
- algolia.md
|
||||
- pusher.md
|
||||
- admin.md
|
||||
- previewing-emails.md
|
||||
|
|
|
|||
|
|
@ -19,7 +19,6 @@ globals: {
|
|||
InstantClick: false,
|
||||
filterXSS: false,
|
||||
Pusher: false,
|
||||
algoliasearch: false,
|
||||
}
|
||||
```
|
||||
|
||||
|
|
|
|||
|
|
@ -5,8 +5,7 @@ title: Configuring Environment Variables
|
|||
# Configuring environment variables and secret keys
|
||||
|
||||
Take a look at `Envfile`. This file lists all the `ENV` variables we use and
|
||||
provides a fake default for any missing keys. You'll need to get your own free
|
||||
[Algolia credentials][algolia] to get your development environment running.
|
||||
provides a fake default for any missing keys.
|
||||
|
||||
The [backend guide][backend_guide] will show you how to get free API keys for
|
||||
additional services that may be required to run certain parts of the app.
|
||||
|
|
@ -30,11 +29,11 @@ GITHUB_SECRET: "ANOTHER_REAL_SECURE_KEY_HERE"
|
|||
(Don't worry, your `application.yml` file is ignored by git)
|
||||
|
||||
If you are missing `ENV` variables on bootup, the [envied][envied] gem will
|
||||
alert you with messages similar to `'error_on_missing_variables!': The following environment variables should be set: A_MISSING_KEY.`.
|
||||
alert you with messages similar to
|
||||
`'error_on_missing_variables!': The following environment variables should be set: A_MISSING_KEY.`.
|
||||
|
||||
Only certain features require "real" keys, so you may be able to add them as you
|
||||
work on different areas of the application.
|
||||
|
||||
[algolia]: /backend/algolia
|
||||
[backend_guide]: /backend
|
||||
[envied]: https://rubygems.org/gems/envied
|
||||
|
|
|
|||
|
|
@ -31,9 +31,7 @@ well.
|
|||
1. Set up your environment variables/secrets
|
||||
|
||||
- Take a look at `Envfile`. This file lists all the `ENV` variables we use
|
||||
and provides a fake default for any missing keys. You'll need to get your
|
||||
own free [Algolia credentials](/backend/algolia) to get your development
|
||||
environment running.
|
||||
and provides a fake default for any missing keys.
|
||||
- The [backend guide](/backend) will show you how to get free API keys for
|
||||
additional services that may be required to run certain parts of the app.
|
||||
- For any key that you wish to enter/replace:
|
||||
|
|
|
|||
|
|
@ -89,9 +89,7 @@ NOTE: Make sure to download **the OSS version**, `elasticsearch-oss`.
|
|||
1. Set up your environment variables/secrets
|
||||
|
||||
- Take a look at `Envfile`. This file lists all the `ENV` variables we use
|
||||
and provides a fake default for any missing keys. You'll need to get your
|
||||
own free [Algolia credentials](/backend/algolia) to get your development
|
||||
environment running.
|
||||
and provides a fake default for any missing keys.
|
||||
- The [backend guide](/backend) will show you how to get free API keys for
|
||||
additional services that may be required to run certain parts of the app.
|
||||
- For any key that you wish to enter/replace:
|
||||
|
|
|
|||
|
|
@ -207,10 +207,7 @@ your local Elasticsearch installation, for example:
|
|||
default provided for any missing keys.
|
||||
- The [backend guide](/backend) will show you how to get free API keys for
|
||||
additional services that may be required to run certain parts of the app.
|
||||
- For any key that you wish to enter/replace, follow the steps below. At a
|
||||
minimum, you'll need to get your own free
|
||||
[Algolia credentials](/backend/algolia) to get your development environment
|
||||
running.
|
||||
- For any key that you wish to enter/replace, follow the steps below.
|
||||
|
||||
1. Create `config/application.yml` by copying from the provided template
|
||||
(i.e. with bash:
|
||||
|
|
|
|||
|
|
@ -162,9 +162,7 @@ NOTE: Make sure to download **the OSS version**, `elasticsearch-oss`.
|
|||
1. Set up your environment variables/secrets
|
||||
|
||||
- Take a look at `Envfile`. This file lists all the `ENV` variables we use
|
||||
and provides a fake default for any missing keys. You'll need to get your
|
||||
own free [Algolia credentials](/backend/algolia) to get your development
|
||||
environment running.
|
||||
and provides a fake default for any missing keys.
|
||||
- The [backend guide](/backend) will show you how to get free API keys for
|
||||
additional services that may be required to run certain parts of the app.
|
||||
- For any key that you wish to enter/replace:
|
||||
|
|
|
|||
|
|
@ -16,9 +16,9 @@ The view responsible for managing user reports can be found at
|
|||
action of the [`internal/feedback_messages_controller`][feedback_messages].
|
||||
|
||||
For DEV, Ransack is being used exclusively in internal, for search problems in
|
||||
other parts of the app we use [Algolia][algolia].
|
||||
other parts of the app we use [Elasticsearch][elasticsearch].
|
||||
|
||||
[feedback_messages]:
|
||||
https://github.com/thepracticaldev/dev.to/blob/4e41e4a2ac893fa2a6c36990cfe475858ffb086a/app/controllers/internal/feedback_messages_controller.rb#L4
|
||||
[ransack]: https://github.com/activerecord-hackery/ransack
|
||||
[algolia]: /backend/algolia
|
||||
[elasticsearch]: /backend/elasticsearch
|
||||
|
|
|
|||
|
|
@ -68,9 +68,9 @@ Rails][fastly_rails] docs, but we bust specific URLs via `CacheBuster`.
|
|||
|
||||
The home feed is based on a combination of recent collective posts that are
|
||||
cached and delivered the same to everyone in the HTML, and additional articles
|
||||
fetched from an Algolia index after page load. To determine which posts a user
|
||||
sees, they are ranked based on the user's followed tags, followed users, and
|
||||
relative weights for each tag. Additional fetched articles also follow this
|
||||
fetched from an Elasticsearch index after page load. To determine which posts a
|
||||
user sees, they are ranked based on the user's followed tags, followed users,
|
||||
and relative weights for each tag. Additional fetched articles also follow this
|
||||
general pattern.
|
||||
|
||||
Currently, the top post on the home feed, which must have a cover image, is
|
||||
|
|
|
|||
|
|
@ -17,8 +17,7 @@ For the Dev.to tech stack we use:
|
|||
- [_Sidekiq_](https://github.com/mperham/sidekiq) and
|
||||
[_Active Job_](https://guides.rubyonrails.org/active_job_basics.html) for
|
||||
background workers
|
||||
- [_Algolia_](https://www.algolia.com/) for search (Algolia will be phased out
|
||||
in favor of [_Elasticsearch_](https://www.elastic.co/))
|
||||
- [_Elasticsearch_](https://www.elastic.co/elasticsearch/) for in app searching
|
||||
- [Ransack](https://github.com/activerecord-hackery/ransack) for internal search
|
||||
- [_Redcarpet_](https://github.com/vmg/redcarpet) and
|
||||
[_Rouge_](https://github.com/jneen/rouge) to parse Markdown
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ RSpec.describe PodcastEpisode, type: :model do
|
|||
describe "validations" do
|
||||
# Couldn't use shoulda matchers for these tests because:
|
||||
# Shoulda uses `save(validate: false)` which skips validations, but runs callbacks
|
||||
# So an invalid record is saved and the algolia callback fails to run because there's no associated podcast
|
||||
# So an invalid record is saved and the elasticsearch callback fails because there's no associated podcast
|
||||
# https://git.io/fjg2g
|
||||
|
||||
it "validates guid uniqueness" do
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ abort("The Rails environment is running in production mode!") if Rails.env.produ
|
|||
|
||||
# Add additional requires below this line. Rails is not loaded until this point!
|
||||
|
||||
require "algolia/webmock"
|
||||
require "pundit/matchers"
|
||||
require "pundit/rspec"
|
||||
require "webmock/rspec"
|
||||
|
|
|
|||
|
|
@ -1,86 +0,0 @@
|
|||
require "webmock/rspec"
|
||||
require "rspec/rails"
|
||||
|
||||
RSpec.configure do |config|
|
||||
config.before do
|
||||
# list indexes
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/indexes/).
|
||||
to_return(body: '{ "items": [] }')
|
||||
# query index
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+/).
|
||||
to_return(body: '{ "hits": [ { "objectID": 42 } ], "page": 1, "hitsPerPage": 1 }')
|
||||
# delete index
|
||||
WebMock.
|
||||
stub_request(:delete, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# clear index
|
||||
WebMock.
|
||||
stub_request(:post, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/clear/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# add object
|
||||
WebMock.
|
||||
stub_request(:post, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# save object
|
||||
WebMock.
|
||||
stub_request(:put, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/[^\/]+/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# partial update
|
||||
WebMock.
|
||||
stub_request(:put, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/[^\/]+\/partial/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# get object
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/[^\/]+/).
|
||||
to_return(body: "{}")
|
||||
# delete object
|
||||
WebMock.
|
||||
stub_request(:delete, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/[^\/]+/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# batch
|
||||
WebMock.
|
||||
stub_request(:post, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/batch/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# settings
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/settings/).
|
||||
to_return(body: "{}")
|
||||
WebMock.
|
||||
stub_request(:put, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/settings/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# browse
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/browse/).
|
||||
to_return(body: "{}")
|
||||
# operations
|
||||
WebMock.
|
||||
stub_request(:post, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/operation/).
|
||||
to_return(body: '{ "taskID": 42 }')
|
||||
# tasks
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/task\/[^\/]+/).
|
||||
to_return(body: '{ "status": "published" }')
|
||||
# index keys
|
||||
WebMock.
|
||||
stub_request(:post, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/keys/).
|
||||
to_return(body: "{ }")
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/keys/).
|
||||
to_return(body: '{ "keys": [] }')
|
||||
# global keys
|
||||
WebMock.
|
||||
stub_request(:post, /.*\.algolia(net\.com|\.net)\/1\/keys/).to_return(body: "{ }")
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/keys/).to_return(body: '{ "keys": [] }')
|
||||
WebMock.
|
||||
stub_request(:get, /.*\.algolia(net\.com|\.net)\/1\/keys\/[^\/]+/).to_return(body: "{ }")
|
||||
WebMock.
|
||||
stub_request(:delete, /.*\.algolia(net\.com|\.net)\/1\/keys\/[^\/]+/).to_return(body: "{ }")
|
||||
# query POST
|
||||
WebMock.
|
||||
stub_request(:post, /.*\.algolia(net\.com|\.net)\/1\/indexes\/[^\/]+\/query/).
|
||||
to_return(body: '{ "hits": [ { "objectID": 42 } ], "page": 1, "hitsPerPage": 1 }')
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue