Пример #1
0
        // GET: /Sql/Find?
        public string Find(string id, string callback) {
            Response.ContentType = String.IsNullOrEmpty(callback) ? ContentPlain : ContentJavascript;

            var result = !string.IsNullOrEmpty(id) ? new SqloogleSearcher(ConfigurationManager.AppSettings.Get("SearchIndexPath")).Find(id) : null;

            if (result != null)
            {
                var searchResponse = new SearchResponse();
                searchResponse.searchresults.Add(new Models.ScriptedObjects.SearchResult(result, this));

                return
                    string.IsNullOrEmpty(callback) ?
                    searchResponse.ToJson() :
                        $"{callback}({searchResponse.ToJson()});";
            }

            throw new HttpException(404, "NotFound");
        }
Пример #2
0
        // GET: /Sql/Search?
        public string Search(string q, string callback) {
            Response.ContentType = string.IsNullOrEmpty(callback) ? ContentPlain : ContentJavascript;

            var searchResponse = new SearchResponse();

            if (!string.IsNullOrEmpty(q)) {
                try {
                    var searcher = new SqloogleSearcher(ConfigurationManager.AppSettings.Get("SearchIndexPath"));
                    var results = searcher.Search(q);
                    foreach (var result in results)
                        searchResponse.searchresults.Add(new Models.ScriptedObjects.SearchResult(result, this));
                } catch (Exception e) {
                    searchResponse.success = false;
                    searchResponse.message = e.Message;
                }
                  
            }

            return
                string.IsNullOrEmpty(callback) ?
                searchResponse.ToJson() :
                    $"{callback}({searchResponse.ToJson()});";
        }