mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-22 13:12:41 +00:00
Test scraping
Text search should also match scraped content when appropriate
This commit is contained in:
parent
76f70119fd
commit
7897585d98
2 changed files with 43 additions and 8 deletions
|
@ -1711,10 +1711,10 @@ class Database {
|
|||
}
|
||||
// handle text-matching context options
|
||||
$options = [
|
||||
"titleTerms" => ["arsse_articles.title"],
|
||||
"searchTerms" => ["arsse_articles.title", "arsse_articles.content"],
|
||||
"authorTerms" => ["arsse_articles.author"],
|
||||
"annotationTerms" => ["arsse_marks.note"],
|
||||
"titleTerms" => ["title"],
|
||||
"searchTerms" => ["title", "content"],
|
||||
"authorTerms" => ["author"],
|
||||
"annotationTerms" => ["note"],
|
||||
];
|
||||
foreach ($options as $m => $columns) {
|
||||
if (!$context->$m()) {
|
||||
|
@ -1722,6 +1722,10 @@ class Database {
|
|||
} elseif (!$context->$m) {
|
||||
throw new Db\ExceptionInput("tooShort", ['field' => $m, 'action' => $this->caller(), 'min' => 1]); // must have at least one array element
|
||||
}
|
||||
$columns = array_map(function ($c) use ($colDefs) {
|
||||
assert(isset($colDefs[$c]), new Exception("constantUnknown", $c));
|
||||
return $colDefs[$c];
|
||||
}, $columns);
|
||||
$q->setWhere(...$this->generateSearch($context->$m, $columns));
|
||||
}
|
||||
// further handle exclusionary text-matching context options
|
||||
|
@ -1729,6 +1733,10 @@ class Database {
|
|||
if (!$context->not->$m() || !$context->not->$m) {
|
||||
continue;
|
||||
}
|
||||
$columns = array_map(function ($c) use ($colDefs) {
|
||||
assert(isset($colDefs[$c]), new Exception("constantUnknown", $c));
|
||||
return $colDefs[$c];
|
||||
}, $columns);
|
||||
$q->setWhereNot(...$this->generateSearch($context->not->$m, $columns, true));
|
||||
}
|
||||
// return the query
|
||||
|
|
|
@ -22,10 +22,11 @@ trait SeriesArticle {
|
|||
'num' => 'int',
|
||||
],
|
||||
'rows' => [
|
||||
["jane.doe@example.com", "",1],
|
||||
["john.doe@example.com", "",2],
|
||||
["john.doe@example.org", "",3],
|
||||
["john.doe@example.net", "",4],
|
||||
["jane.doe@example.com", "", 1],
|
||||
["john.doe@example.com", "", 2],
|
||||
["john.doe@example.org", "", 3],
|
||||
["john.doe@example.net", "", 4],
|
||||
["jill.doe@example.com", "", 5],
|
||||
],
|
||||
],
|
||||
'arsse_feeds' => [
|
||||
|
@ -110,6 +111,7 @@ trait SeriesArticle {
|
|||
[12,"john.doe@example.net",2, 9,null,0],
|
||||
[13,"john.doe@example.net",3, 8,"Subscription 13",0],
|
||||
[14,"john.doe@example.net",4, 7,null,0],
|
||||
[15,"jill.doe@example.com",11,null,null,1],
|
||||
],
|
||||
],
|
||||
'arsse_tag_members' => [
|
||||
|
@ -1149,4 +1151,29 @@ trait SeriesArticle {
|
|||
$state = $this->primeExpectations($this->data, $this->checkTables);
|
||||
$this->compareExpectations(static::$drv, $state);
|
||||
}
|
||||
|
||||
public function testSelectScrapedContent(): void {
|
||||
$exp = [
|
||||
['id' => 101, 'content' => "<p>Article content 1</p>"],
|
||||
['id' => 102, 'content' => "<p>Article content 2</p>"],
|
||||
];
|
||||
$this->assertResult($exp, Arsse::$db->articleList("john.doe@example.org", (new Context)->subscription(8), ["id", "content"]));
|
||||
$exp = [
|
||||
['id' => 101, 'content' => "<p>Scraped content 1</p>"],
|
||||
['id' => 102, 'content' => "<p>Article content 2</p>"],
|
||||
];
|
||||
$this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15), ["id", "content"]));
|
||||
}
|
||||
|
||||
public function testSearchScrapedContent(): void {
|
||||
$exp = [
|
||||
['id' => 101, 'content' => "<p>Scraped content 1</p>"],
|
||||
['id' => 102, 'content' => "<p>Article content 2</p>"],
|
||||
];
|
||||
$this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15)->searchTerms(["article"]), ["id", "content"]));
|
||||
$exp = [
|
||||
['id' => 101, 'content' => "<p>Scraped content 1</p>"],
|
||||
];
|
||||
$this->assertResult($exp, Arsse::$db->articleList("jill.doe@example.com", (new Context)->subscription(15)->searchTerms(["scraped"]), ["id", "content"]));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue