'Elastic/Elasticsearch'에 해당되는 글 385건

  1. 2013.06.28 [elasticsearch] query timeout 개념 설명
  2. 2013.06.20 [elasticsearch] path_hierachy 설정
  3. 2013.06.19 [lucene]phrase query
  4. 2013.05.27 [lucene] field options for indexing - StringField.java
  5. 2013.05.22 [elasticsearch] mapping 분석 및 이해. 5
  6. 2013.05.22 [검색일반] elasticsearch + logstash + kibana
  7. 2013.05.21 [한글형태소분석기] 카이스트 한나눔 분석기.
  8. 2013.05.16 [Lucene] Apache Lucene - Index File Formats (발번역)
  9. 2013.05.15 [Algorithm] Document Weight.
  10. 2013.05.15 [Algorithm] IDF(Inverse Document Frequency)

[elasticsearch] query timeout 개념 설명

Elastic/Elasticsearch 2013. 6. 28. 21:46

elasticsearch 에서의 query timeout 에 대해 설명 합니다.


query timeout 은 두 가지 방법으로 설정이 가능 합니다.

1. Java API

setTimeout(millisecond)

2. Request URI (?timeout=10ms)

timeout=1S

S    : 1S = 1millisecond

ms : millisecond

s : second

m : minute

H : hour

d : day

w : week


기본 millisecond 입니다.


elasticsearch 에서는 query execution 후 중지 시킬 수 없습니다.

즉, timeout 을 지정 했다고 해서 실행 시간이 설정한 timeout 을 넘더라도 실행을 중지 하거나 connection 을 끊거나 하지 않습니다.


shard 들에 질의 후 문서를 collecting 하는데 실행 시간을 제한 하는 기능 입니다.

es 에서 구현된 기능이 아닌 lucene 에서 구현된 기능 입니다.


아래는 이해를 돕기 위한 관련 클래스 파일 입니다.

lucene

TimeLimitingCollector.java

elasticsearch

ContextIndexSearcher.java

TimeValue.java


:

[elasticsearch] path_hierachy 설정

Elastic/Elasticsearch 2013. 6. 20. 15:14

category 나 기타 tree 구조를 갖는 문서속성의 경우 path_hierachy 기능을 사용하면 유용한 부분이 있습니다.

단, 이 기능은 facet 사용은 못하니 참고 하시구요.


{

    "settings" : {

        "index" : {

            "analysis" : {

                "analyzer" : {

                    "path_analyzer" : {"tokenizer" : "path_hierarchy"}

                }

            }

        }

    },

    "mappings" : {

        "category" : {

            "properties" : {

                "category" : {

                    "type" : "multi_field",

                    "fields" : {

                        "name" : { "type" : "string", "index" : "not_analyzed" },

                        "path" : { "type" : "string", "analyzer" : "path_analyzer", "store" : true }

                    }

                }

            }

        }

    }

}



:

[lucene]phrase query

Elastic/Elasticsearch 2013. 6. 19. 14:22

http://www.avajava.com/tutorials/lessons/how-do-i-query-for-words-near-each-other-with-a-phrase-query.html


slop 관련 설명이 잘 되어 있어 공유 합니다.


Here are some foods that Deron likes:
hamburger
french fries
steak
mushrooms
artichokes
Query: contents:"french fries"
Number of hits: 1
Hit: C:\projects\workspace\demo\filesToIndex\deron-foods.txt

Query: contents:"hamburger steak"
Number of hits: 0

Query: contents:"hamburger steak"~1
Number of hits: 0

Query: contents:"hamburger steak"~2
Number of hits: 1
Hit: C:\projects\workspace\demo\filesToIndex\deron-foods.txt

Query: contents:"hamburger steak"~3
Number of hits: 1
Hit: C:\projects\workspace\demo\filesToIndex\deron-foods.txt

