Gravatar for hussaindotnet@gmail.com

Question by Hussain Shaik, Mar 2, 2017 4:14 AM

get results by multiple queries

I want get the results by sending multiple queries to JS framework.

Example : i want to get the results from "text1" or/and from "text2"

I am using the below query expression

 var queryBuilder = new Coveo.QueryBuilder();
 queryBuilder.expression.add('text1');
 queryBuilder.expression.add('text2');

Any help here?

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Mar 2, 2017 7:49 AM

I don't quite understand your question, how is it different from getting search results directly by sending query?

Can you not call the endpoint multiple times?

var endpoint = Coveo.SearchEndpoint.endpoints['default'];

var queryBuilder = new Coveo.QueryBuilder(); 
queryBuilder.expression.add('text1');

endpoint.search(queryBuilder.build()).then(function(data) { 
   // you can iterate on data.results here;
});

var anotherQuery = new Coveo.QueryBuilder();
anotherQuery.expression.add('text2');

endpoint.search(anotherQuery.build()).then(function(data) { 
   // you can iterate on data.results here;
});
Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Mar 2, 2017 8:37 AM

Thanks for the reply. Here as you mentioned , do we need to call multiple time calls instead of one call with query "text1" OR "text2" ?

Gravatar for flguillemette@coveo.com

Comment by François Lachance-Guillemette, Mar 2, 2017 9:37 AM

If you call queryBuilder.build() you will get the return and see what is sent.

var queryBuilder = new Coveo.QueryBuilder(); 
queryBuilder.expression.add('text1');
queryBuilder.expression.add('text2');
var query = queryBuilder.build();

query here returns { ..., q:"(text1) (text2)", ... }, so the query will be "text1" AND "text2".

Please refer to the query syntax to understand what kind of queries you can do.

Gravatar for hussaindotnet@gmail.com

Comment by Hussain Shaik, Mar 3, 2017 1:18 AM

Thank you.. It works !!!

1 Reply
Gravatar for jflheureux@coveo.com

Answer by Jean-François L'Heureux, Mar 2, 2017 11:04 AM

To get a text1 OR text2 query, you need to build you query like this:

var queryBuilder = new Coveo.QueryBuilder(); 
queryBuilder.expression.add('text1 OR text2');
var query = queryBuilder.build();
Ask a question