{"id":25196048,"url":"https://github.com/ddochea0314/example-postgres-text-search-types","last_synced_at":"2026-05-05T07:31:46.830Z","repository":{"id":180294446,"uuid":"664894943","full_name":"ddochea0314/example-postgres-text-search-types","owner":"ddochea0314","description":"본 프로젝트는 postgres 문자열 검색 기능 사용을 위한 tsvector, tsquery 의 간략한 사용예시를 다룹니다.","archived":false,"fork":false,"pushed_at":"2023-07-15T08:47:22.000Z","size":386,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-04T15:52:47.250Z","etag":null,"topics":["example","postgres","postgresql","tsquery","tsvector"],"latest_commit_sha":null,"homepage":"https://ddochea.tistory.com/235","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ddochea0314.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-07-11T02:01:12.000Z","updated_at":"2023-07-11T02:40:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"a5698ff6-e5d2-47b9-b749-2712bbd9b6df","html_url":"https://github.com/ddochea0314/example-postgres-text-search-types","commit_stats":null,"previous_names":["ddochea0314/example-postgres-text-search-types"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ddochea0314/example-postgres-text-search-types","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddochea0314%2Fexample-postgres-text-search-types","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddochea0314%2Fexample-postgres-text-search-types/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddochea0314%2Fexample-postgres-text-search-types/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddochea0314%2Fexample-postgres-text-search-types/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ddochea0314","download_url":"https://codeload.github.com/ddochea0314/example-postgres-text-search-types/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ddochea0314%2Fexample-postgres-text-search-types/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32640533,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-04T10:08:07.713Z","status":"online","status_checked_at":"2026-05-05T02:00:06.033Z","response_time":54,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["example","postgres","postgresql","tsquery","tsvector"],"created_at":"2025-02-10T01:39:43.861Z","updated_at":"2026-05-05T07:31:46.818Z","avatar_url":"https://github.com/ddochea0314.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# example-postgres-text-search-types\n\n본 프로젝트는 postgres 문자열 검색 기능 사용을 위한 `tsvector`, `tsquery` 의 간략한 사용예시를 다룹니다.\n\n# 데이터 초기 구축하기\n\n아래 순서에 따라 데이터를 구축합니다.\n\u003e 일부 환경에 따라 관리자 권한으로 실행해야할 수 있습니다. (sudo su)\n\n## 1. npm 인스톨 명령어 실행\n\n```\nnpm i\n```\n\n## 2. env 설정\n\ndb 접속 정보를 설정합니다. example 파일값을 토대로 `.env` 파일을 수정하세요.\n\n```\ncp .env.example .env\n```\n\n## 3. 데이터 insert 처리\n\n아래 명령어로 데이터를 db에 구축하는 스크립트를 실행합니다.\n```\nnpx ts-node script.ts\n```\n\n# tsquery 연산자 종류\n\n- AND(\u0026) : \u0026 사이에 속한 조건들이 모두 부합한 대상을 필터링 합니다. 예를 들어 `세종특별시 \u0026 호려울로` 로 조회하면 `세종특별시` 와 `호려울로`가 모두 포함되어 있는 tsvector 값으로 필터링합니다.\n- OR(|) : | 사이에 속한 조건들 중 1개라도 부합하면 됩니다. 예를 들어 `호려울로 | 대평로` 로 조회하면, `호려울로` 와 `대평로`가ㅣ 모두 포함되어 있는 tsvector 값으로 필터링합니다.\n- NOT(!) : 단어 앞에 붙이며, 해당 조건에 부합하지 않는 항목을 대상으로 조회합니다. 예를 들어 `!대평시장` 의 결과 값은 `대평시장`을 포함하지 않습니다.\n- FOLLOWED BY(\u003c-\u003e) : 앞 뒤 단어의 순서 일치여부를 따집니다. 예를 들어 `세종특별시 \u003c-\u003e 호려울로` 로 조회하면 `세종특별시` 다음에 `호려울로` 순으로 정의된 tsvector 값을 필터링합니다.\n\n# AND(\u0026) 와 FOLLOWED BY(\u003c-\u003e) 차이점\n\n`세종특별시 \u0026 호려울로` 와 `호려울로 \u0026 세종특별시` 는 같은 결과가 조회됩니다.\n`세종특별시 \u003c-\u003e 호려울로` 와 `호려울로 \u003c-\u003e 세종특별시` 는 조회 결과가 다릅니다.\n\n# 조회 예시\n\n```\nSELECT rnaddrkor.\"road_address_id\", \n  rnaddrkor.\"city_name\", \n  rnaddrkor.\"district_name\", \n  rnaddrkor.\"road_name\"\nFROM rnaddrkor\nWHERE to_tsvector('simple', rnaddrkor.\"city_name\" || ' ' \n||  rnaddrkor.\"district_name\" || ' ' \n|| rnaddrkor.\"road_name\") @@ to_tsquery('세종:* \u0026 (호려울로 | 대평:*) \u0026 !대평시장:*')\n```\n\n# 예시 결과\n\n|    | road_address_id character varying | city_name character varying | district_name character varying | road_name character varying |\n|:--:|:---------------------------------:|:---------------------------:|:-------------------------------:|:---------------------------:|\n|  1 | 36110103335079400000900000        | 세종특별자치시              |                                 | 호려울로                    |\n|  2 | 36110103335079400001900000        | 세종특별자치시              |                                 | 호려울로                    |\n|  3 | 36110103335079400002900000        | 세종특별자치시              |                                 | 호려울로                    |\n|  4 | 36110103335079400004200000        | 세종특별자치시              |                                 | 호려울로                    |\n|  5 | 36110103335079400004500000        | 세종특별자치시              |                                 | 호려울로                    |\n|  6 | 36110103335079400005100000        | 세종특별자치시              |                                 | 호려울로                    |\n|  7 | 36110104335079500000300000        | 세종특별자치시              |                                 | 대평로                      |\n|  8 | 36110104335079500002700000        | 세종특별자치시              |                                 | 대평로                      |\n|  9 | 36110104335079500003400000        | 세종특별자치시              |                                 | 대평로                      |\n| 10 | 36110104335079500005600000        | 세종특별자치시              |                                 | 대평로                      |\n| 11 | 36110104335079500007100000        | 세종특별자치시              |                                 | 대평로                      |\n| 12 | 36110104335079500007500000        | 세종특별자치시              |                                 | 대평로                      |\n| 13 | 36110104335079500008000000        | 세종특별자치시              |                                 | 대평로                      |\n| 14 | 36110104335079500008300000        | 세종특별자치시              |                                 | 대평로                      |\n| 15 | 36110104335079500008600000        | 세종특별자치시              |                                 | 대평로                      |\n| 16 | 36110104335079500008700000        | 세종특별자치시              |                                 | 대평로                      |\n| 17 | 36110104485319100001000000        | 세종특별자치시              |                                 | 대평1길                     |\n| 18 | 36110104485319100001700000        | 세종특별자치시              |                                 | 대평1길                     |\n| 19 | 36110104485319100001900000        | 세종특별자치시              |                                 | 대평1길                     |\n| 20 | 36110104485319100002200000        | 세종특별자치시              |                                 | 대평1길                     |\n| 21 | 36110104485319100002700000        | 세종특별자치시              |                                 | 대평1길                     |\n| 22 | 36110104485319100003700000        | 세종특별자치시              |                                 | 대평1길                     |\n| 23 | 36110104485319100003800000        | 세종특별자치시              |                                 | 대평1길                     |\n| 24 | 36110104485319300001000000        | 세종특별자치시              |                                 | 대평3길                     |\n| 25 | 36110104485319300001700000        | 세종특별자치시              |                                 | 대평3길                     |\n| 26 | 36110104485319300001800000        | 세종특별자치시              |                                 | 대평3길                     |\n| 27 | 36110104485510800001700000        | 세종특별자치시              |                                 | 대평4길                     |\n| 28 | 36110104485510800003300000        | 세종특별자치시              |                                 | 대평4길                     |\n\n\n# 참조\n\nhttps://www.postgresql.org/docs/current/datatype-textsearch.html\nhttps://www.postgresql.org/docs/current/textsearch-intro.html#TEXTSEARCH-DOCUMENT","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddochea0314%2Fexample-postgres-text-search-types","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fddochea0314%2Fexample-postgres-text-search-types","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fddochea0314%2Fexample-postgres-text-search-types/lists"}