Searching for 'french fries' using QueryParser
Type of query: BooleanQuery
Query: contents:french contents:fries
Number of hits: 1
Hit: C:\projects\workspace\demo\filesToIndex\deron-foods.txt

Searching for '"french fries"' using QueryParser
Type of query: PhraseQuery
Query: contents:"french fries"
Number of hits: 1
Hit: C:\projects\workspace\demo\filesToIndex\deron-foods.txt

Searching for '"hamburger steak"~1' using QueryParser
Type of query: PhraseQuery
Query: contents:"hamburger steak"~1
Number of hits: 0

Searching for '"hamburger steak"~2' using QueryParser
Type of query: PhraseQuery
Query: contents:"hamburger steak"~2
Number of hits: 1
Hit: C:\projects\workspace\demo\filesToIndex\deron-foods.txt

Let's talk briefly about the console output. The first phrase query searches for "french" and "fries" with a slop of 0, meaning that the phrase search ends up being a search for "french fries", where "french" and "fries" are next to each other. Since this exists in deron-foods.txt, we get 1 hit.

In the second query, we search for "hamburger" and "steak" with a slop of 0. Since "hamburger" and "steak" don't exist next to each other in either document, we get 0 hits. The third query also involves a search for "hamburger" and "steak", but with a slop of 1. These words are not within 1 word of each other, so we get 0 hits.

The fourth query searches for "hamburger" and "steak" with a slop of 2. In the deron-foods.txt file, we have the words "... hamburger french fries steak ...". Since "hamburger" and "steak" are within two words of each other, we get 1 hit. The fifth phrase query is the same search but with a slop of 3. Since "hamburger" and "steak" are withing three words of each other (they are two words from each other), we get a hit of 1.

The next four queries utilize QueryParser. Notice that in the first of the QueryParser queries, we get a BooleanQuery rather than a PhraseQuery. This is because we passed QueryParser's parse() method "french fries" rather than "\"french fries\"". If we want QueryParser to generate a PhraseQuery, the search string needs to be surrounded by double quotes. The next query does search for "\"french fries\"" and we can see that it generates a PhraseQuery (with the default slop of 0) and gets 1 hit in response to the query.

The last two QueryParser queries demonstrate setting slop values. We can see that the slop values can be set the following the double quotes of the search string with a tilde (~) following by the slop number.

As we have seen, phrase queries are a great way to produce queries that have a degree of leeway to them in terms of the proximity and ordering of the words to be searched. The total allowed spacing between words can be controlled using the setSlop() method of PhaseQuery.


:

[lucene] field options for indexing - StringField.java

Elastic/Elasticsearch 2013. 5. 27. 10:52

lucene 3.6.X 에는 없는 클래스 입니다.

4.X 에서 처음 등장한 넘이구요.

코드를 조금 보면

public final class StringField extends Field {


  /** Indexed, not tokenized, omits norms, indexes

   *  DOCS_ONLY, not stored. */

  public static final FieldType TYPE_NOT_STORED = new FieldType();


  /** Indexed, not tokenized, omits norms, indexes

   *  DOCS_ONLY, stored */

  public static final FieldType TYPE_STORED = new FieldType();


  static {

    TYPE_NOT_STORED.setIndexed(true);

    TYPE_NOT_STORED.setOmitNorms(true);

    TYPE_NOT_STORED.setIndexOptions(IndexOptions.DOCS_ONLY);

    TYPE_NOT_STORED.setTokenized(false);

    TYPE_NOT_STORED.freeze();


    TYPE_STORED.setIndexed(true);

    TYPE_STORED.setOmitNorms(true);

    TYPE_STORED.setIndexOptions(IndexOptions.DOCS_ONLY);

    TYPE_STORED.setStored(true);

    TYPE_STORED.setTokenized(false);

    TYPE_STORED.freeze();

  }


