Debian Codegraph @

tools/generate-long-posting-list-data.rb

raw symbols SCIP
1 #!/usr/bin/env ruby
2 #
3 # Copyright(C) 2019 Kouhei Sutou <[email protected]>
4 #
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2.1 of the License, or (at your option) any later version.
9 #
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
14 #
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19 require "json"
20 require "optparse"
21
22 n_records = 100000
23 use_section = false
24 content = "XX XX XX"
25 parser = OptionParser.new
26 parser.on("--n-records=N", Integer,
27 "[#{n_records}]") do |n|
28 if n < 0
29 n_records = Float::INFINITY
30 else
31 n_records = n
32 end
33 end
34 parser.on("--[no-]use-section",
35 "[#{use_section}]") do |boolean|
36 use_section = boolean
37 end
38 parser.on("--content=CONTENT",
39 "[#{content}]") do |_content|
40 content = _content
41 end
42 parser.parse!
43
44 if use_section
45 columns = 5.times.collect {|i| "value#{i}"}
46 else
47 columns = ["value"]
48 end
49
50 puts(<<-COMMANDS)
51 table_create Data TABLE_NO_KEY
52 COMMANDS
53 columns.each do |column|
54 puts(<<-COMMANDS)
55 column_create Data #{column} COLUMN_SCALAR|COMPRESS_ZSTD Text
56 COMMANDS
57 end
58
59 index_column_flags = "COLUMN_INDEX|WITH_POSITION"
60 if columns.size > 1
61 index_column_flags += "|WITH_SECTION"
62 end
63 puts(<<-COMMANDS)
64 table_create Terms TABLE_PAT_KEY ShortText \
65 --normalizer NormalizerNFKC100 \
66 --default_tokenizer TokenRegexp
67 column_create Terms index #{index_column_flags} Data #{columns.join(",")}
68 COMMANDS
69
70 puts(<<-LOAD)
71 load --table Data
72 [
73 LOAD
74 (1..n_records).each do |id|
75 record = {"_id" => id}
76 columns.each do |column|
77 record[column] = content
78 end
79 puts(record.to_json)
80 end
81 puts(<<-LOAD)
82 ]
83 LOAD