2017-11-22 12 views
0

これは私のpythonのコードです:Solrはドイツ語の文字をフィールドに追加しませんか?

cmd = "curl localhost:8983/solr/" + core + "/update?commit=true -H 'Content-type:application/json' --data-binary " + "\"[{'id':'" + getLastAddedDocumentID(
     'id') + "','title':{'set':'" + title + "'},'author':{'set':'" + authorNames + "'},'abstract':{'set':'" + abstract + "'}}]\"" 
    print cmd 
    pp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) 
    text, err = pp.communicate() 
    print text 

フィールドにデータを追加するためにcurlコマンドが含まれている私の変数cmdは以下の通りです:

curl localhost:8983/solr/test/update?commit=true -H 'Content-type:application/json' --data-binary 
"[{'id':'15973569-229c-4ce1-83e2-4f5ba543386f', 
    'title':{'set':'Bi\-criteria\ Algorithm\ for\ Scheduling\ Jobs\ on\ Cluster\ Platforms\ \*'}, 
    'author':{'set':'Pierre\-François\ Dutot\;\ Lionel\ Eyraud\;\ Grégory\ Gr´\;\ Grégory\ Mouní\;\ Denis\ Trystram\;\ '}, 
    'abstract':{'set':'We\ describe\ in\ this\ paper\ a\ new\ method\ for\ building\ an\ efficient\ algorithm\ for\ scheduling\ jobs\ in\ a\ cluster.\ Jobs\ are\ considered\ as\ parallel\ tasks\ \(PT\)\ which\ can\ be\ scheduled\ on\ any\ number\ of\ processors.\ The\ main\ feature\ is\ to\ consider\ two\ criteria\ that\ are\ optimized\ together.\ These\ criteria\ are\ the\ makespan\ and\ the\ weighted\ minimal\ average\ completion\ time\ \(minsum\).\ They\ are\ chosen\ for\ their\ complementarity,\ to\ be\ able\ to\ represent\ both\ user\-oriented\ objectives\ and\ system\ administrator\ objectives.\ We\ propose\ an\ algorithm\ based\ on\ a\ batch\ policy\ with\ increasing\ batch\ sizes,\ with\ a\ smart\ selection\ of\ jobs\ in\ each\ batch.\ This\ algorithm\ is\ assessed\ by\ intensive\ simulation\ results,\ compared\ to\ a\ new\ lower\ bound\ \(obtained\ by\ a\ relaxation\ of\ ILP\)\ of\ the\ optimal\ schedules\ for\ both\ criteria\ separately.\ It\ is\ currently\ implemented\ in\ an\ actual\ real\-size\ cluster\ platform.'}}]" 

フィールドアブストラクトは次のとおりです。

<field name="abstract" type="string" docValues="true" indexed="true" stored="true"/> 

次のコマンドを実行しているときに私が直面する問題は、次のとおりです。

Traceback (most recent call last): 

File "F:/pyCalculation/uploadResearchPaper.py", line 196, in addDocument(pathToResearchPapersFolder + department + '/', query, >department) File "F:/pyCalculation/uploadResearchPaper.py", line 188, in addDocument pp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) File "C:\Python27\lib\subprocess.py", line 390, in init errread, errwrite) File "C:\Python27\lib\subprocess.py", line 610, in _execute_child args = '{} /c "{}"'.format (comspec, args) UnicodeEncodeError: 'ascii' codec can't encode character u'\xe7' in position >267: ordinal not in range(128)

と位置276の行は次のようになります。

'set':'Pierre-François\ Dutot\;

問題このキャラクターは?

なぜ私はこのデータをフィールドに追加できないのですか?

答えて

0

これは、サブプロセス呼び出しを呼び出そうとしているときにあなたのキャラクターがアスキーコーデックに変換されていないと不平を言っています。しかし、use a python Solr clientをPythonからSolrに接続するときは、コマンドラインと同じように、サブプロセスを通してcurlを起動しないでください。

データがユニコードであれば問題は解決されるはずです(また、strである限り、python3としてタグ付けしているので問題ありません)。

setコマンドは既存のドキュメントを変更するためのコマンドでもあります。ドキュメントを初めて索引付けする場合は、ドキュメント構造の一部にsetの部分は必要ありません。

関連する問題