예제 #1
0
        public IContentResponse GetResponse(string method, string rawUrl, System.Collections.Specialized.NameValueCollection headers, System.IO.Stream inputStream)
        {
            string        pageText   = null;
            StringBuilder searchText = new StringBuilder();

            string[] args = rawUrl.Substring(_urlPrefix.Length).TrimStart('?').Split('#')[0].Split('&');
            foreach (string arg in args)
            {
                if (arg.StartsWith("page="))
                {
                    pageText = arg.Substring(5);
                }
                else
                {
                    searchText.AppendFormat("{0} ", Uri.UnescapeDataString(arg.Substring(arg.IndexOf('=') + 1)).Replace('+', ' '));
                }
            }

            int page;

            if (pageText == null || !int.TryParse(pageText, out page))
            {
                page = 1;
            }

            string query = searchText.ToString().Trim();

            if (_template == null || !Object.ReferenceEquals(_templateReadFrom, _content.Storage))
            {
                _templateReadFrom = _content.Storage;
                _template         = new SearchTemplate(_content.Storage);
            }

            return(new DynamicResponse(_template.RenderResults(query, page)));
        }
예제 #2
0
 public void HtmlSearch(
     [Argument("site", "s", Description = "The root http address of the website copy.")]
     string site,
     [Argument("term", "t", Description = "The expression to search for, see http://lucene.apache.org/java/2_4_0/queryparsersyntax.html.")]
     string term,
     [Argument("page", "p", DefaultValue = 1, Description = "The result page to return.")]
     int page)
 {
     using (ContentStorage store = new ContentStorage(StoragePath(site), true))
     {
         SearchTemplate template = new SearchTemplate(store);
         string         tmp      = template.RenderResults(term, page);
         Console.WriteLine(tmp);
     }
 }