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?

1

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

| improve this answer | |
  • yeah, that would be the last option. – Saurabh Gangwar Aug 20 '14 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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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