
NetGrep는 HTTP 프로토콜을 사용하여 WASM의 실험적인 포팅입니다. 이 프로젝트의 범위는 작은 파일 기반 데이터베이스가있는 응용 프로그램을위한 인덱스 기반 검색 엔진에 대한 실용적인 대안을 제공하는 것입니다. 원래 ripgrep 저장소의 포크를 사용하여 WASM에서 실행할 수 있도록 충분한 변경 사항 만 사용합니다.
현재 NetGrep은 ripgrep 코어 검색 엔진을 활용하는 원격 파일에 패턴이 있는지 여부를 알릴 것입니다. 성능을 극대화하기 위해 파일이 다운로드되는 동안 발생합니다.
참고 정적 사이트 생성기를 통해 생성 된 블로그에서 게시물을 검색하는 것은이 실험에 흥미로운 용도입니다. NetGrep는 원시 포스트 파일에서 실시간 검색 엔진을 만들기 위해 쉽게 사용될 수 있습니다. 이 동작의 실시간 예는 내 블로그에서 찾을 수 있습니다 (소스 코드를 살펴볼 수 있음).
경고 현재이 라이브러리는 ESM으로만 내보내므로 WebPack과 같은 번들이 사용해야합니다.
이 짧은 튜토리얼은 Webpack 5 가
netgrep통합 될 애플리케이션에 사용 된 번들러라고 가정 합니다.example패키지에서 전체 예제를 사용할 수 있습니다.
우선 모듈 설치 :
# Using yarn
yarn add @netgrep/netgrep
# Using npm
npm install @netgrep/netgrep asyncWebAssembbly 실험 플래그는 webpack.config.js 내부에서 활성화되어야합니다.
module . exports = {
//...
experiments : {
// ...
asyncWebAssembly : true ,
} ,
} ; 그런 다음 Bundled WASM 파일이 백그라운드에서 비동기 적으로로드되는 동안 netgrep 직접 실행할 수 있습니다.
import { Netgrep } from '@netgrep/netgrep' ;
// Create a Netgrep instance, here it's
// possible to pass an initial configuration.
const NG = new Netgrep ( ) ;
// Execute a Netgrep search on the url using
// the given pattern.
NG . search ( "url" , "pattern" )
. then ( ( output ) => {
console . log ( 'The pattern has matched' , output . result )
} ) ;
// It's possible to pass custom metadata during
// the search. These will be returned back in the result
// for convenience.
NG . search ( "url" , "pattern" , { post } )
. then ( ( output ) => {
console . log ( 'The pattern has matched' , output . result )
console . log ( 'Metadata' , output . metadata )
} ) ;
// There is a convenient method to do batched searches
// to multiple urls. Using `searchBatch` the resulting `Promise`
// will resolve only after the completion of all the searches.
NG . searchBatch ( [
{ url : 'url1' } ,
{ url : 'url2' } ,
{ url : 'url3' }
] , "pattern" )
. then ( ( outputs ) => {
outputs . forEach ( ( output ) => {
console . log ( `The pattern has matched for ${ output . url } ` , output . result )
} ) ;
} ) ;
// If you want to avoid waiting for the completion of
// all the searches, the method `searchBatchWithCallback` will
// execute a callback every time a search completes.
NG . searchBatchWithCallback ( [
{ url : 'url1' } ,
{ url : 'url2' } ,
{ url : 'url3' }
] , "pattern" , ( output ) => {
console . log ( `The pattern has matched for ${ output . url } ` , output . result )
} ) ; NetGrep는 MIT 라이센스에 따라 있습니다.