public QueryTerm addInUrl(String term, bool include) { if (include) { InUrlTerms.Add(term); } else { NotInUrlTerms.Add(term); } return(this); }
/// <summary> /// Extracts QueryTerm properties from a querystring. /// </summary> /// <param name="queryString"></param> public void Populate(string queryString) { // pad the querystring with a space to make our job easier queryString += _SP; string[] flagArray = new string[] { _NOT_IN_TITLE, _NOT_IN_URL, _EXCLUDE_FILETYPE, _EXCLUDE_SITE, _IN_TITLE, _IN_URL, _INCLUDE_FILETYPE, _INCLUDE_SITE, _CACHE, _INFO, _LINK, _ALL_IN_TITLE, _ALL_IN_URL }; foreach (string flag in flagArray) { // loop through all instances of the flag while (queryString.Contains(flag)) { // extract the flag and value from our querystring for further processing int startIndex = queryString.IndexOf(flag); string extract = null; if (flag == _ALL_IN_URL || flag == _ALL_IN_TITLE) { // capture from flag till the next flag or the end of the line int nextFlagIndex = queryString.IndexOfAny(flagArray); extract = queryString.Substring(startIndex, nextFlagIndex != -1 ? nextFlagIndex : queryString.Length - startIndex); } else // capture till first space { extract = queryString.Substring(startIndex, queryString.IndexOf(_SP, startIndex) - startIndex); } // remove the extract from our querystring queryString = queryString.Remove(startIndex, extract.Length); // update the appropriate property string value = extract.Remove(0, flag.Length); switch (flag) { case _IN_TITLE: AllInTitleTerms.Add(value); break; case _NOT_IN_TITLE: NotInTitleTerms.Add(value); break; case _IN_URL: InUrlTerms.Add(value); break; case _NOT_IN_URL: NotInTitleTerms.Add(value); break; case _INCLUDE_FILETYPE: IncludeFiletype.Add(value); break; case _EXCLUDE_FILETYPE: ExcludeFiletype.Add(value); break; case _INCLUDE_SITE: IncludeSite = true; Site = value; break; case _EXCLUDE_SITE: IncludeSite = false; Site = value; break; case _LINK: Link = value; break; case _INFO: WebDocLocation = value; break; case _CACHE: CacheDocLocation = value; break; default: throw new NotImplementedException(); break; } } } // anything that is left over is the querystring this.QueryString = queryString.Trim(); }