Gravatar for kvarley@parse3.com

Question by kvarley, Feb 4, 2015 9:56 PM

Expose external source in Sitecore

We're looking at what options we might have to integrate external content into a landing page via Coveo. The results shown would be comprised of content within Sitecore and a source using the Web connector. I've looked at :

https://developers.coveo.com/display/public/SC201410/Displaying+External+Content+in+a+Search+Interface

This seems like a good option for using the JS interface or built in Sitecore search components but we need to have pretty tight control over the UI and would prefer to perform the query logic server-side. We're aware that we could probably just go directly to the REST API but were wondering if the were any other options that might be available, ideally some way that would expose the external source through Sitecore's search provider.

Gravatar for slangevin@coveo.com

Comment by Simon, Mar 10, 2015 5:29 PM

The problem was a product issue that will be corrected in the March 2015 version of Coveo for Sitecore. The root cause was that CoveoSearchContextOptions added an OR to the query, making it search for the filed OR the entire external source

2 Replies
Gravatar for slangevin@coveo.com

Answer by Simon, Mar 10, 2015 5:29 PM

The problem was a product issue that will be corrected in the March 2015 version of Coveo for Sitecore. The root cause was that CoveoSearchContextOptions added an OR to the query, making it search for the filed OR the entire external source

Gravatar for vseguin@coveo.com

Answer by Vincent Séguin, Feb 4, 2015 10:07 PM

Hi,

If you're using the most recent version of Coveo for Sitecore, there's a little trick that can be used with LINQ queries. When creating the ProviderSearchContext just like that :

using (var context = new ContentSearchManager.GetIndex("indexname").CreateSearchContext()) { //LINQ Query }

You can cast the context into a "ICoveoSearchContext" which is available in the Coveo.SearchProviderBase dll, and then set some SearchContextOptions on it. In the SearchContextOptions, there's a property called ExternalSources which a list of string… you could add the name of your external source there.

It would go this way:

using (var context = new ContentSearchManager.GetIndex("indexname").CreateSearchContext()) 
{
      ICoveoSearchContext coveoContext = context as ICoveoSearchContext;
      coveoContext.SearchContextOptions = new CoveoSearchContextOptions { ExternalSources = new List<string>() {...}};
}
Gravatar for kvarley@parse3.com

Comment by kvarley, Feb 5, 2015 11:53 AM

Interesting. I will give that a shot and let you know where we get. Thanks.

Gravatar for kvarley@parse3.com

Comment by kvarley, Feb 8, 2015 6:23 PM

So this looks to work in terms of pulling the content in but it is not being filtered in any way by the queries we are applying to the linq expression created from the context. We are trying to achieve what is outlined in the article I linked in the initial post (filter on a field shared across a Sitecore source and an external source). However the queries I am seeing in the console look like:

Query (@fcategories44305==68cfcb6ac49348a9b6935ad2108ece8b) OR ((@syssource="Test External Site"))

I am interpreting this as it simply includes anything in the external source.

Gravatar for kvarley@parse3.com

Comment by kvarley, Feb 8, 2015 7:16 PM

This seems to work but it appears that it simply adds the source to an expression that is OR'ed on to the end of any query constructed from linq expressions created from the provider:

(@fcategories44305==68cfcb6ac49348a9b6935ad2108ece8b) OR ((@syssource="Test External Site"))

The categories field is a multilist field I have mapped to the name Categories which is the same name of a field I have added to the external source. We're basically trying to query on a field across sources, the same as what I understood was being done in the example on the Coveo site I referenced in the question.

Gravatar for kvarley@parse3.com

Comment by kvarley, Feb 9, 2015 11:44 AM

One other question I have here is whether the following section plays a role here:

Gravatar for sbelzile@coveo.com

Comment by Sébastien Belzile, Feb 9, 2015 1:18 PM

Every Sitecore field is translated in queries like this: categories -> fcategories44305. When you have a field on an external source (let's name it categories), you want the query to look like this: @categories, not like this: @fcategories44305. Fields in the externalField section of the config won't be translated like Sitecore fields while building queries.

Gravatar for kvarley@parse3.com

Comment by kvarley, Feb 9, 2015 3:25 PM

It seems like I have the fields in the queries being passed correctly now. I can run a similar query within the Coveo admin and get the desired results but I'm still running into the issue with the way the source clause is being applied above.

Gravatar for kvarley@parse3.com

Comment by kvarley, Feb 9, 2015 4:14 PM

I should add that if I remove the SearchContextOptions the query looks correct to me but does not return results from the external source. In fact the query sent to the console when I run the field query from the admin console and the query passed when I run it from a sitecore page look to be the same except for the user executing it.

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Feb 10, 2015 3:24 PM

I think Vincent's code override the existing options to set the external sources. You should use the existing options object if any and add your external source to the existing external sources if any. This code should be better suited to your needs:

Gravatar for jflheureux@coveo.com

Comment by Jean-François L'Heureux, Feb 10, 2015 3:24 PM

code:

ICoveoSearchContext coveoContext = context as ICoveoSearchContext;
CoveoSearchContextOptions options = coveoContext.SearchContextOptions;
if (options == null) {
    options = new CoveoSearchContextOptions();
    coveoContext.SearchContextOptions = options;
}
List<string> externalSources = new List<string>();
if (options.ExternalSources != null) {
    externalSources = new List<string>(options.ExternalSources);
}
externalSources.Add("YourExternalSourceName");
options.ExternalSources = externalSources;
Gravatar for kvarley@parse3.com

Comment by kvarley, Feb 12, 2015 9:12 AM

We opened a case with support on this and tried this solution but the end result was the same. My understanding is it's being escalated. I will post the resolution here when we have one. At this point we are likely going to look for a workaround using the REST API.

Gravatar for vlambert@coveo.com

Comment by vince, Feb 18, 2015 7:57 PM

As a work around, and assuming your field is not decorated anymore, you can give the RawQueryExpression a shot, if it can be used in your case. Add this line to the code:

coveoContext.SearchContextOptions.RawQueryExpression = " @categories==68cfcb6ac49348a9b6935ad2108ece8b";

The RawQueryExpression is an additional expression added to the query, and will be applied on the external sources as well. Note the starting space, to avoid concatenation issues.

Gravatar for slangevin@coveo.com

Comment by Simon, Mar 10, 2015 5:28 PM

The problem was a product issue that will be corrected in the March 2015 version of Coveo for Sitecore. The root cause was that CoveoSearchContextOptions added an OR to the query, making it search for the filed OR the entire external source

Ask a question