Integración de Sonic Channel para Node. Se utiliza junto con Sonic, el backend de búsqueda rápido, liviano y sin esquemas.
Sonic Channel te permite administrar tu índice de búsqueda de Sonic, desde tu código NodeJS. Consulte su índice y obtenga resultados de búsqueda, envíe entradas a su índice y extráigalas mediante programación.
?? Elaborado en Nantes, Francia.
Crujiente |
¿Utilizas Sonic-Channel y quieres aparecer allí? Contáctame.
Incluya sonic-channel
en sus dependencias de package.json
.
Alternativamente, puedes ejecutar npm install sonic-channel --save
.
node-sonic-channel
se puede instanciar en modo de búsqueda como tal:
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 ) ;
}
} ) ;
Utilice la misma instancia sonicChannelSearch
para consultar el índice de búsqueda:
sonicChannelSearch . query ( "messages" , "default" , "valerian saliou" )
. then ( function ( results ) {
// Query results come there
} )
. catch ( function ( error ) {
// Query errors come there
} ) ;
Si necesita desconectar una conexión en curso con Sonic, utilice:
sonicChannelSearch . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
node-sonic-channel
se puede instanciar en modo de ingesta como tal:
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 ) ;
}
} ) ;
Utilice la misma instancia sonicChannelIngest
para enviar texto al índice de búsqueda:
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
} ) ;
Si necesita desconectar una conexión en curso con Sonic, utilice:
sonicChannelIngest . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
node-sonic-channel
se puede instanciar en modo de control como tal:
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 ) ;
}
} ) ;
Puede utilizar la misma instancia sonicChannelControl
para administrar su servidor Sonic.
Si necesita desconectar una conexión en curso con Sonic, utilice:
sonicChannelControl . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
Para obtener detalles sobre los valores de los argumentos, consulte la especificación del protocolo Sonic Channel.
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>)
¿Te preguntas qué es Sonic? Echa un vistazo a valeriansaliou/sonic .
node-sonic-channel
mantiene conexiones TCP persistentes a las interfaces de red de Sonic que están escuchando en su instancia de Sonic en ejecución. En caso de que node-sonic-channel
se desconecte de Sonic, volverá a intentar conectarse una vez que se establezca nuevamente la conexión.
Puede configurar los detalles de conexión de su instancia de Sonic al inicializar node-sonic-channel
desde su código; a través del host y el puerto de Sonic.