1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 # http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 # Example using a `FileIndex`
17 # This example shows of to index files from the system and retrieve them
27 var opt_white_exts
= new OptionArray("Allowed file extensions (default is [])",
28 "-w", "--whitelist-exts")
31 var opt_black_exts
= new OptionArray("Allowed file extensions (default is [])",
32 "-b", "--blacklist-exts")
35 opts
.add_option
(opt_white_exts
, opt_black_exts
)
39 var config
= new Config
40 config
.tool_description
= "usage: example_vsm <files>"
41 config
.parse_options
(args
)
43 if args
.length
< 1 then
48 var index
= new FileIndex
49 index
.whitelist_exts
= config
.opt_white_exts
.value
50 index
.blacklist_exts
= config
.opt_black_exts
.value
52 print
"Building index..."
53 index
.index_files
(args
, true)
54 print
"Indexed {index.documents.length} documents"
57 print
"\nEnter query:"
59 var input
= sys
.stdin
.read_line
60 var matches
= index
.match_string
(input
)
62 for match
in matches
do