  /** Creates a new StringField. 

   *  @param name field name

   *  @param value String value

   *  @param stored Store.YES if the content should also be stored

   *  @throws IllegalArgumentException if the field name or value is null.

   */

  public StringField(String name, String value, Store stored) {

    super(name, value, stored == Store.YES ? TYPE_STORED : TYPE_NOT_STORED);

  }

}


무조건 index true 입니다.

기존이랑은 좀 다르죠.

예전 옵션에 대한 정보만 가지고 있으면 실수 할 수도 있는 부분이라 살짝 올려봤습니다.

:

[elasticsearch] mapping 분석 및 이해.

Elastic/Elasticsearch 2013. 5. 22. 18:24

elasticsearch 에서 성능 및 운영에 있어서 기본이면서 핵심 내용이 될 수 있는 정보 입니다.

사실 이 내용만 잘 이해 하고 있으면 50% 이상 먹고 들어 갈 수 있습니다. ^^


mapping section

http://www.elasticsearch.org/guide/reference/mapping/


fields 와 types 를 확인해야 함.

fields

_id

document 의 unique id 는 _uid (_id + _type) 이며, _id 는 색인 ID 로 사용될 수 있다.

기본적으로 색인되지 않고 저장 하지 않습니다.

_type

기본적으로 색인은 하지만 저장은 하지 않습니다.

_source

자동으로 field 생성을 허용할지 결정 합니다.

_all

하나 또는 더 많은 field 를 색인시 저장 할 것인지 결정을 합니다.

"simple1" : {"type" : "long", "include_in_all" : true},

"simple2" : {"type" : "long", "include_in_all" : false}

_analyzer (설정 하지 않아도 되는 field)

색인 시 등록된 analyzer 또는 index_analyzer 를 사용 합니다.

또한, 특정 field 를 지정 할 경우 해당 field 에 정의된 analyzer 를 사용하게 됩니다.

_boost

문서나 field 의 연관성을 향상시키기 위해 사용한다.

_parent

parent type 을 지시하는 child mapping 정의 입니다.

blog type 과 blog_tag type 이 있을 경우 blog_tag 의 parent type 은 blog 가 됩니다.

_routing

색인 데이터에 대한 routing 관리를 위해서 사용 합니다.

routing field 는 store : yes, index : not_analyzed 로 설정이 되어야 합니다.

_index (설정 하지 않아도 되는 field)

index 가 소유한 문서를 store 합니다.

default false 로 저장 하지 않음.

_size (설정 하지 않아도 되는 field)

_source 에 의해서 자동으로 생성된 색인 field 의 수.

default disabled 입니다.

_timestamp

색인 시 문서의 timestamp 입니다.

기본 store : no, index : not_analyzed 이며,

설정 시 field 지정이 가능 합니다.

