Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
/.cache
/src
*.pyc
*~
__pycache__
/coverage.xml
/.coverage
Expand Down
4 changes: 2 additions & 2 deletions plugins/backlinks.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ def hook_spark_pipeline_action(self, sc, sqlc, df, indexer):
CONCAT(
regexp_replace(url_to, "^http(s?)://", ""),
" ",
COUNT(*),
SIZE(COLLECT_SET(url_from)),
" ",
CONCAT_WS(" ", COLLECT_LIST(url_from))
CONCAT_WS(" ", COLLECT_SET(url_from))
) r
FROM (
SELECT url url_from, EXPLODE(external_links.href) url_to
Expand Down
40 changes: 40 additions & 0 deletions tests/sparktests/test_plugin_backlinks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# coding: utf-8

import tempfile
import os
import pipes
import pytest
import shutil
import ujson as json


CORPUS = {
"desc": "Simple test with to backlinks to one page",
"docs": [
{
"url": "http://example-a.com/page1",
"content": """<html><title>Page A1</title><a href="http://example-c.com">First backlink</a><a href="http://example-c.com">Second backlink</a></html>"""
},
{
"url": "http://example-c.com",
"content": """<html><title>Example C</title></html>"""
}
]
}


def test_spark_plugin_backlinks(sparksubmit):
tmp_dir = tempfile.mkdtemp()
try:
sparksubmit("spark/jobs/pipeline.py\
--source corpus:{corpus}\
--plugin plugins.backlinks.MostExternallyLinkedPages:domain=example-c.com,output={tmpdir}/out\
".format(corpus=pipes.quote(json.dumps(CORPUS)),
tmpdir=tmp_dir))
parts = [os.path.join(tmp_dir, 'out', f) for f in os.listdir(tmp_dir + '/out/') if f.startswith("part-")]
assert len(parts) == 1
with open(parts[0], 'r') as f:
data = set(f.read().strip().split('\n'))
assert data == set(["example-c.com/ 1 http://example-a.com/page1"])
finally:
shutil.rmtree(tmp_dir)