-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathquickstart.rb
More file actions
executable file
·75 lines (61 loc) · 2.25 KB
/
Copy pathquickstart.rb
File metadata and controls
executable file
·75 lines (61 loc) · 2.25 KB
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#!/usr/bin/env ruby
# frozen_string_literal: true
require_relative "setup"
def demo_basic_search
puts "\n--- Basic Search: 'shoes' ---"
results = MockItem.search(:description).match_all("shoes").limit(5)
puts(results.map { |item| " - #{item.description.truncate(60)}" })
end
def demo_scored_search
puts "\n--- Scored Search: 'running' ---"
results = MockItem.search(:description)
.match_all("running")
.with_score
.order(search_score: :desc)
.limit(5)
puts(results.map { |item| " - #{item.description.truncate(50)} (score: #{item.search_score.round(2)})" })
end
def demo_phrase_search
puts "\n--- Phrase Search: 'running shoes' ---"
results = MockItem.search(:description)
.phrase("running shoes")
.with_score
.order(search_score: :desc)
.limit(5)
puts(results.map { |item| " - #{item.description.truncate(50)} (score: #{item.search_score.round(2)})" })
end
def demo_snippet_highlighting
puts "\n--- Snippet Highlighting: 'shoes' ---"
results = MockItem.search(:description)
.match_all("shoes")
.with_score
.with_snippet(:description, start_tag: "<b>", end_tag: "</b>")
.order(search_score: :desc)
.limit(3)
puts(results.map { |item| " - #{item.description_snippet}" })
end
def demo_filtered_search
puts "\n--- Filtered Search: 'shoes' + in_stock + rating >= 4 ---"
results = MockItem.search(:description)
.match_all("shoes")
.where(in_stock: true)
.where(MockItem.arel_table[:rating].gteq(4))
.with_score
.order(search_score: :desc)
.limit(5)
puts(results.map { |item| " - #{item.description.truncate(40)} (rating: #{item.rating})" })
end
if $PROGRAM_NAME == __FILE__
puts "=" * 60
puts "rails-paradedb Quickstart Example"
puts "=" * 60
count = QuickstartSetup.setup_mock_items!
puts "Loaded #{count} mock items"
demo_basic_search
demo_scored_search
demo_phrase_search
demo_snippet_highlighting
demo_filtered_search
puts "\n" + "=" * 60
puts "Done!"
end