- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我对此深陷困境。我正在创建一个简单的应用程序,它使用 SOLR 4 作为 NoSQL 数据存储和 AngularJS v1.2.2 作为界面。我已经从命令行加载了一堆文档,AngularJS 使得搜索/查看这些文档变得非常容易。我想允许文档编辑,但无法使 POST 工作。 Chrome 控制台显示 400 错误,网络选项卡显示它在 OPTIONS 方法上失败。
网络 header :请求网址:http://localhost:8983/solr/mrm_assay/update
请求方式:OPTIONS
状态码:400 错误请求
请求 header
接受:*/*
接受编码:gzip、deflate、sdch
接受语言:en-US,en;q=0.8,es;q=0.6
访问控制请求 header :接受,内容类型
访问控制请求方法:POST
缓存控制:无缓存
连接:保持事件状态
主机:本地主机:8983
来源:http://localhost:63342
用法:无缓存
引用:http://localhost:63342/angular-solr2/app/index.html
用户代理:Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36
响应头
访问控制允许凭据:true
Access-Control-Allow-Headers:origin, content-type, cache-control, accept, 选项
访问控制允许方法:GET、POST、DELETE、PUT、HEAD、OPTIONS
访问控制允许来源:http://localhost:63342
访问控制最大年龄:1800
内容类型:应用程序/xml;字符集=UTF-8
传输编码:分块
架构快速概览:
SOLR 和 AngularJS 应用程序都在我的 Mac 上运行。SOLR 使用默认的 Jetty 实例,Angular 应用程序从 WebStorm 的 IDE 在服务器内运行。 CORS 已启用,包括 GET、POST、DELETE、PUT、HEAD、OPTIONS。
更新在以下情况下有效:
$ curl http://localhost:8983/solr/mrm_assay/update -H 'Content-type:application/json' -d '[ {
“keep_in_assay”{“设置”:“N”,
"detected_endog": "N",
"problems_w_is": "删除 b/c 需要添加后绿洲",
"onc_std_set": "set1",
"fraction_id": "7",
"onclistgene": "UBL3",
“基因”:“UBL3_IS6”,
“类群”:“9606”,
“肽”:“SSNVPADMINLR”,
"degen_human": "1",
“基因退化”:“1”,
"percnt_id": "66.7",
“uuid”:“6d20eb03-d3ee-4eb2-bc16-27cfaabab989”
} ]'
我的 Angular Controller 代码如下所示:assayControllers.controller('AssayUpdateController', ['$scope', '$http',
功能($范围,$http){
$scope.processForm = function(){
console.log($scope.assay);
$http({
方法:'POST',
url:'http://localhost:8983/solr/mrm_assay/update',
数据:$scope.assay,
header :{'Content-Type':'application/json'}
})
.success(函数(数据、状态、标题){
控制台日志(数据。消息);
})
.error(函数(数据、状态、标题、配置){
控制台日志(状态);
});
};
}
]);
数据已成功从表单发送,正如我在控制台上看到的那样(尽管 JSON 对象未打包在数组中,这是 SOLR 似乎期望的……我还尝试将 JSON 格式的数据推送到数组和 POST 但没有运气)
感谢您的帮助 - 即使只是指导我进行故障排除!
最佳答案
关于如何使用 AngularJS v1.2.2 将单个文档更新到 SOLR v4.7 的答案是多部分的。这只在我的本地主机上测试过!
我。在 SOLR 附带的 Jetty 服务器上配置 CORS
solr-4.7.0/example/solr-webapp/webapp/WEB-INF/web.xml
注释: CrossOriginFilter 有一个参数 chainPreflight,默认设置为 true。这需要设置为false。 这是 CORS 将 POST 而不是 OPTIONS 转发到 SOLR 的关键。。另外,顺序很重要!
<filter>
<filter-name>cross-origin</filter-name>
<filter-class>org.eclipse.jetty.servlets.CrossOriginFilter</filter-class>
<init-param>
<param-name>allowedOrigins</param-name>
<param-value>http://localhost*</param-value>
</init-param>
<init-param>
<param-name>allowedMethods</param-name>
<param-value>GET,POST,DELETE,PUT,HEAD,OPTIONS</param-value>
</init-param>
<init-param>
<param-name>allowedHeaders</param-name>
<param-value>origin, content-type, cache-control, accept, options, authorization, x-requested-with</param-value>
</init-param>
<init-param>
<param-name>supportsCredentials</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>chainPreflight</param-name>
<param-value>false</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>cross-origin</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
二。 SOLR 需要数组格式的有效负载,因此您需要将 Angular 对象插入其中。基本上,$scope.data 变成了 [$scope.data]
assayControllers.controller('AssayUpdateController', ['$scope', '$http', '$location',
function($scope, $http, $location){
$scope.processForm = function(){
$http.post("http://localhost:8983/solr/mrm_assay/update?commit=true", [$scope.assay])
.success(function(data, status, headers){
console.log(data.message);
$location.path("/assays")
})
.error(function(data, status, headers, config){
console.log(status);
});
};
}
]);
三。 SOLR 文档包含可能导致 POST 出现“冲突”错误的version 字段。这是由于我无法追踪的缓存问题(curl 显示当前值但浏览器有旧值;即使在强制刷新时也是如此)。无论如何,这对 SOLR 比我更有用,所以最好的办法是一开始就不要将它返回给客户。我不认为字段排除是一个选项,所以我将我想在 solrconfig.xml 中返回的所有字段列入白名单
<!-- A request handler that returns indented JSON by default -->
<requestHandler name="/query" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">text</str>
<str name="fl">uuid,keep_in_assay,detected_endog,problems_w_is,onc_std_set,fraction_id,detected_by_orbi_experiments,onclistgene,geneid,taxonid,peptide,\
degen_human,degen_mouse,gene_degeneracy,department,protein_ac,pepid,protid,percnt_id,peptide_ordered</str>
现在这个应用程序就像一个魅力!
关于angularjs - 从 AngularJS 将文档发布到 SOLR 4,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22579367/
是否有在非 AngularJS 页面内初始化 AngularJS 应用程序的最佳实践方法?我正在向现有网页添加新功能,需要传入一个参数。具体来说,有一组选项卡,一个新选项卡将启动一个 Angular
找不到这两者之间的区别。 保留其中任何一个来引导我的 Angular 应用程序是否有意义? angular.bootstrap(document,['myApp']); 或者 angularAMD.b
我试图理解 Packpub 的书附带的示例 AngularJS 应用程序。 app.js文件在 client/src/app 下定义文件夹,它的模块定义看起来像 angular.module('app
Angularjs 具有用于表单验证和显示错误消息的强大基础设施。但是,我处于必须在特定场景中向用户显示警告消息的情况。这是我的简单表格的图表 该表单在两个字段上都应用了必需和模式验证。除了此验证之外
我在重试功能正常工作时遇到了一些麻烦,希望能获得一些帮助。我有一个要调用的$ resource,直到出现成功情况或超过最大重试次数为止。 我似乎遇到的问题是,在我的重试函数中,我正在调用另一个prom
我目前正在开发一个 AngularJS 应用程序,我遇到了以下障碍。 当用户提交时,我们有一个 login 页面,我们调用一个 web api 并对用户进行身份验证,我们目前正在使用 claims 身
当范围更新时,指令的属性不会改变,它们仍然保持初始值。我在这里缺少什么? HTML works great works: {{foo}} Javascript (基于首页上的 A
我正在使用 Zurb 的 Foundation 框架修改应用程序以实现响应性和 AngularJS。存在数据显示在带有 ... 的表中的错误有 是根据 Foundation 的响应规则隐藏/显示的。不
在过去的三天里,我一直在搜寻互联网,试图弄清楚当angular注意到div的宽度发生变化时如何使指令运行。 我不断看到相同的示例,说明如何实现此目标,但是它们对我不起作用,我也不知道为什么。 我回到一
我正在使用以下代码尝试汇总 在 Angular ,这在整个作品中,但是小于 0.5 的数字四舍五入为 0。我想 向上取整 每个数字到下一个整数。例如 0.02 应四舍五入为 1 {{((data.Vi
我目前正在尝试以一种能够适当扩展到企业级别的方式来组织我的 Angular 应用程序。但是我发现似乎过度依赖框架内的命名约定,并且试图避免命名冲突是一个真正的问题。 例如,当定义任何 constant
我正在阅读 AngularJS 基础知识,并且喜欢在我的页面中使用它的绑定(bind)功能。所以我可以定义可以在 View 中显示的数据,可以对数据进行更改,以便在 View 中更改它而无需担心。 在
在父 Controller 范围内,我定义了 selectedItem设置为“x”。然后在子范围内,我定义了selectedItem使用 ngModel:
关闭。这个问题需要更多 focused .它目前不接受答案。 想改进这个问题?更新问题,使其仅关注一个问题 editing this post . 5年前关闭。 Improve this questi
如果2个条件为真,我试图将一个特定的类应用于li元素,因此我编写了以下代码,但似乎无法正常工作 ng-class="{current:isActive('/'), loginStatus: false
请看看朋克。 http://plnkr.co/edit/DuTFYbLVbPkCIvRznYjG?p=preview ng-pattern regEx不适用于输入文本字段。 仅在需要验证的情况下才能正
我正在为iOS + Android构建AngularJS(1.x)和Ionic/Cordova移动应用程序。我想在登录页面上添加/创建“深层链接”,以便在我向新用户发送“确认您的电子邮件”电子邮件时,
angularjs 中服务(或工厂)的生命周期是什么,何时重新初始化? 最佳答案 当 Angular 启动时,它会将服务的构造函数附加到关联的模块上。这种情况发生一次。 angular .modu
我对 Angular 很陌生,所以希望我知道的足够多,可以问什么似乎是合理的设计问题。 我正在通过 Angular 绘制一些数据,并且正在使用 $resource。在将 Angular 引入项目之前,
我需要在我的 angular-breeze 应用程序中使用国家/地区下拉菜单,我尝试了以下操作: https://github.com/banafederico/angularjs-country-s
我是一名优秀的程序员,十分优秀!