netgrep
1.0.0

NetGrep是使用HTTP協議在WASM上的RIPGREP的實驗移植。該項目的範圍是為具有基於小文件的數據庫的應用程序提供基於索引的搜索引擎的可行替代方案。它使用原始ripgrep存儲庫的叉子具有足夠的更改,可以使其在WASM上運行。
目前,NetGrep只是要告訴遠程文件上是否存在模式,該文件是否利用了ripgrep核心搜索引擎。在下載文件以最大程度地提高性能時,這種情況發生。
注意通過靜態站點生成器創建的博客上搜索帖子是該實驗的有趣用例。 NetGrep可以輕鬆地從RAW POST文件中創建實時搜索引擎。可以在我的博客上找到這個行為的實時示例(您可以查看源代碼)。
此刻的警告僅作為ESM導出,因此需要像WebPack這樣的捆綁包來使用它。
請注意,此簡短教程假設WebPack 5是將
netgrep集成的應用程序中使用的捆綁包。example軟件包中有一個完整的示例。
首先安裝模塊:
# Using yarn
yarn add @netgrep/netgrep
# Using npm
npm install @netgrep/netgrep在webpack.config.js中,應啟用asyncWebAssembbly實驗標誌:
module . exports = {
//...
experiments : {
// ...
asyncWebAssembly : true ,
} ,
} ;然後,可以在捆綁的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許可證。