Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Newer
Older
100644 37 lines (28 sloc) 1.27 kb
66915a0 @igrigorik TFIDF vs PageRank demo for a trivial 3-page web
authored
1 # Ilya Grigorik
2 #
3 # TFIDF vs PageRank demo for a trivial 3-page web:
4 # page 1 -> page 2, page 3 (PageRank: 0.05)
5 # page 2 -> page 3 (PageRank: 0.07)
6 # page 3 -> page 3, page 3 (PageRank: 0.87)
7 #
8
9 require 'ferret'
10 include Ferret
11
12 index = Index::Index.new()
13
14 index << {:title => "Page 1", :content => open("web/page-1.html").read, :pagerank => 0.05 }
15 index << {:title => "Page 2", :content => open("web/page-2.html").read, :pagerank => 0.07 }
16 index << {:title => "Page 3", :content => open("web/page-3.html").read, :pagerank => 0.87 }
17
18 index.search_each('content:"world"') do |id, score|
19 puts "Score: #{score}, #{index[id][:title]} (PageRank: #{index[id][:pagerank]})"
20 end
21
22 puts "*" * 50
23
24 sf_pagerank = Search::SortField.new(:pagerank, :type => :float, :reverse => true)
25
26 index.search_each('content:"world"', :sort => sf_pagerank) do |id, score|
27 puts "Score: #{score}, #{index[id][:title]}, #{index[id][:pagerank]}"
28 end
29
30 # Score: 0.267119228839874, Page 3 (PageRank: 0.87)
31 # Score: 0.17807948589325, Page 1 (PageRank: 0.05)
32 # Score: 0.17807948589325, Page 2 (PageRank: 0.07)
33 # **************************************************
34 # Score: 0.267119228839874, Page 3, 0.87
35 # Score: 0.17807948589325, Page 2, 0.07
36 # Score: 0.17807948589325, Page 1, 0.05
Something went wrong with that request. Please try again.