7

I need to search components based on keywords using core-service. and I am using the SearchQueryData class to search.

I am using below function:

public XElement GetSearchResults(string[] keywordList)
{
    var filter = new SearchQueryData { ItemTypes = new[] { ItemType.Component } };

    if (keywordList != null && keywordList.Any())
    {
        //Keyword Filtering
        var lnkKeywords = Array.ConvertAll(keywordList, t => new LinkToKeywordData { IdRef = t });
        filter.UsedKeywords = lnkKeywords;
        filter.SearchInSubtree = true;
    }

    var results = ProxyClient.GetSearchResultsXml(filter);
    return results;
}

But it supports just a single keyword. If I pass more than one Keyword to the function, it just picks the first one and ignore the others. I have read the documentation and it says "Current implementation allows only one Keyword".

So if it could not be achieved by using "SearchQueryData" class, What could be the other possible ways to achieve this?

2 Answers 2

1

You could execute the search multiple times, and process the results.

1
  • yeah, that would be the last option. Aug 20, 2014 at 14:37
1

SearchQuery uses Tridion's search underneath the covers IIRC. Which means that you should be able to use standard search with an OR operator to search by multiple values (http://docs.sdl.com/LiveContent/content/en-US/SDL%20Tridion%20full%20documentation-v1/GUID-7D469F68-6D4D-43F0-B20F-D965F3DF2A98).

The trouble is that this way, the search may return components with matching values which are not necessarily keyword fields (e.g. matching descriptions or titles), so you'll need to figure out some way to weed these out - perhaps by scanning for keyword fields within each returned component to see if they are KW fields and are the match.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.