How to sort search results from a GlideRecord Query based on Relevancy?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-16-2016 01:29 AM
Consider that my Task table has 10 records(Task type is not relevant).
Record #1: Short Description = "Hello bla bla bla World";
Record #2: Doesn't contain neither "Hello" nor "World"
Record #3: Short Description = "HELLO WORLD";
Record #4: Doesn't contain neither "Hello" nor "World"
Record #5: Description = "World";
Record #6: Doesn't contain neither "Hello" nor "World"
Record #7: Description = "Hello bla bla bla World";
Record #8: Doesn't contain neither "Hello" nor "World"
Record #9: Short Description = "Hello";
Record #10: Description = "World Hello";
Consider the following GlideRecord query,
var t = new GlideRecord('task')
t.addQuery('IR_AND_OR_QUERY','HELLO WORLD');
t.query();
while(t.next()){
gs.print(t.number);
}
The Results returned would be something like,
***Script: Record#1
***Script: Record#3
***Script: Record#5
***Script: Record#7
***Script: Record#9
***Script: Record#10
Now,
What do I do --> in the sense --> what orderBy query can I add to the GlideRecord query so that the Results returned are the most relevant Records? I want Record#3 to be my 1st Result.
Like,
var t = new GlideRecord('task')
t.addQuery('IR_AND_OR_QUERY','HELLO WORLD');
t.orderBy('relevance') --> What should this query be exactly --> Something like this is being done in Knowledge Searches I believe.
t.query();
while(t.next()){
gs.print(t.number);
}
Please assist!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 03:25 AM
Please clarify where you want to use it exactly , Knowledge or any other module?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-18-2016 06:27 AM
On my CMS to query on a Custom Table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-10-2016 05:46 AM
Hi Aswin
var t = new GlideRecord('task');
t.orderBy('relevance');
t.addQuery('IR_AND_OR_QUERY','HELLO WORLD');
t.query();
while(t.next()){
gs.print(t.number);
}
Try using the orderBy() befoe the addQuery()
You can refer to Scoped GlideRecord API Reference - ServiceNow Wiki