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许可证。