강좌
클라우드/리눅스에 관한 강좌입니다.
리눅스 분류

사이트 검색엔진(htdig)

작성자 정보

  • 웹관리자 작성
  • 작성일

컨텐츠 정보

본문

사이트 검색엔진(htdig)

 

t.gif
t.gif
작성일: 2002-09-15
작성자: 강명규(kang@dbakorea.pe.kr)
OS: Linux 2.4.18 (intel)

ht://Dig (www.htdig.org)

이것이 뭐하는 놈인가?
자신의 사이트의 검색엔진이 필요하다면 설치하기에 적당한 놈이다.
간단한 예제로 kldp.org에서 검색시 이 놈을 이용해서 처리하고 있다.

[root@ns /down]# wget http://www.htdig.org/files/htdig-3.1.6.tar.gz
[root@ns /down]# tar xvzf htdig-3.1.6.tar.gz -C /usr/local/src
[root@ns /down]# cd /usr/local/src/htdig-3.1.6/
[root@ns htdig-3.1.6]# ./configure
[root@ns htdig-3.1.6]# make;make install

여기까지 하면 /opt/www 에 모든 것들이 설치된다.
좀더 자세한 설치법은 http://www.htdig.org/dev/htdig-3.2/install.html를 참고하라.

/opt/www/htdig/bin에는 htdig와 관련된 실행파일들이 존재한다.

    * htdig     - A www information gathering and indexing system
    * htmerge   - A htdig database merging program
    * htfuzzy   - A fuzzy search database creation program
    * htsearch  - A search engine.
    * htlib     - A small general purpose C++ class library
    * htcommon  - ht://Dig specific classes
    * htdoc     - ht://Dig documentation in HTML
    * db        - The Berkeley DB package from Sleepycat Software

설정파일을 약간 수정할 필요가 있다.
자세한 설정사항은 http://www.htdig.org/confindex.html를 참고하라.

[/opt/www/htdig/conf/htdig.conf]에서 수정한 부분
start_url:              http://dbakorea.pe.kr/
exclude_urls:           /board/ /analog-5.01/ /image/ /webalizer/ /cgi-bin/ .cgi
bad_extensions:         .wav .gz .z .sit .au .zip .tar .hqx .exe .com .gif
        .jpg .jpeg .aiff .class .map .ram .tgz .bin .rpm .mpg .mov .avi .css
        .php .cfg .pl .sh .JPG
maintainer:             kang@dbakorea.pe.kr

설정파일을 수정후 다음과 같이 수행한다.
[root@ns htdig-3.1.6]# /opt/www/htdig/bin/rundig (serching database를 생성하므로 시간이 좀 걸린다)
[root@ns htdig-3.1.6]# l /opt/www/htdig/db
total 3294
-rw-r--r--    1 root     root       499712 Sep 15 07:23 db.docdb
-rw-r--r--    1 root     root        10240 Sep 15 07:23 db.docs.index
-rw-r--r--    1 root     root      1177185 Sep 15 07:23 db.wordlist
-rw-r--r--    1 root     root      1668096 Sep 15 07:23 db.words.db

rundig는 여러개의 실행파일을 차례로 실행한다.
initial database를 만들기 위해 htdig를 -i옵션으로(항상 reindex를 실시) 실행 ->
htmerge가 htdig에 의해 생성된 파일로부터 문서색인(document index), word database를 생성 ->
htnotify -> htfuzzy

사이트에 htdig를 가상호스트로 하여 달기로 한다.
[/usr/local/apache/conf/httpd.conf]
<VirtualHost *>
     ServerAdmin         kang@dbakorea.pe.kr
     DocumentRoot        /opt/www/htdocs
     ServerName          htdig.dbakorea.pe.kr
     ScriptAlias /cgi-bin/ /opt/www/cgi-bin/

        <Directory "/opt/www">
                Options -Indexes MultiViews
                AllowOverride None
                Order Allow,Deny
                Allow from all
        </Directory>
</VirtualHost>        

[/var/named/zone-dbakorea.pe.kr]
htdig   IN              A               61.74.120.193

만일 인덱스를 위한 데이터베이스 생성이 안된다면 htdig -v 와 같이 디버그옵션(-v)을
사용하여 파악해 보라.