format 은 기본 dateOptionalTime. (http://www.elasticsearch.org/guide/reference/mapping/date-format/)

_ttl

색인 시 문서의 expiration date를 설정 합니다.

기본 disabled 입니다.

설정 시 ttl 이후 문서는 자동 삭제 됩니다.

core types

string type

index_name

array type 선언 시 사용되는 항목으로 array list 항목에 대한 개별 field 명으로 사용된다.

store

default no 이며, 저장에 대한 설정을 위해서 사용 된다.

yes 시 저장

index

검색 또는 색인 시 분석관련 설정을 위해서 사용 된다.

analyzed

검색과 색인 시 analyzer 를 이용해서 분석

not_analyzed

검색가능 하다는 의미

no

검색 불가능 하다는 의미

term_vector

기본 no 설정

no

yes

with_offsets

with_positions

with_positions_offsets

boost

기본 1.0

null_value

null value 시 기본 값은 아무것도 넣지 않으나 설정한 값이 있을 경우 등록 함.

omit_norms

기본 false 로 analyzed field 설정, true 일 경우 not_analyzed field 에서 설정

index_options

색인 옵션

docs

not_analyzed field

freqs

analyzed field

positions

analyzed field

analyzer

global 설정으로 검색과 색인 시 사용된다.

index_analyzer

색인 시에 사용된다.

search_analyzer

검색 시에 사용된다.

include_in_all

기본 true 로 설정 됨.

_all field 에 저장할 것인지 지정함.

ignore_above

지정한 크기 이상의 문자열을 무시 합니다.

position_offset_gap

number type

type : "float, double, byte, short, integer, and long",

index_name

store

index

precision_step

number 의 term value 를 만들어 냅니다.

설정 값이 작을 수록 검색은 빠르게 이루어 집니다.

기본 값은 4이며, 32bits 는 4 정도, 64bits 는 6~8정도를 사용합니다.

0 은 disable 입니다.

null_value

boost

include_in_all

ignore_malformed

비정상적인 숫자를 무시 한다.

기본 false로 설정 되어 있기 때문에 true 설정 하는 것이 좋다.

date type

index_name

format

http://www.elasticsearch.org/guide/reference/mapping/date-format.html

store

index

precision_step

number 의 term value 를 만들어 냅니다.

설정 값이 작을 수록 검색은 빠르게 이루어 집니다.

기본 값은 4이며, 32bits 는 4 정도, 64bits 는 6~8정도를 사용합니다.

0 은 disable 입니다.

null_value

boost

include_in_all

ignore_malformed

비정상적인 숫자를 무시 한다.

기본 false로 설정 되어 있기 때문에 true 설정 하는 것이 좋다.

boolean type

index_name

store

index

null_value

boost

include_in_all

binary type

index_name



default mapping template

"mapping" : {

"TYPE_NAME" : {

"analyzer" : "standard",

"index_analyzer" : "stadnard",

"search_analyzer" : "standard",

"_id" : {

"index" : "not_analyzed",

"store" : "yes",

"path" : "FIELD_NAME"

},

"_type" : {

"index" : "not_analyzed",

"store" : "yes"

},

"_source" : {

"enabled" : "false"

},

"_all" : {

"enabled" : "false"

},

"_boost" : {

"name" : "_boost",

"null_value" : 1.0

},

"_parent" : {

"type" : "PARENT_TYPE_NAME"

},

"_routing" : {

"required" : true,

"path" : "TYPE_NAME.FIELD_NAME"

},

"_timestamp" : {

"enabled" : true,

"path" : "DATE_FIELD_NAME",

"format" : "dateOptionalTime"

},

"properties" : {

"FIELD_NAME" : {

"type" : "string",

"index_name" : ,

"store" : ,

"index" : ,

"term_vector" : ,

"boost" : ,

"null_value" : ,

"omit_norms" : ,

"omit_term_freq_and_positions" : ,

"index_options" : ,

"analyzer" : ,

"index_analyzer" : ,

"search_analyzer" : ,

"include_in_all" : ,

"ignore_above" : ,

"position_offset_gap" : 

},

"FIELD_NAME" : {

"type" : "float, double, byte, short, integer, and long",

"index_name" : ,

"store" : ,

"index" : ,

"precision_step" : ,

"null_value" : ,

"boost" : ,

"include_in_all" : ,

"ignore_malformed" :

},

"FIELD_NAME" : {

"type" : "date",

"index_name" : ,

"format" : ,

"store" : ,

"index" : ,

"precision_step" : ,

"null_value" : ,

"boost" : ,

"include_in_all" : ,

"ignore_malformed" :

},

"FIELD_NAME" : {

"type" : "boolean",

"index_name" : ,

"store" : ,

"index" : ,

"null_value" : ,

"boost" : ,

"include_in_all" : ,

},

"FIELD_NAME" : {

"type" : "binary",

"index_name" : ,

}

}

}

}


:

[검색일반] elasticsearch + logstash + kibana

Elastic/Elasticsearch 2013. 5. 22. 17:47

로그를 수집해서 색인을 하고 검색 결과에 대한 분석 서비스가 나왔내요.

splunk 랑 비슷한 역할을 하는 오픈 소스라 elasticsearch 와 잘 조합해서 사용을 하면 splunk 보다 더 좋은 오픈소스 플랫폼이 나오지 않을까 싶내요.


[오픈소스 링크]

https://github.com/elasticsearch/kibana

http://logstash.net/

https://github.com/elasticsearch/elasticsearch


[주의사항]

index name format : logstash-yyyy.mm.dd

@timestamp : es datetime format

:

[한글형태소분석기] 카이스트 한나눔 분석기.

Elastic/Elasticsearch 2013. 5. 21. 03:53

오픈소스 한글 형태소 분석기 중 루씬 기반으로만 사용하다 보니 이런게 있는지 이제야 알았내요.. ^^;


http://kldp.net/projects/hannanum/



[SVN Checkout]



익명 Subversion 권한

이 프로젝트의 SVN 저장소는 다음과 같은 방법을 통해 익명으로 체크아웃하실 수 있습니다.
  • svn checkout --username anonsvn http://kldp.net/svn/hannanum
  • The password is 'anonsvn'



[Demo Run]

- 실행 전 JDK compiler 를 1.6 으로 변경해 주시기 바랍니다.

package kr.ac.kaist.swrc.jhannanum.demo; 아래 클래스 하나 실행 하시면 됩니다.

- Run As -> Java Application

:

[Lucene] Apache Lucene - Index File Formats (발번역)

Elastic/Elasticsearch 2013. 5. 16. 13:34

 

원문 : http://lucene.apache.org/core/4_3_0/core/org/apache/lucene/codecs/lucene42/package-summary.html#Overview

--> Upgrade : lucene.apache.org/core/8_8_2/core/org/apache/lucene/codecs/lucene87/package-summary.html#package.description

Definitions

 

루씬의 기본 개념은 인덱스, 문서, 필드, 용어(색인어)라고 볼수 있습니다.

인덱스는 문서들의 순서를 포함합니다..

 

문서는 필드들의 집합.

 

필드는 용어들의 집합

 

용어(색인어)는 바이트의 집합.

 

두개의 다른 필드에 동일한 바이트의 순서는 다른 용어(색인어)로 간주됩니다. 

 

용어(색인어)는 문자이름을 가진 필드와 바이트를 포함한 필드의 쌍으로 구성됩니다.

 

 

Inverted Indexing

 

인덱스는 효율적인 색인어 기반의 검색을 생성하기 위하여 색인어에 대한 통계를 저장 합니다.

 

루씬의 인덱스는 인덱스로 알려진 인덱스류로 구분되며, 색인어를 포함하는 문서를 나열 있기 때문 입니다.

 

친자연적 관계의 이라는 것은 문서 목록 색인어를 의미 합니다.

 

 

Types of Fields

 

루씬에서 필드들은 (필드 텍스트가 그대로 인덱스에 저장되어질 경우)비반전 방식으로 저장 있습니다.

 

반전된 필드들을 인덱스라고 부릅니다.

 

필드는 저장과 색인  있습니다.

 

필드의 텍스트들은 색인되기 위해 색인어로 토큰화 있으며, 또는 색인되기 위해 그대로 사용 수도 있습니다.

 

대부분의 필드들은 토근화 됩니다. 그러나 때때로 어떤 식별자 필드들로 그대로 인덱스화하는 것이 유용하기도 하다.

 

 

 

Segments

 

루씬 인덱스들은 여러 하위 인덱스와 세그멘트들로 구성될  있으며,  세그멘트들은 완전 독립된 인덱스로 따로 따로 검색 있습니다.

 

인덱스에 의한 진화:

 

새로운 문서가 추가 되는 동안 신규 세그멘트가 생성하고.

 

기존 세그멘트들을 머지 합니다.

 

검색은 여러 세그멘트들과 인덱스들을 포함할 있습니다. 개별 인덱스 들은 잠재적으로 세그멘트의 집합으로 구성 되어 집니다.

 

 

 

Document Numbers

 

내부적으로 루씬은 정수형 문서번호에 의한 문서와 관련이 있습니다첫번째 문서는 0번을 가지고 인덱스에 추가 됩니다. 이후 문서들은 이전 보다 숫자 1 값을 가지고 추가 됩니다.

 

 

문서의 번호는 루씬 외부에서 저장할때 변경 있으니 주의 해야 합니다.

 

특히 문서번호는 다음과 같은 상황에서 변경  있습니다.

 

세그먼트에 저장된 번호들은 세그먼트 내에서 고유합니다. 그리고 맥락에서 사용되기 전에 변환해야 합니다.

 

표준 기술은 세그먼트에서 사용된 번호들의 범위를 기반으로 값의 범위를 세그먼트에 할당 하게 됩니다.

 

세그먼트에서 외부 값으로 문서 번호를 변환 하기 위해서는 세그먼트의 기본 문서번호가 추가 됩니다.

 

세그먼트의 특정 값으로 다시 외부값을 변환 하려면, 세그먼트는 외부값의 범위에 의해서 식별 되어지고, 세그먼트의 기본 값은 빠집니다.

 

 

 

문서가 삭제 될때 문서번호 간격은 번호로 만들어집니다. 인덱스 병합을 통합으로서 결국 삭제 됩니다. 삭제 문서들은 세그먼트가 병합될때 삭제 됩니다. 새로 병합된 세그먼트들은 번호의 차이가 없습니다.

 

 

Index Structure Overview

 

세그먼트 인덱스 유지보수는 다음과 같습니다.

 

- 세그먼트 정보. 문서의 번호나 어떤 파일을 사용지와 같은 세그먼트의 메타정보를 포함 합니다.

 

- 인덱스에서 사용하는 필드 이름의 집합을 포함합니다.

 

저장된 필드 . 문서에 대한 속성들은 필드 이름이고 속성- 목록을 포함 합니다. 이것들은 문서에 대한 보조정보를 저장하기 위한 타이틀이나 URL 또는 데이터베이스에 접근하기 위한 식별자로 사용됩니다. 저장된 필드의 집합들은 검색 매칭된 개별로 반환 되어집니다. 반환된 값은 문서 번호에 의한 키입니다.

 

용어 사전. 색인된 모든 필드 문서에 들어 있는 색인어(용어) 포함 하고 있습니다.

 

또한 사전은 색인어의 빈도와 근접 데이터의 포인터 그리고 용어를 포함하는 문서들의 번호를 포함 합니다.

 

색인어(용어) 빈도 데이터. 사전에서 용어를 위해, 문서 빈도 설정을 생략 하지 않는 다면 모든 문서와 문서 번호에서 용어를 포함 합니다.

 

용어 근접데이터. 사전에서 용어를 위해, 문서에서 발생한 용어의 위치, 생략 근접데이터 정보는 존재 하지 않습니다.

 

정규화 요소. 문서의 개별 필드를 위한 값이 히트 필드에 점수로 곱해져서 저장 됩니다.

 

용어 벡터. 문서의 개별 필드에 대해, 용어벡터(문서벡터) 저장 됩니다. 용어벡터는 용어 텍스트와 용어 빈도로 구성됩니다.

 

문서 . 저장된 값과 같이 또한 문서 번호에 의해 구분 되어지며, 일반적으로 빠른 액세스를위한 메인 메모리에로드 것입니다. 저장된 값은 일반적으로 검색의 요약 결과를 구성하는 반면, 문서 값은 점수 요소 같은 것들에 유용합니다.

 

삭제된 문서. 문서 삭제 삭제 표시 옵션 입니다.

 

 

 

File Naming

모든 파일은 세그먼트에 속하며 다양한 확장자에  같은 이름을 갖습니다.

 

비록 이것이 필수 사항은 아니지만 전형적으로 인덱스의 모든 세그멘트는 단일 디렉토리에 저장됩니다.

 

버전 2.1 부터 파일 이름은 절대 재사용하지 않습니다. (segments.gen)

 

순차적인 long integer 생성 합니다.

 

 

 

Summary of File Extensions

 Name

Extension

Brief Description 

 Segments File

 segments.gen, segments_N

 커밋 포인트에 대한 정보를 저장

 Lock File

 write.lock

 write.lock  동일한 파일에 여러 IndexWriter  쓰는 것을 방지

 Segment Info

 .si

 세그먼트에 대한 메타정보를 저장

 Compound File

 .cfs, .cfe

 부가적인 가상 파일은 빈번한 파일 처리가 어려운 시스템을 위해 다른 모든 인덱스 파일을 구성한다.

 Fields

 .fnm

 필드에 대한 정보를 저장

 Field Index

 .fdx

 필드 데이터의 포인터를 포함

 Field Data

 .fdt

 문서를 위한 필드를 저장

 Term Dictionary

 .tim

 용어사전으로 용어 정보를 저장

 Term Index

 .tip

 용어 사전에서의 인덱스

 Frequencies  .doc  개별 용어사이의 빈도를 포함하고 있는 문서들의 목록을 포함
 Positions  .pos  인덱스에서 용어가 발생한 위치 정보를 저장
 Payloads  .pay  개별 위치 메타데이터 정보를 추가적으로 저장 한다. 예를 들어 문자 오프셋  사용자 페이로드를 저장한다. (색인 하는 동안 발생한 모든 용어에 대한 위치를 저장)
 Norms  .nvd, .nvm  문서와 필드에 대한 부스트 요소와 길이를 표현
 Per-Document Values  .dvd, .dvm  추가적인 스코어 요소나 개별 문서의 정보를 표현
 Term Vector Index   .tvx  문서데이터 파일에서의 오프셋 정보를 저장
 Term Vector Data (Documents)  .tvd  개별 문서들이 가지고 있는 term vector 정보를 포함
 Term Vector Fields  .tvf  term vector  대한 레벨 정보 필드
 Deleted Documents   .del
 삭제된 파일에 대한 정보
 Live Documents .liv   Segment 파일에 삭제 된 정보가 있는 경우에 생성 됩니다.
Point Values .dii, .dim 색인 된 포인트 정보를 가집니다.

 

 

:

[Algorithm] Document Weight.

Elastic/Elasticsearch 2013. 5. 15. 14:40

TD, IDF 를 이용해서 Weight 를 줄 수 있으며, 아래와 같은 수식을 사용한다.


Wij = tfij x idfj

                      # of TotalDocs

Wij = tfij x log-----------------

                          dfi

여기서 log 밑수는 10 입니다.

혹시라도 수학한지 너무 오래 되서 잊으셨을까봐.. ^^

:

[Algorithm] IDF(Inverse Document Frequency)

Elastic/Elasticsearch 2013. 5. 15. 14:32

참고 URL : http://kaistwebst.blog.me/130166255835


위 문서에 쉽게 설명이 나와 있습니다.

정리 하면, 하나의 문서 묶음(|S|)에서 어떤 단어(Wj) 가 한번 이라도 발생한 문서 수(Å)의 역수를 구하는 것입니다.


idfj  =            |S|

        log2


Term Wj 에 대한 idf 는 위와 같습니다.

그래서 TF-IDF 공식은 아래와 같습니다.



log2(1+fij) * idfj



즉, idf 값이 작게 되면 문서의 중요도가 낮다고 볼 수 있습니다.

TF-IDF 값이 클 수록 검색어에 대한 찾는 문서에 가깝다고 이해 하면 되겠습니다.

: