2017-11-22 8 views
0

Das ist mein Python-Code:Solr fügt kein deutsches Zeichen zum Feld hinzu?

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 

Meine Variable cmd, die Curl-Befehl enthält die Daten zu den Feldern hinzuzufügen, ist wie folgt:

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.'}}]" 

Die Feld Zusammenfassung ist wie folgt:

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

Das Problem, das ich konfrontiert werden, wenn dieser Befehl ausgeführt ist:

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)

Und die Linie an Position 276 ist:

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

Das Problem ist mit ç dieser Charakter.

Ich bin verwirrt wie Warum nicht Solr erlauben, diese Daten zu dem Feld hinzufügen?

Antwort

0

Das ist Python, das sich darüber beschwert, dass Ihr Zeichen nicht in den Ascii-Codec konvertiert werden kann, wenn Sie versuchen, einen Unterprozessaufruf aufzurufen. Aber bitteuse a python Solr client Bei der Verbindung zu Solr von Python, nicht Curl durch Subprozess wie auf der Kommandozeile aufrufen.

Das sollte auch Ihr Problem lösen, solange Ihre Daten in Unicode sind (und Sie es als python3 getaggt haben, solange es ein str ist).

Der Befehl set dient auch zum Ändern eines vorhandenen Dokuments. Wenn Sie also das Dokument zum ersten Mal indexieren, benötigen Sie nicht die set Teile Ihrer Dokumentstruktur.

Verwandte Themen