게시일: · 수정일:

PGroonga 가이드

PGroonga의 다양한 연산자

PGroonga의 다양한 연산자 &@ : Full Text Search by keyword SELECT FROM articles WHERE ARRAY title, content &@ '첫 번째'; 단순히 입력된 문자열이 컬럼 값에 포함되는지 검사합니다. PostgreSQL의 LIK...

작성자: gymynnym

PGroonga의 다양한 연산자

&@ : Full Text Search by keyword

SELECT * FROM articles
WHERE ARRAY[title, content] &@ '첫 번째';

단순히 입력된 문자열이 컬럼 값에 포함되는지 검사합니다.
PostgreSQL의 LIKE '%keyword%'와 비슷하지만, Groonga 인덱스를 활용하므로 일반적으로 훨씬 빠릅니다.

SELECT * FROM articles
WHERE ARRAY[title, content] &@~ '첫 번째 OR 두 번째';

&@ 연산자와 유사하지만 Groonga의 쿼리 문법을 지원합니다. 따라서 AND, OR, - 연산자도 사용할 수 있습니다.

예시:

  • apple AND banana : apple과 banana 포함
  • apple OR banana : apple 또는 banana 포함
  • apple -banana : apple 포함 AND banana 제외

검색엔진 구현 시 적합한 연산자입니다.

CREATE TABLE memos (
  id integer,
  content text
);

CREATE INDEX pgroonga_content_index
ON memos USING pgroonga (content);
INSERT INTO memos VALUES (1, 'PostgreSQL is a relational database management system.');
INSERT INTO memos VALUES (2, 'Groonga is a fast full text search engine that supports all languages.');
INSERT INTO memos VALUES (3, 'PGroonga is a PostgreSQL extension that uses Groonga as index.');
INSERT INTO memos VALUES (4, 'There is groonga command.');
SELECT * FROM memos WHERE content &@* 'Mroonga is a MySQL extension taht uses Groonga';
--   id |                            content
-- -----+----------------------------------------------------------------
--    3 | PGroonga is a PostgreSQL extension that uses Groonga as index.

키워드와 유사한 단어를 포함하는지 검색합니다. 위 예제에서는 Mroonga와 PGroonga는 비슷한 단어이므로 검색 결과에 포함됩니다.

유사어 검색 또는 유사 컨텐츠 추천 기능이 필요한 경우 적합한 연산자입니다.