index —
Attribute | Pos. | Req. | Default | Description |
---|---|---|---|---|
extension | ||||
basefile | ||||
type | ||||
export_only | ||||
spec | ||||
fn | ||||
fields | ||||
col | ||||
columns | ||||
show_status | ||||
interpolate | 0 | interpolate input? | ||
reparse | 1 | interpolate output? |
Interchange 5.9.0:
Source: code/SystemTag/index.coretag
Lines: 16
# Copyright 2002-2007 Interchange Development Group and others # # 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. See the LICENSE file for details. # # $Id: index.coretag,v 1.5 2007-03-30 23:40:49 pajamian Exp $ UserTag index Order table UserTag index addAttr UserTag index attrAlias base table UserTag index attrAlias database table UserTag index PosNumber 1 UserTag index Version $Revision: 1.5 $ UserTag index MapRoutine Vend::Data::index_database
Source: lib/Vend/Data.pm
Lines: 1137
sub index_database { my($dbname, $opt) = @_; return undef unless defined $dbname; my $db; $db = database_exists_ref($dbname) or do { logError("Vend::Data export: non-existent database %s", $dbname); return undef; }; $db = $db->ref(); my $ext = $opt->{extension} || 'idx'; my $db_fn = $db->config('db_file'); my $bx_fn = $opt->{basefile} || $db->config('db_text'); my $ix_fn = "$bx_fn.$ext"; my $type = $opt->{type} || $db->config('type'); #::logDebug( # "dbname=$dbname db_fn=$db_fn bx_fn=$bx_fn ix_fn=$ix_fn\n" . # "options: " . uneval($opt) . "\n" # ); if( ! -f $bx_fn or file_modification_time($db_fn) > file_modification_time($bx_fn) ) { export_database($dbname, $bx_fn, $type); } return if $opt->{export_only}; if( -f $ix_fn and file_modification_time($ix_fn) >= file_modification_time($bx_fn) ) { # We didn't need to index if got here return; } if(! $opt->{spec}) { $opt->{fn} = $opt->{fn} || $opt->{fields} || $opt->{col} || $opt->{columns}; my $key = $db->config('KEY'); my @fields = grep $_ ne $key, split /[\0,\s]+/, $opt->{fn}; my $sort = join ",", @fields; if(! $opt->{fn}) { logError(errmsg("index attempted on table '%s' with no fields, no search spec", $dbname)); return undef; } $opt->{spec} = <<EOF; ra=1 rf=$opt->{fn} tf=$sort EOF } my $scan = Vend::Interpolate::escape_scan($opt->{spec}); $scan =~ s:^scan/::; my $c = { mv_list_only => 1, mv_search_file => $bx_fn, }; Vend::Scan::find_search_params($c, $scan); $c->{mv_matchlimit} = 100000 unless defined $c->{mv_matchlimit}; my $f_delim = $c->{mv_return_delim} || "\t"; my $r_delim = $c->{mv_record_delim} || "\n"; my @fn; if($c->{mv_return_fields}) { @fn = split /\s*[\0,]+\s*/, $c->{mv_return_fields}; } #::logDebug( "search options: " . uneval($c) . "\n"); open(Vend::Data::INDEX, "+<$ix_fn") or open(Vend::Data::INDEX, "+>$ix_fn") or die "Couldn't open $ix_fn: $!\n"; lockfile(\*Vend::Data::INDEX, 1, 1) or die "Couldn't exclusive lock $ix_fn: $!\n"; open(Vend::Data::INDEX, "+>$ix_fn") or die "Couldn't write $ix_fn: $!\n"; if(@fn) { print INDEX " "; print INDEX join $f_delim, @fn; print INDEX $r_delim; } my $ref = Vend::Scan::perform_search($c); for(@$ref) { print INDEX join $f_delim, @$_; print INDEX $r_delim; } unlockfile(\*Vend::Data::INDEX) or die "Couldn't unlock $ix_fn: $!\n"; close(Vend::Data::INDEX) or die "Couldn't close $ix_fn: $!\n"; return 1 if $opt->{show_status}; return; }