public List<SearchResult> AdvancedSearch(string searchmethod, string searchstring, string key) { if (!CheckKey(key)) return null; try { searchstring = HttpUtility.UrlDecode(searchstring); String[] termpairlist = searchstring.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); System.Collections.Specialized.NameValueCollection searchFieldsAndTerms = new System.Collections.Specialized.NameValueCollection(); foreach (string s in termpairlist) { string[] t = s.Split(new char[] { '=' }); searchFieldsAndTerms[t[0]] = t[1]; } string username = GetUsername(); if (username == "") return null; //Do the search List<SearchResult> results = new List<SearchResult>(); vwarDAL.PermissionsManager prm = new vwarDAL.PermissionsManager(); vwarDAL.DataAccessFactory factory = new vwarDAL.DataAccessFactory(); vwarDAL.ISearchProxy search = factory.CreateSearchProxy(username); vwarDAL.SearchMethod method = vwarDAL.SearchMethod.OR; if (searchmethod.Equals("AND", StringComparison.CurrentCultureIgnoreCase)) method = vwarDAL.SearchMethod.AND; IEnumerable<vwarDAL.ContentObject> caresults = search.SearchByFields(searchFieldsAndTerms, method); //Build the search results foreach (vwarDAL.ContentObject co in caresults) { SearchResult r = new SearchResult(); r.PID = co.PID; r.Title = co.Title; results.Add(r); } search.Dispose(); return results; } catch (Exception ex) { List<SearchResult> results = new List<SearchResult>(); results.Add(new SearchResult { Title = ex.Message }); return results; } //return them }
//Search the repo for a list of pids that match a search term //This returns the results as a list of pairs of titles and pids //will eventually take a pagenum and other params for more advanced searching public List<SearchResult> Search(string terms, string key) { if (!CheckKey(key)) return null; try { terms = HttpUtility.UrlDecode(terms); String[] termlist = terms.Split(new char[] {';', ',', '&' }, StringSplitOptions.RemoveEmptyEntries); string username = GetUsername(); if (username == "") return null; //Do the search List<SearchResult> results = new List<SearchResult>(); vwarDAL.PermissionsManager prm = new vwarDAL.PermissionsManager(); vwarDAL.DataAccessFactory factory = new vwarDAL.DataAccessFactory(); vwarDAL.ISearchProxy search = factory.CreateSearchProxy(username); bool usingKeyword = false; if (termlist[0] == "Keywords") { List<String> temp = new List<string>(termlist); temp.RemoveAt(0); termlist = temp.ToArray(); usingKeyword = true; } foreach (string searchterm in termlist) { IEnumerable<vwarDAL.ContentObject> caresults; if (! usingKeyword) caresults = search.DeepSearch(searchterm); else caresults = search.QuickSearch(searchterm); //Build the search results if (caresults != null) foreach (vwarDAL.ContentObject co in caresults) { SearchResult r = new SearchResult(); r.PID = co.PID; r.Title = co.Title; results.Add(r); } } search.Dispose(); prm.Dispose(); return results; } catch (Exception ex) { List<SearchResult> results = new List<SearchResult>(); results.Add(new SearchResult { Title = ex.Message + ex.StackTrace }); return results; } //return them }