如何将 Recoll 查询的结果移动到文件夹?

如何将 Recoll 查询的结果移动到文件夹?

我想知道是否可以将 Recoll 中的匹配文件(在多个文件 .pdf .doc 等的内容中搜索单词或字符串)发送到文件夹中。

谢谢!

答案1

您可以使用命令行搜索

recoll -t "yourquery" 

然后过滤它得到一个文件名列表。例如(你当然可以更简洁、更安全地做到这一点):

[:~/tmp/lalla/out] % files=$(recoll -t "x11vnc" | awk '{print $2}' | grep file:/// | sed 's+\[file://++' | sed 's/]$//')
[:~/tmp/lalla/out] % echo $files    
/home/romano/personal/archivio/Tricks/remote-ubuntu-login.txt
/home/romano/lib/Jed_Backups/remote-ubuntu-login.txt
/home/romano/software/documentation/Ubuntu:Maverick.html
/home/romano/personal/library/Unknown/Ubuntu_Maverick
/home/romano/.wajig/romano-asus/Available.prv
/home/romano/.wajig/romano-asus/Available
/home/romano/.wajig/asus-romano/Available.prv
/home/romano/.wajig/asus-romano/Available

然后使用它们:

 cp $files my-new-dir/

为了理解复杂的管道,recoll -t输出如下内容:

8 results
text/plain  [file:///home/romano/personal/archivio/Tricks/remote-ubuntu-login.txt]  [remote-ubuntu-login.txt]   322 bytes
  1. 第一个awk只打印第二个(空格分隔)项目(和将要如果文件名中有空格的话,事情就会变得混乱);
  2. 仅选择grep包含“file:///”的行
  3. 第一个sed删除前导[file://(注意使用+分隔符)
  4. 第二个sed删除尾随的]

也许正确的方法是使用recoll Python 绑定

答案2

Bash 脚本解决方案

@Rmano 抢先一步,但我想有不同的解决方案总是好的。这是我编写的脚本:

#!/bin/bash

# NAME:         recoll_move_results
# VERSION:      0.1
# AUTHOR:       (c) 2014 Glutanimate
# DESCRIPTION:  queries recoll database for provided string and either symlinks or moves
#               results
# DEPENDENCIES: recoll
#
# LICENSE:      GNU GPLv3 (http://www.gnu.de/documents/gpl-3.0.en.html)
#
# NOTICE:       THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. 
#               EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES 
#               PROVIDE THE PROGRAM “AS IS” WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR 
#               IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 
#               AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 
#               PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE,
#               YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
#
#               IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY 
#               COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS THE PROGRAM AS 
#               PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, 
#               INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE 
#               THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED 
#               INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE 
#               PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 
#               PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
#
# USAGE:        recoll_move_results <query>

# VARIABLES / SETINGS

DESTINATION="$HOME/recollresults" # ⇐ Set the destination folder here

QUERY="$@"
USAGE="$0 <query>"

if [[ -z "$QUERY" ]]
  then
      echo "Error: No arguments provided."
      echo "Usage: $USAGE"
      exit 1
fi

# create destination folder
mkdir -p "$DESTINATION"

# FUNCTIONS

# query recoll and convert URIs to file paths
recoll_get_results(){
    recoll -t -b "$QUERY" 2> /dev/null | sed 's,file://,,g'
}

# symlink or move files read from stdin
move_files(){
    while read -r FILE; do
      echo "Processing $FILE"
      FILENAME="${FILE##*/}"
      # PLEASE USE ONLY ONE OF THE OPTIONS BELOW. COMMENT THE ONE YOU DON'T WANT
      # AND UNCOMMENT THE ONE YOU DO WANT
      ln -sv "$FILE" "$DESTINATION/$FILENAME" # Create a symbolic link in $DESTINATION
      #mv -v "$FILE" "$DESTINATION/$FILENAME" # Move to $DESTINATION
    done
}

# MAIN

recoll_get_results "$QUERY" | move_files

用法

使用脚本:

 recoll_move_results <query>

它将执行提供的查询,并将所有搜索结果符号链接或移动到新创建的文件夹。脚本应该正确处理空格和特殊字符(换行符除外)。


设置

您可以自定义以下一些设置:

  • DESTINATION="$HOME/recollresults"- 修改此项以设置目标文件夹
  • ln -sv "$FILE" "$DESTINATION/$FILENAME"#-如果您确定要移动文件而不是创建指向它们的符号链接,请注释此行(使用),并取消注释以下行

请注意,移动结果将导致无法从 Recoll 的搜索界面访问文件,直到您再次更新索引。

另一个选择是通过替换来复制文件:

`ln -sv "$FILE" "$DESTINATION/$FILENAME"`

`cp -v "$FILE" "$DESTINATION/$FILENAME"`

相关内容