모든 것이 정상이라면 http://htdig.dbakorea.pe.kr/search.html 주소로 접속하여 사이트내
컨텐트를 검색할 수 있다.

/opt/www/htdig/common디렉토리에 있는 파일을 수정하면, 출력문서의 포맷을 변경할 수 있다.
한 예로 출력되는 폰트크기를 변경하기 위해 header.html에 다음과 같이 스타일시트를 추가하자.

<head><title>Search results for '$&(WORDS)'</title>
<style type="text/css">
<!--
BODY {
font-family : 굴림체;
  font-size : 9pt;
  }
-->
</style></head>

이제 최신의 검색DB를 유지하기 위해 배치파일 <a href=/down/rundig.sh>rundig.sh</a>를 crontab에 등록하여
매일 새벽 4시에 실행하도록 하겠다. 제공된 rundig.sh는 자신의 환경에 맞게 메일주소등을 변경하기 바란다.

등록: crontab -e
보기: crontab -l

[kang@ns bin]$ crontab -l
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.14827 installed on Sun Sep 15 22:09:57 2002)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
0 4 * * * /opt/www/htdig/bin/rundig.sh


지금까지 별다른 조치가 없는 상태에서는 한국어의 검색을 할 수 없다.
<a href="/down/htdig-3.1.5-ko.patch">3.1.5버전의 한글패치</a>가 있는데 이를 3.1.6에 적용해도 크게 지장이 없으므로 패치를 적용하면 한글을 사용할 수 있다.


[root@ns htdig-3.1.6]# cat htdig-3.1.5-ko.patch | patch -p1
patching file `CONFIG'
patching file `Makefile.config.in'
patching file `Makefile.in'
Hunk #1 FAILED at 94.
1 out of 1 hunk FAILED -- saving rejects to Makefile.in.rej
patching file `README.ko'
patching file `contrib/htparsedoc/catdoc.c'
patching file `contrib/htparsedoc/htparsedoc'
Hunk #1 succeeded at 15 (offset 1 line).
Hunk #2 FAILED at 57.
1 out of 2 hunks FAILED -- saving rejects to contrib/htparsedoc/htparsedoc.rej
patching file `htcommon/WordList.cc'
patching file `htdig/Document.cc'
Hunk #1 succeeded at 694 (offset 146 lines).
patching file `htdig/Plaintext.cc'
patching file `htdig/Retriever.cc'
Hunk #2 succeeded at 1032 (offset 12 lines).
patching file `htdig/hantail.txt'
patching file `htlib/HtWordType.h'
patching file `htsearch/Display.cc'
Hunk #1 succeeded at 1528 (offset 365 lines).
Hunk #2 succeeded at 1196 with fuzz 2.
patching file `installdir.ko/english.aff'
patching file `installdir.ko/footer.html'
patching file `installdir.ko/header.html'
patching file `installdir.ko/htdig.conf'
patching file `installdir.ko/nomatch.html'
patching file `installdir.ko/search.html'
patching file `installdir.ko/syntax.html'
[root@ns htdig-3.1.6]#

위에서 보듯이 Makefile.in htparsedoc등에서 뭐라고 하지만, 신경쓰지 말자.
나의 경우, 모든 설치가 끝난 후 한글패치를 적용했는데 순서가 변경되면 어떻게 될지 확인 못했다.
위의 순서에 따라 하면 크게 지장을 없을 듯한다.

dbakorea에서 사용하던 검색창폼
<form method="post" action="/cgi-bin/htsearch">
<input type="hidden" name="method" value="and">
<input type="hidden" name="format" value="Long">
<input type="hidden" name="sort" value="Score">
<input type="hidden" name="config" value="htdig">
<input type="hidden" name="restrict" value="">
<input type="hidden" name="exclude" value="">
<input type="text" size="15" maxlength="30" name="words" value="" class=editbox>
<input type="submit" value="사이트검색" class=button>
</form>

This article comes from dbakorea.pe.kr (Leave this line as is)

관련자료

댓글 0
등록된 댓글이 없습니다.

공지사항


뉴스광장


  • 현재 회원수 :  60,032 명
  • 현재 강좌수 :  35,773 개
  • 현재 접속자 :  243 명