1

I'm attempting to export all query rules for a provided URL to a csv file via PowerShell. I have this working about 80%, the last piece I need is to find the keywords or terms that actually trigger the query rule. Through Microsoft.Office.Server.Search.Query.Rules.QueryRuleManager I can collect the query rule title, any promoted results, publication info (start date, end date, etc) but I can't seem to return the triggering keywords. The only related property I can seem to find is "QueryConditions" which tells me the rule is fired via keyword but not what they are. Is there another reference or something else I am missing?

Any help or insight appreciated.

1 Answer 1

1

Try casting the QueryCondition items from QueryConditions (which really is ends up being an IEnumerable<QueryCondition>) to KeywordCondition objects. From what I can tell, the collection is just a bunch of objects that report as the superclass, and you need to cast them to the specific class to actually access the properties that make them unique. I say this because the inheritance hierarchy of a KeywordCondition is:

System.Object
  Microsoft.Office.Server.Search.Query.Rules.QueryCondition
    Microsoft.Office.Server.Search.Query.Rules.KeywordCondition

See http://msdn.microsoft.com/en-us/library/microsoft.office.server.search.query.rules.keywordcondition%28v=office.15%29.aspx for information about the inheritance.

The KeywordCondition type has a Terms property (see http://msdn.microsoft.com/en-us/library/microsoft.office.server.search.query.rules.keywordcondition_properties%28v=office.15%29.aspx for a full list) which is an IEnumberable<String> and which should list all the strings that trigger the query condition.

3
  • Welcome to SharePoint StackExchange! If you could give an example, it would improve your answer a lot. We try to discourage answers that are primarily just links as even MSDN links have been know to go disappear. Commented Mar 7, 2014 at 1:51
  • Thanks for helping. I moved more information into the post so it should stand on its own without needing to read the links. Commented Mar 7, 2014 at 6:36
  • Thanks for the insight! I was finally able to get this figured out and access the terms by using '$rule.QueryConditions.Terms' even though msdn does not list Terms as a property of the QueryConditions class. Commented Mar 11, 2014 at 20:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.