⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 03 - indexing unstructured text with simplesearch.rb

📁 O Reilly Ruby Cookbook source code
💻 RB
字号:
require 'rubygems'require 'search/simple'contents = Search::Simple::Contents.newcontents << Search::Simple::Content.              new('In the beginning God created the heavens...',                  'Genesis.txt', Time.now)contents << Search::Simple::Content.new('Call me Ishmael...',	                                'MobyDick.txt', Time.now)contents << Search::Simple::Content.new('Marley was dead to begin with...',	                                'AChristmasCarol.txt', Time.now)searcher = Search::Simple::Searcher.load(contents, 'index_file')#---require 'rubygems'require 'search/simple'searcher = nilopen('index_file') do |f|  searcher = Search::Simple::Searcher.new(Marshal.load(f), Marshal.load(f),	                                  'index_file')endsearcher.find_words(['begin']).results.collect { |result| result.name }# => ["AChristmasCarol.txt", "Genesis.txt"]#---class Search::Simple::Searcher  def add_contents(contents)     Search::Simple::Searcher.create_indices(contents, @dict,                                              @document_vectors)     dump                             # Re-serializes the file  endendcontents = Search::Simple::Contents.newcontents << Search::Simple::Content.new('A spectre is haunting Europe...',	     	                        'TheCommunistManifesto.txt', Time.now)searcher.add_contents(contents)searcher.find_words(['spectre']).results[0].name# => "TheCommunistManifesto.txt"#---

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -