예제 #1
0
 def post(self):
     if self.validate(self.get_argument('validate', default=None)):
         qaStr = self.get_argument('qa')
         qaJson = os.path.join(constants.TEMP_PATH, 'qa_json')
         try:
             make_json.convert(qaStr, qaJson)
             solr_tools.clear_documents(config.get('/anyq/host', '0.0.0.0'),
                                        'collection1',
                                        config.get('/anyq/solr_port', '8900')
             )
             solr_tools.upload_documents(config.get('/anyq/host', '0.0.0.0'),
                                         'collection1',
                                         config.get('/anyq/solr_port', '8900'),
                                         qaJson,
                                         10
             )
             with open(constants.getQAPath(), 'w') as f:
                 f.write(qaStr)
             res = {'code': 0, 'message': 'ok'}
             self.write(json.dumps(res))
         except Exception as e:
             logger.error(e)
             res = {'code': 1, 'message': '提交失败,请检查内容'}
             self.write(json.dumps(res))
     else:
         res = {'code': 1, 'message': 'illegal visit'}
         self.write(json.dumps(res))
     self.finish()
예제 #2
0
 def post(self):
     if self.validate(self.get_argument("validate", default=None)):
         qaStr = self.get_argument("qa")
         qaJson = os.path.join(constants.TEMP_PATH, "qa_json")
         try:
             make_json.convert(qaStr, qaJson)
             solr_tools.clear_documents(
                 config.get("/anyq/host", "0.0.0.0"),
                 "collection1",
                 config.get("/anyq/solr_port", "8900"),
             )
             solr_tools.upload_documents(
                 config.get("/anyq/host", "0.0.0.0"),
                 "collection1",
                 config.get("/anyq/solr_port", "8900"),
                 qaJson,
                 10,
             )
             with open(constants.getQAPath(), "w") as f:
                 f.write(qaStr)
             res = {"code": 0, "message": "ok"}
             self.write(json.dumps(res))
         except Exception as e:
             logger.error(e)
             res = {"code": 1, "message": "提交失败,请检查内容"}
             self.write(json.dumps(res))
     else:
         res = {"code": 1, "message": "illegal visit"}
         self.write(json.dumps(res))
     self.finish()
예제 #3
0
 def upload(self, threadNum=10):
     """
     手动上传 QA 集语料,重建 solr 索引
     """
     try:
         qaJson = os.path.join(constants.TEMP_PATH, 'qa_json')
         make_json.run(constants.getQAPath(), qaJson)
         solr_tools.clear_documents(config.get('/anyq/host', '0.0.0.0'),
                                    'collection1',
                                    config.get('/anyq/solr_port', '8900'))
         solr_tools.upload_documents(config.get('/anyq/host',
                                                '0.0.0.0'), 'collection1',
                                     config.get('/anyq/solr_port', '8900'),
                                     qaJson, threadNum)
     except Exception as e:
         logger.error("上传失败:{}".format(e))
예제 #4
0
 def upload(self, threadNum=10):
     """
     手动上传 QA 集语料,重建 solr 索引
     """
     try:
         qaJson = os.path.join(constants.TEMP_PATH, "qa_json")
         make_json.run(constants.getQAPath(), qaJson)
         solr_tools.clear_documents(
             config.get("/anyq/host", "0.0.0.0"),
             "collection1",
             config.get("/anyq/solr_port", "8900"),
         )
         solr_tools.upload_documents(
             config.get("/anyq/host", "0.0.0.0"),
             "collection1",
             config.get("/anyq/solr_port", "8900"),
             qaJson,
             threadNum,
         )
     except Exception as e:
         logger.error("上传失败:{}".format(e))