~ubuntu-branches/ubuntu/saucy/dhelp/saucy-proposed

« back to all changes in this revision

Viewing changes to tmp/xapian/simpleindex.rb

  • Committer: Bazaar Package Importer
  • Author(s): Colin Watson
  • Date: 2008-06-19 01:25:07 UTC
  • Revision ID: james.westby@ubuntu.com-20080619012507-adt75omul1shucde
Tags: 0.6.9ubuntu1
* Resynchronise with Debian. Remaining changes:
  - Recommends: firefox-3.0.
  - Exit zero if the bdb module is not available; this usually indicates
    that dhelp is not configured yet.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env ruby
2
 
 
3
 
require 'xapian'
4
 
 
5
 
if ARGV.size != 1
6
 
  $stderr.puts "Usage: #{$0} PATH_TO_DATABASE"
7
 
  exit 99
8
 
end
9
 
 
10
 
# Open the database for update, creating a new database if necessary.
11
 
database = Xapian::WritableDatabase.new(ARGV[0], Xapian::DB_CREATE_OR_OPEN)
12
 
 
13
 
indexer = Xapian::TermGenerator.new()
14
 
stemmer = Xapian::Stem.new("english")
15
 
indexer.stemmer = stemmer
16
 
 
17
 
para = ''
18
 
while line = $stdin.gets()
19
 
  line.strip!()
20
 
  if line.empty?
21
 
    if not para.empty?
22
 
      # We've reached the end of a paragraph, so index it.
23
 
      doc = Xapian::Document.new()
24
 
      doc.data = para
25
 
 
26
 
      indexer.document = doc
27
 
      indexer.index_text(para)
28
 
 
29
 
      # Add the document to the database
30
 
      database.add_document(doc)
31
 
      para = ''
32
 
    end # if not para.empty?
33
 
  else # line not empty
34
 
    para += ' ' if para != ''
35
 
    para += line
36
 
  end # if line empty
37
 
end
38