Integrasi Saluran Sonic untuk Node.js Digunakan bersama Sonic, backend pencarian yang cepat, ringan, dan tanpa skema.
Sonic Channel memungkinkan Anda mengelola indeks pencarian Sonic, dari kode NodeJS Anda. Kueri indeks Anda dan dapatkan hasil pencarian, dorong entri ke indeks Anda dan masukkan secara terprogram.
?? Dibuat di Nantes, Prancis.
Garing |
Anda menggunakan saluran sonik dan ingin terdaftar di sana? Hubungi saya.
Sertakan sonic-channel
dalam dependensi package.json
Anda.
Alternatifnya, Anda dapat menjalankan npm install sonic-channel --save
.
node-sonic-channel
dapat dipakai dalam mode pencarian seperti:
var SonicChannelSearch = require ( "sonic-channel" ) . Search ;
var sonicChannelSearch = new SonicChannelSearch ( {
host : "::1" , // Or '127.0.0.1' if you are still using IPv4
port : 1491 , // Default port is '1491'
auth : "SecretPassword" // Authentication password (if any)
} ) . connect ( {
connected : function ( ) {
// Connected handler
console . info ( "Sonic Channel succeeded to connect to host (search)." ) ;
} ,
disconnected : function ( ) {
// Disconnected handler
console . error ( "Sonic Channel is now disconnected (search)." ) ;
} ,
timeout : function ( ) {
// Timeout handler
console . error ( "Sonic Channel connection timed out (search)." ) ;
} ,
retrying : function ( ) {
// Retry handler
console . error ( "Trying to reconnect to Sonic Channel (search)..." ) ;
} ,
error : function ( error ) {
// Failure handler
console . error ( "Sonic Channel failed to connect to host (search)." , error ) ;
}
} ) ;
Gunakan instance sonicChannelSearch
yang sama untuk menanyakan indeks pencarian:
sonicChannelSearch . query ( "messages" , "default" , "valerian saliou" )
. then ( function ( results ) {
// Query results come there
} )
. catch ( function ( error ) {
// Query errors come there
} ) ;
Jika Anda perlu memutuskan koneksi yang sedang berlangsung ke Sonic, gunakan:
sonicChannelSearch . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
node-sonic-channel
dapat dipakai dalam mode penyerapan seperti:
var SonicChannelIngest = require ( "sonic-channel" ) . Ingest ;
var sonicChannelIngest = new SonicChannelIngest ( {
host : "::1" , // Or '127.0.0.1' if you are still using IPv4
port : 1491 , // Default port is '1491'
auth : "SecretPassword" // Authentication password (if any)
} ) . connect ( {
connected : function ( ) {
// Connected handler
console . info ( "Sonic Channel succeeded to connect to host (ingest)." ) ;
} ,
disconnected : function ( ) {
// Disconnected handler
console . error ( "Sonic Channel is now disconnected (ingest)." ) ;
} ,
timeout : function ( ) {
// Timeout handler
console . error ( "Sonic Channel connection timed out (ingest)." ) ;
} ,
retrying : function ( ) {
// Retry handler
console . error ( "Trying to reconnect to Sonic Channel (ingest)..." ) ;
} ,
error : function ( error ) {
// Failure handler
console . error ( "Sonic Channel failed to connect to host (ingest)." , error ) ;
}
} ) ;
Gunakan instance sonicChannelIngest
yang sama untuk memasukkan teks ke indeks pencarian:
sonicChannelIngest . push ( "messages" , "default" , "conversation:1" , "I met Valerian Saliou yesterday. Great fun!" )
. then ( function ( ) {
// Push success handler
} )
. catch ( function ( error ) {
// Push errors come there
} ) ;
Jika Anda perlu memutuskan koneksi yang sedang berlangsung ke Sonic, gunakan:
sonicChannelIngest . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
node-sonic-channel
dapat dipakai dalam mode kontrol seperti:
var SonicChannelControl = require ( "sonic-channel" ) . Control ;
var sonicChannelControl = new SonicChannelControl ( {
host : "::1" , // Or '127.0.0.1' if you are still using IPv4
port : 1491 , // Default port is '1491'
auth : "SecretPassword" // Authentication password (if any)
} ) . connect ( {
connected : function ( ) {
// Connected handler
console . info ( "Sonic Channel succeeded to connect to host (control)." ) ;
} ,
disconnected : function ( ) {
// Disconnected handler
console . error ( "Sonic Channel is now disconnected (control)." ) ;
} ,
timeout : function ( ) {
// Timeout handler
console . error ( "Sonic Channel connection timed out (control)." ) ;
} ,
retrying : function ( ) {
// Retry handler
console . error ( "Trying to reconnect to Sonic Channel (control)..." ) ;
} ,
error : function ( error ) {
// Failure handler
console . error ( "Sonic Channel failed to connect to host (control)." , error ) ;
}
} ) ;
Anda dapat menggunakan instance sonicChannelControl
yang sama untuk mengatur server Sonic Anda.
Jika Anda perlu memutuskan koneksi yang sedang berlangsung ke Sonic, gunakan:
sonicChannelControl . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
Untuk detail tentang nilai argumen, lihat spesifikasi Sonic Channel Protocol.
sonicChannelSearch.query(collection_id<string>, bucket_id<string>, terms_text<string>, [options{limit<number>, offset<number>, lang<string>}<object>]?)
➡️ Promise(results<object>, error<object>)
sonicChannelSearch.suggest(collection_id<string>, bucket_id<string>, word_text<string>, [options{limit<number>}<object>]?)
➡️ Promise(results<object>, error<object>)
sonicChannelSearch.list(collection_id<string>, bucket_id<string>, [options{limit<number>, offset<number>}<object>]?)
➡️ Promise(results<object>, error<object>)
sonicChannelIngest.push(collection_id<string>, bucket_id<string>, object_id<string>, text<string>, [options{lang<string>}<object>]?)
➡️ Promise(_, error<object>)
sonicChannelIngest.pop(collection_id<string>, bucket_id<string>, object_id<string>, text<string>)
➡️ Promise(count<number>, error<object>)
sonicChannelIngest.count<number>(collection_id<string>, [bucket_id<string>]?, [object_id<string>]?)
➡️ Promise(count<number>, error<object>)
sonicChannelIngest.flushc(collection_id<string>)
➡️ Promise(count<number>, error<object>)
sonicChannelIngest.flushb(collection_id<string>, bucket_id<string>)
➡️ Promise(count<number>, error<object>)
sonicChannelIngest.flusho(collection_id<string>, bucket_id<string>, object_id<string>)
➡️ Promise(count<number>, error<object>)
sonicChannelControl.trigger(action<string>, [data<string>]?)
➡️ Promise(_, error<object>)
sonicChannelControl.info()
➡️ Promise(results<object>, error<object>)
Ingin tahu apa itu Sonic? Lihat valeriansaliou/sonic .
node-sonic-channel
mempertahankan koneksi TCP yang persisten ke antarmuka jaringan Sonic yang mendengarkan instance Sonic Anda yang sedang berjalan. Jika node-sonic-channel
terputus dari Sonic, ia akan mencoba menyambung kembali setelah sambungan dibuat kembali.
Anda dapat mengonfigurasi detail koneksi instance Sonic Anda saat menginisialisasi node-sonic-channel
dari kode Anda; melalui host dan port Sonic.