Searching and filtering via the CRM SDK does take some time to get used to. In order to simulate full text search, you need to use nested FilterExpressions as your QueryExpression. Criteria SDK page for nested filters The hardest part is figuring out how to build the parent child relationships.
There's so much boolean logic going on that it's easy to get lost I had a requirement to build a "search engine" for one of our custom entities. Using this method for a complex search string ("one AND two OR three") with multiple searchable attributes was ugly. If you're interested though, I can dig it up.
While it's not really supported, if you can access the database directly, I would suggest using SQL's full text search capabilities ok, here you go. I don't think you'll be able to copy paste this and fulfill your needs. My customer was only doing two to three key word searches and they were happy with the results from this.
You can see what a pain it is to just do this in a simple search scenario. I basically puked out code until it was 'working private FilterExpression BuildFilterV2(string words, string seachAttributes) { FilterExpression filter = new FilterExpression(); List allchildfilters = new List(); List andbucket = new List(); List orBucket = new List(); // clean up commas, quotes, etc words = ScrubWords(words); int index = 0; while (index 0) { List filters = new List(); foreach (string s in andbucket) { filters. Add(BuildSingleWordFilter(s, seachAttributes)); } // send existing and bucket to condition builder FilterExpression childFilter = new FilterExpression(); childFilter.
FilterOperator = LogicalOperator. And; childFilter. Filters = filters.ToArray(); // add to child filter list allchildfilters.
Add(childFilter); //new 'and' bucket andbucket = new List(); } if (index + 1 0) { List filters = new List(); foreach (string s in andbucket) { filters. Add(BuildSingleWordFilter(s, seachAttributes)); } // send existing and bucket to condition builder FilterExpression childFilter = new FilterExpression(); childFilter. FilterOperator = LogicalOperator.
And; childFilter. Filters = filters.ToArray(); // add to child filter list allchildfilters. Add(childFilter); //new 'and' bucket andbucket = new List(); } if (orBucket.
Count > 0) { filter. Conditions = BuildConditions(orBucket.ToArray(), seachAttributes); } filter. FilterOperator = LogicalOperator.
Or; filter. Filters = allchildfilters.ToArray(); return filter; } private FilterExpression BuildSingleWordFilter(string word, string seachAttributes) { List conditions = new List(); foreach (string attr in seachAttributes) { ConditionExpression expr = new ConditionExpression(); expr. AttributeName = attr; expr.
Operator = ConditionOperator. Like; expr. Values = new string { "%" + word + "%" }; conditions.
Add(expr); } FilterExpression filter = new FilterExpression(); filter. FilterOperator = LogicalOperator. Or; filter.
Conditions = conditions.ToArray(); return filter; } private ConditionExpression BuildConditions(string words, string seachAttributes) { List conditions = new List(); foreach (string s in words) { foreach (string attr in seachAttributes) { ConditionExpression expr = new ConditionExpression(); expr. AttributeName = attr; expr. Operator = ConditionOperator.
Like; expr. Values = new string { "%" + s + "%" }; conditions. Add(expr); } } return conditions.ToArray(); }.
Searching and filtering via the CRM SDK does take some time to get used to. In order to simulate full text search, you need to use nested FilterExpressions as your QueryExpression.Criteria. SDK page for nested filters The hardest part is figuring out how to build the parent child relationships.
There's so much boolean logic going on that it's easy to get lost. I had a requirement to build a "search engine" for one of our custom entities. Using this method for a complex search string ("one AND two OR three") with multiple searchable attributes was ugly.
If you're interested though, I can dig it up. While it's not really supported, if you can access the database directly, I would suggest using SQL's full text search capabilities. -- ok, here you go.
I don't think you'll be able to copy paste this and fulfill your needs. My customer was only doing two to three key word searches and they were happy with the results from this. You can see what a pain it is to just do this in a simple search scenario.
I basically puked out code until it was 'working'. Private FilterExpression BuildFilterV2(string words, string seachAttributes) { FilterExpression filter = new FilterExpression(); List allchildfilters = new List(); List andbucket = new List(); List orBucket = new List(); // clean up commas, quotes, etc words = ScrubWords(words); int index = 0; while (index 0) { List filters = new List(); foreach (string s in andbucket) { filters. Add(BuildSingleWordFilter(s, seachAttributes)); } // send existing and bucket to condition builder FilterExpression childFilter = new FilterExpression(); childFilter.
FilterOperator = LogicalOperator. And; childFilter. Filters = filters.ToArray(); // add to child filter list allchildfilters.
Add(childFilter); //new 'and' bucket andbucket = new List(); } if (index + 1 0) { List filters = new List(); foreach (string s in andbucket) { filters. Add(BuildSingleWordFilter(s, seachAttributes)); } // send existing and bucket to condition builder FilterExpression childFilter = new FilterExpression(); childFilter. FilterOperator = LogicalOperator.
And; childFilter. Filters = filters.ToArray(); // add to child filter list allchildfilters. Add(childFilter); //new 'and' bucket andbucket = new List(); } if (orBucket.
Count > 0) { filter. Conditions = BuildConditions(orBucket.ToArray(), seachAttributes); } filter. FilterOperator = LogicalOperator.
Or; filter. Filters = allchildfilters.ToArray(); return filter; } private FilterExpression BuildSingleWordFilter(string word, string seachAttributes) { List conditions = new List(); foreach (string attr in seachAttributes) { ConditionExpression expr = new ConditionExpression(); expr. AttributeName = attr; expr.
Operator = ConditionOperator. Like; expr. Values = new string { "%" + word + "%" }; conditions.
Add(expr); } FilterExpression filter = new FilterExpression(); filter. FilterOperator = LogicalOperator. Or; filter.
Conditions = conditions.ToArray(); return filter; } private ConditionExpression BuildConditions(string words, string seachAttributes) { List conditions = new List(); foreach (string s in words) { foreach (string attr in seachAttributes) { ConditionExpression expr = new ConditionExpression(); expr. AttributeName = attr; expr. Operator = ConditionOperator.
Like; expr. Values = new string { "%" + s + "%" }; conditions. Add(expr); } } return conditions.ToArray(); }.
Thanks for the answer. It would be a help if you could dig it up. I was thinking about using SQL Server full text searching and probably will end up going that way unless I can find a good way to do it through the APIs available to me.
– Dan Jan 16 '09 at 22:23.
Hm, that's a pretty interesting scenario... You could certainly do a 'Like' query, and 'or' together the colums/attribute conditions you want included in the search. This seems to be how CRM does queries from the box above entity lists (and they're plenty fast). It looks like the CRM database has a full-text index, although exactly which columns are used to populate it is a bit foggy to me after a brief peek.
And remember LinqtoCRM for CRM query love (I started the project, sorry about the shameless plug).
I would suggest utilizing the Dynamics CRM filtered views provided for you in the database. Then you can utilize all the power of native SQL to do any LIKE's or other logic you need. Plus, the filtered views are security trimmed, so you won't have to worry about users accessing records they do not have permission to.
Second - I can recommend "Global Search" by Akvelon which provides ability to search in all Custom Entities and attributes and Out of Box entities and attributes. Also they are using FTS for search in the attached documents contents. You can find more details in their official site: akvelon.com/Products/Dynamics%20CRM%20gl....
Searching and filtering via the CRM SDK does take some time to get used to. In order to simulate full text search, you need to use nested FilterExpressions as your QueryExpression.Criteria. SDK page for nested filters The hardest part is figuring out how to build the parent child relationships.
There's so much boolean logic going on that it's easy to get lost. I had a requirement to build a "search engine" for one of our custom entities. Using this method for a complex search string ("one AND two OR three") with multiple searchable attributes was ugly.
If you're interested though, I can dig it up. While it's not really supported, if you can access the database directly, I would suggest using SQL's full text search capabilities. Ok, here you go.
I don't think you'll be able to copy paste this and fulfill your needs. My customer was only doing two to three key word searches and they were happy with the results from this. You can see what a pain it is to just do this in a simple search scenario.
I basically puked out code until it was 'working'.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.