Created
January 13, 2014 15:54
-
-
Save BartDM/8402642 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected SearchResult Search<T>(string field, string searchQuery) where T : IDocument | |
{ | |
Log.DebugFormat("Searching for Type: {0} with query \"{1}\" for field \"{2}\"", typeof(T), searchQuery, field); | |
//Fetch the possible fields to search on | |
PropertyInfo[] properties = typeof(T).GetProperties(); | |
var fields = new List<string>(); | |
var fieldsToSearchOn = new List<string>(); | |
foreach (PropertyInfo property in properties) | |
{ | |
var attributes = property.GetCustomAttributes(true); | |
foreach (var o in attributes) | |
{ | |
var attr = o as SearchField; | |
if (attr != null) | |
{ | |
fields.Add(property.Name); | |
if (attr.CombinedSearchFields.Any() && field == property.Name) | |
{ | |
fieldsToSearchOn.Add(property.Name); | |
for (int i = 0; i < attr.CombinedSearchFields.Count(); i++) | |
{ | |
fieldsToSearchOn.Add(attr.CombinedSearchFields[i]); | |
} | |
} | |
else if (field == property.Name) | |
{ | |
fieldsToSearchOn.Add(property.Name); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment