我正在尝试通过实现一个简单的Web应用程序开始使用Clojure和Clojurescript.到目前为止事情进展顺利,从不同的教程中读到我提出的代码如下:
core.clj:
(ns myapp.core
(:require [compojure.core :as compojure]
[compojure.handler :as handler]
[compojure.route :as route]
[myapp.controller :as controller]))
(compojure/defroutes app-routes
(compojure/GET "/" [] controller/index)
(route/resources "/public")
(route/not-found "Not Found"))
(def app
(handler/site app-routes))
Run Code Online (Sandbox Code Playgroud)
controller.clj:
(ns myapp.controller
(:use ring.util.response)
(:require [myapp.models :as model]
[myapp.templates :as template]))
(defn index
"Index page handler"
[req]
(->> (template/home-page (model/get-things)) response))
Run Code Online (Sandbox Code Playgroud)
templates.clj:
(ns myapp.templates
(:use net.cgrand.enlive-html)
(:require [myapp.models :as model]))
(deftemplate home-page "index.html" [things]
[:li] (clone-for [thing things] (do->
(set-attr 'data-id (:id thing))
(content (:name thing)))))
Run Code Online (Sandbox Code Playgroud)
问题是我无法在页面上显示非ascii字符,我不知道如何在页面上设置HTTP标头. …
我正在尝试从C#生成Excel图表.生成的图表只是查找但它总是出现在屏幕的中心.如何设置图表的位置?
谢谢.
我的代码看起来像这样:
Microsoft.Office.Interop.Excel._Workbook ebook = (Microsoft.Office.Interop.Excel._Workbook)etablo.Workbooks.Add(true);
Microsoft.Office.Interop.Excel._Worksheet esheet = (Microsoft.Office.Interop.Excel._Worksheet)ebook.ActiveSheet;
_Chart grafik1 = (Chart)ebook.Charts.Add(Type.Missing, Type.Missing, Type.Missing, Type.Missing);
/* Add Data From Cells here */
/* Then */
grafik1.Location(XlChartLocation.xlLocationAsObject, esheet.Name);
Run Code Online (Sandbox Code Playgroud) 我的问题非常类似于这个问题:如何在Clojure中评估一系列不纯函数?但是,如何不是不纯函数,我如何评估纯函数的序列并将结果作为另一个序列?
让我们假设我们有一个函数向量,如:
[#(str "a" "b") #(str "c" "d") #(str "e" "f")]
Run Code Online (Sandbox Code Playgroud)
我们需要这样的输出:
("ab" "cd" "ef")
Run Code Online (Sandbox Code Playgroud)
我尝试过类似的东西:
(map eval [#(str "a" "b") #(str "c" "d") #(str "e" "f")])
Run Code Online (Sandbox Code Playgroud)
但它只返回一个函数引用向量.
使用Spark 1.6.2并尝试查找字段是否包含空字符串或日期值.
Spark文档解释说,如果unix_timestamp()函数失败,则返回null,因此需要以下行为:
sqlContext.sql("select unix_timestamp('')").show
+----+
| _c0|
+----+
|null|
+----+
Run Code Online (Sandbox Code Playgroud)
但是当我尝试用"is null"检查它时,它返回false:
sqlContext.sql("select unix_timestamp('') is null").show
+-----+
| _c0|
+-----+
|false|
+-----+
Run Code Online (Sandbox Code Playgroud)
相同的查询在Hive中返回true:
hive> select unix_timestamp('') is null;
OK
true
Run Code Online (Sandbox Code Playgroud)
为了完整起见,这里是空的null检查:
sqlContext.sql("select null is null").show
+----+
| _c0|
+----+
|true|
+----+
Run Code Online (Sandbox Code Playgroud) 试图从字符串中读取哈希映射,但如果键是"关键字"类型值,我从cljs.reader/read-string得到错误.从字符串中读取哈希映射的正确方法是什么?
此版本没有关键字工作:
(cljs.reader/read-string (pr-str {1 "a", 1481876814936 "sdafa", 1481876816039 "afdas", 1481876817344 "asdfa", 2 "b"}))
=> {1 "a", 1481876814936 "sdafa", 1481876816039 "afdas", 1481876817344 "asdfa", 2 "b"}
Run Code Online (Sandbox Code Playgroud)
但是这个带有关键字的版本会抛出错误:
(cljs.reader/read-string (pr-str {:1 "a", :1481876814936 "sdafa", :1481876816039 "afdas", :1481876817344 "asdfa", :2 "b"}))
cljs.user=> #object[TypeError TypeError: Cannot read property '0' of null]
TypeError: Cannot read property '0' of null
at cljs$reader$read_keyword (file:///test/resources/public/js/ui-out/cljs/reader.js:681:19)
at cljs$reader$read_delimited_list (file:///test/resources/public/js/ui-out/cljs/reader.js:397:20)
at cljs$reader$read_map (file:///test/resources/public/js/ui-out/cljs/reader.js:466:41)
at cljs$reader$read (file:///test/resources/public/js/ui-out/cljs/reader.js:879:34)
at cljs$reader$read_string (file:///test/resources/public/js/ui-out/cljs/reader.js:911:25)
at eval (eval at figwheel$client$utils$eval_helper (file:///test/resources/public/js/ui-out/figwheel/client/utils.js:143:8), <anonymous>:1:114)
at eval (eval at …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用solrj获得构面查询的结果,但似乎我是否添加了facet查询并不重要.无论如何,我得到了相同的文件清单.
所以这个查询返回相同的文档列表......
query.setQuery(searchString);
query.setFacet(true);
query.addFacetField("CATNAME_STR");
query.addFacetQuery("CATNAME_STR:" + facetName);
Run Code Online (Sandbox Code Playgroud)
...使用此查询
query.setQuery(searchString);
query.setFacet(true);
query.addFacetField("CATNAME_STR");
Run Code Online (Sandbox Code Playgroud)
唯一的区别是我可以获得与facet查询匹配的文档数量 response.getFacetQuery();
我期待它的工作方式
http://localhost:8983/solr/select/?q=*%3A*&version=2.2&start=0&rows=10&indent=on&facet=on&facet.field=CATNAME_STR&fq=CATNAME_STR:Erasmus
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
谢谢.
顺便说一句,我使用的是Solr 3.1.0和solr-core-3.1.0