Created
July 30, 2013 15:51
-
-
Save outsmartin/6114186 to your computer and use it in GitHub Desktop.
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
class JobSearch | |
class << self | |
def create_index | |
Tire.index self.to_s.downcase do | |
delete | |
create mappings: { | |
job: { | |
properties: { | |
id: { type: 'string', index: 'not_analyzed', include_in_all: false}, | |
title: { type: 'string',analyzer: 'stemming', boost: 3.0}, # TODO Titel with synonyms | |
description: { | |
type: 'multi_field', | |
fields: { | |
with_synonyms: {type:'string',analyzer: 'syn', boost: 0.5}, | |
without_synonyms: {type:'string',analyzer: 'stemming', boost: 1.0}, | |
} | |
}, | |
tags: { type: 'string', boost: 2.0}, | |
location: {type: 'geo_point'}, | |
} | |
} | |
},settings:{ | |
number_of_shards: 1, | |
number_of_replicas: 0, | |
similarity: { | |
default: { | |
type: "org.elasticsearch.index.similarity.CustomSimilarityProvider" | |
} | |
}, | |
analysis: { | |
analyzer: { | |
stemming: { | |
type: 'snowball', | |
language: 'German', | |
filter: %w[standard lowercase] | |
}, | |
syn: { | |
tokenizer: "whitespace", | |
filter: %w[standard lowercase synonym] | |
} | |
}, | |
filter: { | |
german_stemmer: { | |
type: 'stemmer', | |
name: 'german2' | |
}, | |
synonym: { | |
type: "synonym", | |
expand: 0, # =1 -> Ueberall wo Einkauf oder Logistik steht, steht dann "Einkauf Logistik" | |
synonyms: [ | |
"einkauf, logistik", # alle Werte werden wie der erste behandelt | |
] | |
} | |
} | |
} | |
} | |
refresh | |
end | |
end | |
def add jobs | |
Tire.index self.to_s.downcase do | |
jobs = jobs.map do |job| | |
job.merge({type: 'job'}) | |
end | |
import jobs | |
refresh | |
end | |
end | |
def search params | |
Tire.search self.to_s.downcase do | |
query do | |
dis_max do | |
query { string params, fields: ['title', 'description.with_synonyms', 'tags'], use_dis_max: false, default_operator: "AND" } | |
query { string params, fields: ['title', 'description.without_synonyms', 'tags'], use_dis_max: false, default_operator: "AND"} | |
end | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment