LoginSignup
1
1

More than 5 years have passed since last update.

NamazuでPDFが日本語検索できない時の対処法

Posted at

Namazuとは

日本語が利用可能な全文検索システムのこと。
Webの検索システムとして使われたりもする。
詳細は公式でどうぞ。

PDFファイルの検索ができない

とあるサーバのリプレースをした。
そのサーバでは元々検索システムとしてNamazuを利用していたのだが、リプレース後もNamazuを継続して利用したいという声が上がり、導入することに。

ソースからコンパイルか・・・とげんなりしながらもどうにかインストール完了。
開発チームに渡して作業終了・・・となるはずだったのだが、開発で動作確認をしたところPDFファイルが日本語検索できない模様。

pdftotext コマンドの差異

検索したところ、Namazuの公式MLのやり取りが見つかる。
ここに何かないか・・・と検索をかけたところ、なんかそれっぽい情報が見つかる。

バージョンの問題?
スレッドから次の投稿を確認すると、以前パッチを提供してくれた方がいますよーとのこと。

投稿を確認
「poppler由来」ってのが気になる。

色々確認したところ、pdftotextコマンドのプロジェクトがフォークしたらしい。
CentOS5 以前だと Xpdf というプロジェクトの元に作成されていたらしいが、
CentOS6 から Poppler というプロジェクトのユーティリティとして
提供されるようになったらしい。
「じゃあ Xpdf の pdftotextコマンドを入れればいいじゃん」
と思ったのだが、yumでsearchとかprovidesしても出てこない。
どうやらPopplerに完全に取って代わられてしまった模様。

NamazuのMLを更にあさったところ、Popplerへ対応したプレ版をリリースしたとのこと。

なるほど。
じゃあパッチ充てれば問題ないってことね・・・。
製作者からのお墨付きもあるし、これは使うしかないな!
というわけでパッチを充てることに。

pdf.plへパッチを充てる

patchファイルはこれ

中身

patch
*** pdf.pl  2011-09-07 22:38:49+09  1.1
--- pdf.pl  2011-09-07 22:55:27+09
***************
*** 46,51 ****
--- 46,52 ----
      if (defined $pdfconvpath) {
          my @cmd = ("$pdfconvpath");
          my $result = "";
+         my $isPoppler = 0;
          my $status = util::syscmd(
              command => \@cmd,
              option => {
***************
*** 58,65 ****
          if ($result =~ m/^pdftotext\s+version\s+([0-9]+\.[0-9]+)/m) {
              $pdfconvver = $1;
          }
          if (util::islang("ja")) {
!             if ($pdfconvver >= 1.00) {
                  @pdfconvopts = ('-q', '-raw', '-enc', 'EUC-JP');
              } else {
                  @pdfconvopts = ('-q', '-raw', '-eucjp');
--- 59,69 ----
          if ($result =~ m/^pdftotext\s+version\s+([0-9]+\.[0-9]+)/m) {
              $pdfconvver = $1;
          }
+         if ($result =~ m/Copyright 2005-[0-9]+ The Poppler Developers/m) {
+             $isPoppler = 1;
+         }
          if (util::islang("ja")) {
!             if ($isPoppler || $pdfconvver >= 1.00) {
                  @pdfconvopts = ('-q', '-raw', '-enc', 'EUC-JP');
              } else {
                  @pdfconvopts = ('-q', '-raw', '-eucjp');
***************
*** 70,75 ****
--- 74,80 ----
          if (defined $pdfinfopath) {
              my @cmd = ("$pdfinfopath");
              my $result = "";
+             my $isPoppler = 0;
              my $status = util::syscmd(
                  command => \@cmd,
                  option => {
***************
*** 82,89 ****
              if ($result =~ /^pdfinfo\s+version\s+([0-9]+\.[0-9]+)/) {
                  $pdfinfover = $1;
              }
              if (util::islang("ja")) {
!                 if ($pdfinfover >= 2.02) {
                      @pdfinfoopts = ('-enc', 'EUC-JP');
                  } else {
                      @pdfinfoopts = ();
--- 87,97 ----
              if ($result =~ /^pdfinfo\s+version\s+([0-9]+\.[0-9]+)/) {
                  $pdfinfover = $1;
              }
+             if ($result =~ m/Copyright 2005-[0-9]+ The Poppler Developers/m) {
+                 $isPoppler = 1;
+             }
              if (util::islang("ja")) {
!                 if ($isPoppler || $pdfinfover >= 2.02) {
                      @pdfinfoopts = ('-enc', 'EUC-JP');
                  } else {
                      @pdfinfoopts = ();

上記パッチを充てていきます。
手順としては以下。

  1. 上記のパッチを適当な名前のファイルに貼り付ける。
  2. patch コマンドでパッチを当てる。
  3. オシマイ

簡単。一応下にコマンド列を書いておきます。

$ cd /usr/local/share/namazu/filter
$ vi pdf.pl.patch
  # 上記のパッチ内容を貼り付ける

$ cp -ip pdf.pl{,.orig}
$ patch < pdf.pl.patch
patching file pdf.pl

$ ls -la  pdf*
-rw-r--r-- 1 root root 6575 12月  1 16:38 2015 pdf.pl
-rw-r--r-- 1 root root 6251  9月 25 16:13 2015 pdf.pl.orig
-rw-r--r-- 1 root root 2360 12月  1 16:36 2015 pdf.pl.patch

$ diff -c pdf.pl{.orig,}

diffの出力結果が上記パッチと同様か確認する。

とりあえずこれでパッチ充てはOK。

開発チームにも確認してもらってめでたく完了した。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1