Skip to content

Instantly share code, notes, and snippets.

View spaghetticode's full-sized avatar
🪲
bugs, bugs everywhere

Andrea Longhi spaghetticode

🪲
bugs, bugs everywhere
View GitHub Profile
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem "rails", github: "rails/rails", branch: "6-0-stable"
gem "sqlite3"
end
@spaghetticode
spaghetticode / checkout_insufficient_stock_spec.rb
Created January 4, 2019 08:58
Specs to expose stock validation issues on Solidus checkout confirm page
require 'spec_helper'
describe "Checkout confirm page", type: :feature do
include_context 'checkout setup'
context 'when there is not enough stock at the default stock location' do
context "when the product is not backorderable" do
let(:user) { create(:user) }
let(:order) { Spree::TestingSupport::OrderWalkthrough.up_to(:payment) }
# unicorn_rails -c /data/github/current/config/unicorn.rb -E production -D
rails_env = ENV['RAILS_ENV'] || 'production'
# 16 workers and 1 master
worker_processes (rails_env == 'production' ? 16 : 4)
# Load rails+github.git into the master before forking workers
# for super-fast worker spawn times
preload_app true
@spaghetticode
spaghetticode / ElasticSearch_mappings_and_analyzers.json
Last active October 18, 2018 08:38
Beginning Elasticsearch - mappings and analyzers
# Record insertion:
PUT /examples/movies/1
{
"title": "Saving Private Ryan",
"description": "A war movie set during the invasion of Normandy"
}
# see current mappings:
GET /examples/_mapping
@spaghetticode
spaghetticode / 06.updates.md
Last active October 18, 2018 08:38
06.updates

This second paragraph in total looks very nice. It even shows how to use the "suggest" feature standalone. However, whether or not it may be embedded and executed in the actual search, we do not know. (Note: we're still in operation "2d) search")

You can combine the suggester with a query. You can use the same term or even use different words for suggestion and query. Let's see an example:

GET /docs/doc/_search
{
  "query": {
    "match": {"title": "liitle neemo"}
  },
@spaghetticode
spaghetticode / 05.outputs.md
Last active October 18, 2018 08:39
Outputs

outputs (results+metadata):

-weight-sorted list of matches:

{(ID, weight/relevance, distance)}

By id:

GET /docs/doc/_search 
{
 "query": {
@spaghetticode
spaghetticode / 04.fuzzy.md
Last active October 18, 2018 08:39
Queries continued - fuzzy search

Fuzzy query

Basic fuzzy queries:

GET /docs/doc/_search
{
  "query": {
    "fuzzy": {
      "body": "robot"
@spaghetticode
spaghetticode / 03.queries.md
Last active October 18, 2018 08:40
More queries

-OR (better), if feasible:

whole phrases instead of words for context-awareness

Let's see some possible solutions. This one will look for the three words in the body, but requires that only 2 of them are present:

GET /docs/doc/_search
{
  "query": {
    "match": {
@spaghetticode
spaghetticode / 02.queries.md
Last active October 18, 2018 08:40
Query Interface

Search

I'm going to discuss the following part of your request:

d) search: search entries
        inputs:
          -entry set identifier
          -three word lists:
 -words that should match
@spaghetticode
spaghetticode / 01.introduction.md
Last active October 18, 2018 08:40
Elasticsearch Introduction

Introduction

Installation on the development machine

We're going to use our development machine in order to build the knowledge on elasticsearch and its usage. If you're on OSX like us, you can install elasticsearch with a simple brew install elasticsearch. Follow the instruction to start the server and to autostart the service at boot. If you are on a different platform you can go to http://www.elasticsearch.org/download/ and choose your preferred installation way.

Now we need to install the elasticsearch development console. Change directory to the elasticsearch installation (you can find it with which elasticsearch... in my case it's /usr/local) and install the marvel plugin: bin/plugin -i elasticsearch/marvel/latest