Namazu-users-ja(旧)


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

コメント処理の改造



 濱谷@RSKです。

 Namazu 2.0.10 (tar.gz版) を、RedHat 7.2 で使っています。
 Namazu 2.0.10 で、コメント内にあるにもかかわらず、次の hogehoge が
インデックスに載ってしまうことに気が付きました。

    <!-- <A href="dokoka">hogehoge</A> -->

 filter/html.pl をみたところ、コメントの削除はremove_html_elements()
にありますが、そのまえに weight_element() で <A>タグの処理を行っている
ため、こうなるみたいです。

 私はコメント内はすべて無視してほしかったので、html.pl の
remove_html_elements からコメント削除処理を抜き出し、weight_element()
の直前で呼ぶようにしました。これでうまく動いているようです。
 この件のパッチを作りましたので、以下に添付します。

--------------------------------------------------
*** html.pl-   Mon Feb 18 11:54:12 2002
--- html.pl    Mon Feb 18 11:56:00 2002
***************
*** 99,104 ****
--- 99,105 ----
      html::get_title_attr($contref);
      html::normalize_html_element($contref);
      html::erase_above_body($contref);
+     html::remove_comments($contref);
      html::weight_element($contref, $weighted_str, $headings);
      html::remove_html_elements($contref);
      # restore entities of each content.
***************
*** 226,231 ****
--- 227,240 ----
  }


+ # remove all comments. it's not perfect but almost works.
+ sub remove_comments ($) {
+     my ($contref) = @_;
+
+     # remove all comments
+     $$contref =~ s/<!--.*?-->//gs;
+ }
+
  # Weight a score of a keyword in a given text using %conf::Weight hash.
  # This process make the text be surround by temporary tags
  # \x7fXX\x7f and \x7f/XX\x7f. XX represents score.
***************
*** 265,273 ****
  # remove all HTML elements. it's not perfect but almost works.
  sub remove_html_elements ($) {
      my ($contref) = @_;
-
-     # remove all comments
-     $$contref =~ s/<!--.*?-->//gs;

      # remove all elements
      $$contref =~
s!</?([A-Z]\w*)(?:\s+[A-Z]\w*(?:\s*=\s*(?:(["']).*?\2|[\w\-.]+))?)*\s*>!element_space($1)!gsixe;
--- 274,279 ----

--
 リコーシステム開発(株)  濱谷 千尋 (Hamatani, Chihiro)
 mailto:hamatani@xxxxxxxxxxxxxxx