Sonic Channel-Integration für Node. Wird zusammen mit Sonic verwendet, dem schnellen, leichten und schemalosen Such-Backend.
Mit Sonic Channel können Sie Ihren Sonic-Suchindex über Ihren NodeJS-Code verwalten. Fragen Sie Ihren Index ab und erhalten Sie Suchergebnisse, übertragen Sie Einträge in Ihren Index und platzieren Sie sie programmgesteuert.
?? Hergestellt in Nantes, Frankreich.
Knackig |
Sie nutzen Sonic-Channel und möchten dort gelistet werden? Kontaktieren Sie mich.
Fügen Sie sonic-channel
in Ihre package.json
Abhängigkeiten ein.
Alternativ können Sie npm install sonic-channel --save
ausführen.
node-sonic-channel
kann im Suchmodus wie folgt instanziiert werden:
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 ) ;
}
} ) ;
Verwenden Sie dieselbe sonicChannelSearch
Instanz, um den Suchindex abzufragen:
sonicChannelSearch . query ( "messages" , "default" , "valerian saliou" )
. then ( function ( results ) {
// Query results come there
} )
. catch ( function ( error ) {
// Query errors come there
} ) ;
Wenn Sie eine laufende Verbindung zu Sonic trennen müssen, verwenden Sie:
sonicChannelSearch . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
node-sonic-channel
kann im Ingest-Modus wie folgt instanziiert werden:
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 ) ;
}
} ) ;
Verwenden Sie dieselbe sonicChannelIngest
-Instanz, um Text an den Suchindex zu übertragen:
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
} ) ;
Wenn Sie eine laufende Verbindung zu Sonic trennen müssen, verwenden Sie:
sonicChannelIngest . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
node-sonic-channel
kann im Steuermodus wie folgt instanziiert werden:
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 ) ;
}
} ) ;
Sie können dieselbe sonicChannelControl
Instanz verwenden, um Ihren Sonic-Server zu verwalten.
Wenn Sie eine laufende Verbindung zu Sonic trennen müssen, verwenden Sie:
sonicChannelControl . close ( )
. then ( function ( ) {
// Close success handler
} )
. catch ( function ( error ) {
// Close errors come there
} ) ;
Einzelheiten zu Argumentwerten finden Sie in der Sonic Channel Protocol-Spezifikation.
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>)
Sie fragen sich, was Sonic ist? Schauen Sie sich Valeriansaliou/Sonic an.
node-sonic-channel
unterhält dauerhafte TCP-Verbindungen zu den Sonic-Netzwerkschnittstellen, die Ihre laufende Sonic-Instanz überwachen. Falls node-sonic-channel
von Sonic getrennt wird, wird er erneut versuchen, eine Verbindung herzustellen, sobald die Verbindung wieder hergestellt ist.
Sie können die Verbindungsdetails Ihrer Sonic-Instanz konfigurieren, wenn Sie node-sonic-channel
über Ihren Code initialisieren. über den Sonic-Host und -Port.