/
application.rb
50 lines (42 loc) · 1.69 KB
/
application.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# encoding: utf-8
#
# This is your application.
#
# Have fun with Picky!
#
class PickySearch < Application # The App Constant needs to be identical in application.ru.
# This is an example with books that you can adapt.
#
# Note: Much more is possible, but let's start out easy.
#
# Ask me if you have questions!
#
indexes do
illegal_characters(/[^äöüa-zA-Z0-9\s\/\-\"\&\.]/)
stopwords(/\b(und|der|die|das|mit|im|ein|des|dem|the|of)\b/)
split_text_on(/[\s\/\-\"\&\.]/)
type :books,
Sources::DB.new(
'SELECT id, title, author, isbn13 as isbn FROM books',
DB.configure(:file => 'app/db.yml')
),
field(:title, :qualifiers => [:t, :title, :titre], :similarity => Similarity::DoubleLevenshtone.new(3)), # Up to three similar title word indexed.
field(:author, :qualifiers => [:s, :author, :auteur]),
field(:isbn, :qualifiers => [:i, :isbn], :partial => Partial::None.new) # Partially searching on an ISBN makes not much sense.
end
queries do
maximum_tokens 5
# Note that Picky needs the following characters to
# pass through, as they are control characters: *"~:
#
illegal_characters(/[^a-zA-Z0-9\s\/\-\,\&äöü\"\~\*\:]/)
stopwords(/\b(und|der|die|das|mit|ein|des|dem|the|of)\b/)
split_text_on(/[\s\/\-\,\&]+/)
# Set some weights according to the position. Note that the order is important.
#
options = { :weights => Query::Weights.new([:title] => 6, [:author, :title] => 3) }
route %r{^/books/full}, Query::Full.new(Indexes[:books], options)
route %r{^/books/live}, Query::Live.new(Indexes[:books], options)
root 200
end
end