How to use the Zing search engine in a script?

th00011
Kilo Contributor

Does anyone know how to use the Zing search engine in a script ? I would like to create some specific searches on knowledge.
Full text search can be done quite easily using the sample script below, but I would like to use the ranking abilities of Zing.
Tom

var item = new GlideRecord('kb_knowledge');
var search = 'laptop';
if (search.length != 0) {
item.addQuery('123TEXTQUERY321', search);
}
item.addQuery('active', 'true');
item.query();
while (item.next()) {
gs.log(item.number + ' - ' + item.short_description);
}

3 REPLIES 3

j_martin
Tera Guru

Hey Tom,



I ran into a similar question, did you ever find an answer to this?


johndewhurst
Kilo Explorer

Hi,


I have also a need for this functionality, I have a requirement that we should be able to order by ranking/relevancy on a custom knowledge search, anyone any ideas?


Hello All,



If I understand what you guys are looking for, you are already on the right track with your GlideRecord query set up.   The one remaining piece is the ir_query_score field that is added to every retrieved record.   For example, the following will search Catalog Items for the term 'Application' and they will be sorted by strongest score to weakest automatically:



var gr = new GlideRecord('sc_cat_item');


gr.addQuery('123TEXTQUERY321', 'Application');


gr.query();



while (gr.next()) {


  gs.print(gr.name + ': ' + gr.ir_query_score);


}