I’ve been working peripherally with Coveo for the past couple years now. It hasn’t been until recently that I’ve actually needed to start diving into the “API” to try and harvest the data. This, however, proved to be more difficult than one would expect from a Search product!
You see, Coveo wrote a lot of fancy controls (complete with AJAXy functions) that work intimately with their index. They have an “interface editor” that is supposed to help you customize the way these controls function and look. In a perfect world you will tailor your interface using this editor, drop a single user control on your page and you are up and running. However, there are times when these stock controls just don’t cut it; you will either want to change the look, or function, to drastically to be handled with the interface editor. I found myself in such a position.
Coveo lists a few APIs in its online help section (Search Interface API, Converter API, Connector API, and Security API), but none of them tell you how to get access to the raw data!
Before Coveo I was using Lucene for various projects and it had a decent API that you can use to get access to your search results. You were then responsible for rendering these results. This is what I would have expected in terms of an API from Coveo. The Coveo Search Interface API is nothing more than a collection of the aforementioned ASP.NET controls that you can try to use in your Interface. I wasn’t able to find any samples about how to get my data with some API calls, there was however, some MSDN style class documentation.
After some playing around I was able to perform a search using the following code. You need to specify the Collection ID you want to search on as well as the Query to perform. The results will then be populated into the resultArray object. There are many parameters you can set on the SearchBuilder object, which you can read about in the doc. This code will be used in an upcoming post about how to write an autocomplete text box with jQuery and Coveo.
ICESSearchProvider provider = SearchUtilities.CreateDefaultSearchProvider();
SearchBuilder builder = new SearchBuilder();
builder.AddCollection(1234); // add your collection id here
builder.Provider = provider;
builder.ExpandQuery = true;
builder.RetrieveFirstSentences = false;
builder.ExcerptSize = 0;
builder.FilterDuplicates = true;
builder.AddBasicEx pres sion("Search for Me");
QueryWrapper newQueryWrapper = QueryWrapperFactory.GetNewQueryWrapper(builder);
int totalResults = newQueryWrapper.TotalCount;
ICESResult resultArray = newQueryWrapper.GetResults(0, 100);