Gravatar for hussaindotnet@gmail.com

Question by Hussain Shaik, Feb 25, 2017 11:01 AM

How to get top search text or trending search text through JS framework

I am using coveo cloud with sitecore 8.2 .

I need top search queries/text by using JS framework. i am not using any coveo component here. Any guidance here?

i am getting the query results by using JS

Coveo.SearchEndpoint.endpoints["default"].search(coveoQuery).done(function (data) {

    });
Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Feb 25, 2017 2:48 PM

Top Search and queries are logged in the usage analytics service and can be fetched using its API.

What is your use case? What do you want to do with this information?

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 26, 2017 7:32 AM

i want to show them those queries in our application as a clickable. Any references?

1 Reply
Gravatar for olamothe@coveo.com

Answer by olamothe, Feb 27, 2017 9:33 AM

var analyticsDiv = document.querySelector('.CoveoAnalytics');
var analyticsInstance = Coveo.get(analyticsDiv);
analyticsInstance.client.getTopQueries({queryText: 'test', pageSize: 5}).then(function(results){
    console.log(results);
})

See : https://coveo.github.io/search-ui/components/analytics.html and https://coveo.github.io/search-ui/interfaces/ianalyticsclient.html

Or you can also call the API directly : https://usageanalytics.coveo.com/docs/#!/v15%2Fstats%2F/getTopQueriesByFrequency

GET https://usageanalytics.coveo.com/rest/v15/stats/topQueries?queryText=test

Header : Authorization Bearer (API Key/Search token)

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 27, 2017 9:35 AM

i am not using any coveo component. I am using only JS framework.

Gravatar for olamothe@coveo.com

Comment by olamothe, Feb 27, 2017 9:36 AM

Yes. That's why im giving you an answer using the JS framework.

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 28, 2017 1:44 AM

We are capturing all search text in coveo cloud and we wanted to get those text/top queries from cloud by using JS framework. I am using only JS and not binding to any text box.

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Feb 28, 2017 9:59 AM

In your initial response, Coveo.SearchEndpoint.endpoints["default"] is used, which means you are using the coveo-search-ui framework, so this response is perfect for you.

Do you mean you are only using the static classes and not leveraging coveo-search-ui's Coveo.init? Do you have a CoveoSearchInterface in your page?

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Feb 28, 2017 11:25 AM

I don't have any CoveoSearchInterface in my page. I am just getting the results by using searchenpoint. After successful query , i am sending the search event to coveo cloud. I am able to get the search text in coveo cloud.

Now i wanted to get those search text from cloud by using coveo analytics API. I need some reference here.

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Feb 28, 2017 1:12 PM

You should add a div with the <div class="CoveoAnalytics"> tag within the div with the CoveoSearchInterface class and use the code from the original response.

If you don't want to do that, call the API directly using your own caller with the URL from the original response.

You could also look around the open-source code of the coveo-search-ui and find what you need.

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Mar 2, 2017 5:25 AM

https://answers.coveo.com/questions/5669/trendingmost-popular-search-results

this link helps me…

Ask a question