Skip to content

Instantly share code, notes, and snippets.

require 'rubygems'
require 'mechanize'
FILE = 'crawler.log'
a = Mechanize.new { |agent|
agent.user_agent_alias = 'Mac Safari'
}
a.get('http://www.com/') do |page|
@dedico
dedico / stretcher_search.rb
Created February 8, 2013 11:20
Stretcher - readme example
require 'stretcher'
# First Create a server
server = Stretcher::Server.new('http://localhost:9200')
# Delete an index (in case you already have this one)
server.index(:foo).delete rescue nil
# Create an index
server.index(:foo).create(mappings: {tweet: {properties: {text: 'string'}}})
# and here I get following exception:
@dedico
dedico / nested_example.bash
Last active December 12, 2015 04:19
Elasticsearch example - index setup using nested feature and sample queries
# setup
# delete index
curl -XDELETE 'http://localhost:9200/hotels/'
# create index
curl -XPOST 'http://localhost:9200/hotels/'
# create mapping
curl -XPOST localhost:9200/hotels/nested_hotel/_mapping -d '{
"nested_hotel":{
"properties":{
"rooms": {
@dedico
dedico / index_and_queries.bash
Last active April 28, 2020 08:21
Elasticsearch example - index setup and sample queries
# setup
# delete index
curl -XDELETE 'http://localhost:9200/hotels/'
# create index
curl -XPOST 'http://localhost:9200/hotels/'
# create mapping
curl -XPOST localhost:9200/hotels/regular_hotel/_mapping -d '{
"regular_hotel":{
"properties":{
"rooms": {
@dedico
dedico / search_controller_v2.rb
Created July 8, 2012 13:29
Search action with facet filter applied on 'capacity' facet when 'power' is selected
def search
paginate_per = 30
group_id = params[:part_group]
make_id = params[:make]
model_id = params[:model]
vehicle_category_id = params[:category]
vehicle_power = params[:power]
capacity = params[:capacity]
q = params[:q]
@dedico
dedico / search_controller_v1.rb
Created July 8, 2012 13:25
Search action without filters on facets
def search
paginate_per = 30
group_id = params[:part_group]
make_id = params[:make]
model_id = params[:model]
vehicle_category_id = params[:category]
vehicle_power = params[:power]
capacity = params[:capacity]
q = params[:q]
@dedico
dedico / es_sample_2.json
Created July 8, 2012 12:49
incorrect elasticsearch query
{
"query":{
"bool":{
"must":[
{
"match_all":{ }
},
{
"term":{
"vehicles.vehicle_category_id":{
@dedico
dedico / es_sample_1.json
Created July 8, 2012 12:29
correct elasticsearch query
{
"query":{
"bool":{
"must":[
{
"match_all":{ }
},
{
"term":{
"vehicles.vehicle_category_id":{
@dedico
dedico / sample_product.json
Created June 25, 2012 14:04
Sample product
{
"_index" : "megastore",
"_type" : "products",
"_id" : "1",
"_version" : 1,
"exists" : true, "_source" : {
"id": 1,
"sKU": "SKU",
"name": "monitory microsoft",
"description": "producent microsoft kategoria monitory",
@dedico
dedico / product_mapping.json
Created June 25, 2012 13:55
Product mapping
{
"products" : {
"properties" : {
"categoryId" : {
"type" : "integer"
},
"description" : {
"type" : "string"
},
"id" : {