This file is indexed.

/usr/share/doc/libxapian-ruby1.9.1/examples/simpleexpand.rb is in libxapian-ruby1.9.1 1.2.8-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

 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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env ruby
#
# Simple example script demonstrating query expansion.
#
# Originally by Paul Legato (plegato@nks.net), 4/22/06.
#
# Copyright (C) 2006 Networked Knowledge Systems, Inc.
# Copyright (C) 2006,2007 Olly Betts
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301
# USA

require 'xapian'

if ARGV.size < 2
  $stderr.puts "Usage: #{$0} PATH_TO_DATABASE QUERY [-- [DOCID...]]"
  exit 99
end

# Open the database for searching.
database = Xapian::Database.new(ARGV[0])

# Start an enquire session.
enquire = Xapian::Enquire.new(database)

queryString = ''
relevantDocs = Xapian::RSet.new()
onDocIdsYet = false

# Combine the rest of the command line arguments with spaces between
# them, so that simple queries don't have to be quoted at the shell
# level.
ARGV.each_with_index { |arg,index|
  next if index == 0 # skip path to db

  if arg == '--'
    onDocIdsYet = true
    next
  end

  if onDocIdsYet
    relevantDocs.add_document(arg.to_i)
  else
    queryString += ' ' unless queryString.empty?
    queryString += arg
  end
}


# Parse the query string to produce a Xapian::Query object.
qp = Xapian::QueryParser.new()
stemmer = Xapian::Stem.new("english")
qp.stemmer = stemmer
qp.database = database
qp.stemming_strategy = Xapian::QueryParser::STEM_SOME
query = qp.parse_query(queryString)

unless query.empty?
  puts "Parsed query is: #{query.description()}"

  # Find the top 10 results for the query.
  enquire.query = query
  matchset = enquire.mset(0, 10, relevantDocs)

  # Display the results.
  puts "#{matchset.matches_estimated()} results found."
  puts "Matches 1-#{matchset.size}:\n"

  matchset.matches.each {|m|
    puts "#{m.rank + 1}: #{m.percent}% docid=#{m.docid} [#{m.document.data}]\n"
  }
end
  
# Put the top 5 (at most) docs into the rset if rset is empty
if relevantDocs.empty?
  matchset.matches[0..4].each {|match|
    relevantDocs.add_document(match.docid())
  }
end

# Get the suggested expand terms
expandTerms = enquire.eset(10, relevantDocs)
puts "#{expandTerms.size()} suggested additional terms:"
expandTerms.terms.each {|term|
  puts "  * Term \"#{term.name}\", weight #{term.weight}"
}