forked from vjohansen/emacs-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vj-search-index-complete.pl
64 lines (54 loc) · 1.56 KB
/
vj-search-index-complete.pl
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
# Vagn Johansen 2013 (C)
# Usage: perl $0 <word-prefix [space substring]*> <project names..>
use DB_File;
use strict;
my $debug = 0;
my $inputSymbol = lc(shift @ARGV);
my @otherWords;
($inputSymbol, @otherWords) = split /\s+/, $inputSymbol;
my $symbol = lc($inputSymbol);
my @filenames = @ARGV or die "Usage: perl $0 symbol vps-project-name(s)\n";
use Data::Dump qw(pp);
my %filenames;
for my $dbfilename (@filenames)
{
my %database;
my $db = tie %database, 'DB_File', $dbfilename, O_CREAT|O_RDWR, 0666, $DB_BTREE or die "tie failed";
%database or die "$0: tie $dbfilename failed\n\nUse M-x vps-make-index RET\n\n";
my $key = $inputSymbol;
my $value = '?';
my $status = $db->seq($key, $value, R_CURSOR());
my @words;
my $hits = 0;
if ($key !~ /^-/) {
do {
my @ids = split(/-/, $database{$key});
shift @ids;
@ids = map { $filenames{$database{"-$_"}}++; $database{"-$_"} } @ids;
pp($key, $status, $value, [@ids]) if $debug;
push @words, $key;
last unless $hits++ < 200;
$status = $db->seq($key, $value, R_NEXT());
} while ($key =~ m/^\Q$inputSymbol\E/);
}
pp(\@words) if $debug;
undef $db;
untie %database;
}
my $filenames = join(" ", keys %filenames);
pp(\%filenames) if $debug;
if ($filenames) {
my $cmd = "grep -IHni $inputSymbol $filenames";
print $cmd if $debug;
while (@otherWords) {
my $word = $otherWords[0];
if ($word =~ /\w/) {
$word =~ s/^!/-v /; # ! means not
$cmd .= " | grep -i $word" if $word;
}
shift @otherWords;
}
system($cmd);
exit $? >> 8;
}
exit 1;