#!/bin/bash set -e # customize these if you don't use vagrant FORWARDED_PORT=`cat /vagrant/.settings.yaml | ack '^http_port:\s*(\d+)$' --output '$1' || echo 8080` ACTION_API=http://dev.wiki.local.wmftest.net:$FORWARDED_PORT/w/api.php ELASTIC_API=http://localhost:9200 # $1: article title, $2: article text, outputs page ID api_edit() { curl -s -d "format=json&action=edit&title=$1&text=$2" --data-urlencode 'token=+\' "$ACTION_API" } # $1: page ID, $2: ORES data as JSON string api_index() { curl -s -XPOST "$ELASTIC_API/wiki_content/page/$1/_update" -H 'Content-Type: application/json' -d '{"doc": {"ores_articletopics": '"$2"' }}' } # $1: article title, $2: article text, $3: ORES data as JSON string api_execute() { output=$(api_edit $1 $2) echo "$output" | jq . page_id=$(echo "$output" | jq '.edit.pageid') mwscript extensions/CirrusSearch/maintenance/forceSearchIndex.php --ids $page_id api_index $page_id "$3" | jq . } # test data; page name, page content, ES articletopic field content api_execute Test_books "books" '["Culture.Media.Books|980"]' api_execute Test_stem "stem" '["STEM.STEM*|970"]' api_execute Test_both "books stem" '["Culture.Media.Books|600","STEM.STEM*|550"]' api_execute Test_none "-" '[]' # check by visiting Special:ApiSandbox#action=query&format=json&prop=cirrusdoc&titles=Test%20books%7CTest%20stem%7CTest%20both%7CTest%20none