Angularjs   发布时间:2022-04-20  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了将文档从AngularJS发布到SOLR 4大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
对此深陷兔子洞.我正在创建一个简单的应用程序,它使用SOLR 4作为Nosql数据存储区,使用AngularJS v1.2.2作为接口.我从命令行加载了一堆文件,AngularJS使搜索/查看这些文件变得非常容易.我想允许文档编辑,但无法使POST工作. Chrome控制台显示400个错误,“网络”标签显示OPTIONS方法失败.
网络标题
请求URL:http:// localhost:8983 / solr / mrm_assay / update
请求方法:选项
状态代码:400错误请求
请求标题
接受:*/*
接受编码:gzip,放气,SDCH
接受语言:EN-US,EN; Q = 0.8,ES; Q = 0.6
Access-Control-request-Headers:accept,content-type
访问控制请求-方法:POST
缓存控制:无缓存
连接:保持活跃
主持人:本地主机:8983
产地:http://本地主机:63342
附注:无缓存
引用者:http://本地主机:63342 /角solr2 /应用/ index.html中
用户代理:Mozilla / 5.0(Macintosh; Intel Mac OS X 10_8_5)AppleWebKit / 537.36(K HTML,与Gecko一样)Chrome / 31.0.1650.57 Safari / 537.36
响应标题
访问控制允许的凭据:真
Access-Control-Allow-Headers:origin,content-type,cache-control,accept,options
访问控制允许的方法:GET,POST,deletE,PUT,HEAD,OPTIONS
访问控制允许来源:http://本地主机:63342
访问控制 – 最大 – 年龄:1800
内容类型:应用/ XML;字符集= UTF-8
传输编码:分块

架构快速概述:
SOLR和AngularJS应用程序都在我的Mac上运行.
SOLR使用认的jetty实例,Angular应用程序在WebStorm IDE的服务器内运行. CORS已启用,包括GET,OPTIONs.

更新工作时:

>使用SOLR的仪表板
>使用命令行(示例)
$curl http:// localhost:8983 / solr / mrm_assay / update -H’Content-type:application / json’-d'[{
“keep_in_assay”{“set”:“N”,
“detected_endog”:“N”,
“problems_w_is”:“删除的b / c需要添加后绿洲”,
“onc_std_set”:“set1”,
“fraction_id”:“7”,
“onclistgene”:“UBL3”,
“genEID”:“UBL3_IS6”,
“taxonid”:“9606”,
“肽”:“SSNVPADMINLR”,
“degen_human”:“1”,
“gene_degeneracy”:“1”,
“percnt_id”:“66.7”,
“uuid”:“6d20eb03-d3ee-4eb2-bc16-27cfaabab989”
}]’

我的Angular控制器代码如下所示:
assayControllers.controller(‘AssayupdateController’,[‘$scope’,’$http’,
   @R_848_3816@($scope,$http){
        $scope.processForm = function(){
            的console.log($scope.assay);
            $http({
                方法: ‘POST’,
                网址: ‘http://本地主机:8983 / Solr的/ mrm_assay /更新’,
                数据:$scope.assay,
                标题{‘Content-Type’:’application / json’}
            })
                .success(function(data,status,headers){
                    的console.log(data.@R_616_8798@gE);
                })
                .error(function(data,headers,config){
                    的console.log(状态);
                });
        };
    }
]);

数据从表单中成功发送,因为我可以在控制台上看到它(JSON对象没有打包在一个数组中,SOLR似乎期望…我还尝试将JSON格式的数据推送到数组并POST但没有运气)

我感谢您的帮助 – 即使只是为了指导我的故障排除!

解决方法

关于如何使用AngularJS v1.2.2将单个文档更新为SOLR v4.7的答案是多部分的.这只在我的localhost上测试过!

I.在SOLRsolr-4.7.0 / example / solr-webapp / webapp / WEB-INF / web.xml附带的jetty服务器上配置CORS

注意:CrossOriginFilter有一个参数chainPreflight,认情况下设置为true.这需要设置为false.这是CORS转发POST而不是SOLTIONS的关键.此外,订单很重要!

<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,OPTIONS</param-value>
     </init-param>
     <init-param>
         <param-name>allowedHeaders</param-name>
         <param-value>origin,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>

II. 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,headers){
                    console.log(data.@R_616_8798@gE);
                    $LOCATIOn.path("/assays")
                })
                .error(function(data,config){
                    console.log(status);
                });
        };
    }
]);

III. SOLR文档包含可能导致POST出现“冲突”错误的版本字段.这是由于我无法追踪的缓存问题(卷曲显示当前值但浏览器有旧版;甚至强制刷新).无论如何,这对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发布到SOLR 4全部内容,希望文章能够帮你解决将文档从AngularJS发布到SOLR 4所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。