Index/Search support over file contents (Swish-e)

This commit is contained in:
Jaromil 2013-06-12 18:15:55 +02:00
parent 5c70938b67
commit 9706ef1ab1

61
tomb
View File

@ -52,6 +52,7 @@ KDF=1
STEGHIDE=1
MKTEMP=1
RESIZER=1
SWISH=1
MOUNTOPTS="rw,noatime,nodev"
typeset -A global_opts
@ -427,10 +428,10 @@ check_bin() {
command -v steghide > /dev/null || STEGHIDE=0
# check for resize
command -v e2fsck resize2fs > /dev/null || RESIZER=0
# check for KDF auxiliary tools
command -v tomb-kdb-pbkdf2 > /dev/null || KDF=0
# check for Swish-E file content indexer
command -v swish-e > /dev/null || SWISH=0
}
# }}} - Commandline interaction
@ -478,7 +479,7 @@ load_key() {
# this does a check on the file header
if ! is_valid_key ${tombkey}; then
_warning "The key seems invalid, the application/pgp header is missing"
return 1
return 1
fi
print "$tombkey"
return 0
@ -1556,7 +1557,15 @@ index_tombs() {
fi
}
yes "Creating and updating search indexes"
# start the LibreOffice document converter if installed
{ command -v unoconv >/dev/null } && {
unoconv -l 2>/dev/null &
xxx "unoconv listener launched"
sleep 1 }
for t in ${mounted_tombs}; do
mapper=`basename ${t[(ws:;:)1]}`
tombname=${t[(ws:;:)5]}
@ -1564,8 +1573,40 @@ index_tombs() {
{ test -r ${tombmount}/.noindex } && {
say "skipping $tombname (.noindex found)"
continue }
say "indexing $tombname"
say "indexing $tombname filenames..."
updatedb -l 0 -o ${tombmount}/.updatedb -U ${tombmount}
# here we use swish to index file contents
{ test $SWISH = 1 } && {
say "indexing $tombname contents..."
swishrc=`safe_filename swish`
cat <<EOF > $swishrc
DefaultContents TXT*
FileFilter .pdf pdftotext "'%p' -"
FileFilterMatch unoconv "-d spreadsheet -f csv --stdout %P" /\.xls.*/
FileFilterMatch unoconv "-d spreadsheet -f csv --stdout %P" /\.xlt.*/
FileFilter .ods unoconv "-d spreadsheet -f csv --stdout %P"
FileFilter .ots unoconv "-d spreadsheet -f csv --stdout %P"
FileFilter .dbf unoconv "-d spreadsheet -f csv --stdout %P"
FileFilter .dif unoconv "-d spreadsheet -f csv --stdout %P"
FileFilter .uos unoconv "-d spreadsheet -f csv --stdout %P"
FileFilter .sxc unoconv "-d spreadsheet -f csv --stdout %P"
FileFilterMatch unoconv "-d document -f txt --stdout %P" /\.doc.*/
FileFilterMatch unoconv "-d document -f txt --stdout %P" /\.odt.*/
FileFilterMatch unoconv "-d document -f txt --stdout %P" /\.rtf.*/
IndexContents HTML* .htm .html .shtml
IndexContents XML* .xml
IndexDir $tombmount
IndexFile $tombmount/.swish
EOF
xxx "Using swish-e to create index"
swish-e -c $swishrc -S fs -v3
rm -f $swishrc
}
say "search index updated"
done
}
@ -1593,15 +1634,23 @@ search_tombs() {
tombname=${t[(ws:;:)5]}
tombmount=${t[(ws:;:)2]}
if [ -r ${tombmount}/.updatedb ]; then
say "Searching in tomb $tombname"
# use mlocate to search hits on filenames
say "Searching filenames in tomb $tombname"
locate -d ${tombmount}/.updatedb -e -i "${(f)@}"
say "Matches found: `locate -d ${tombmount}/.updatedb -e -i -c ${(f)@}`"
# use swish-e to search over contents
{ test $SWISH = 1 } && { test -r $tombmount/.swish } && {
say "Searching contents in tomb $tombname"
swish-search -w ${=@} -f $tombmount/.swish -H0 }
else
no "skipping tomb $tombname: not indexed"
no "run 'tomb index' to create indexes"
fi
done
say "Search completed."
}
# }}} - Index and search