1
1
Fork 0
mirror of https://code.mensbeam.com/MensBeam/Arsse.git synced 2024-12-22 21:22:40 +00:00

Add ability to search note text

This commit is contained in:
J. King 2019-02-23 20:14:52 -05:00
parent bc3182a961
commit 2df7c25b66
5 changed files with 41 additions and 7 deletions

View file

@ -1184,18 +1184,18 @@ class Database {
if ($context->editions()) {
// if multiple specific editions have been requested, filter against the list
if (!$context->editions) {
throw new Db\ExceptionInput("tooShort", ['field' => "editions", 'action' => __FUNCTION__, 'min' => 1]); // must have at least one array element
throw new Db\ExceptionInput("tooShort", ['field' => "editions", 'action' => $this->caller(), 'min' => 1]); // must have at least one array element
} elseif (sizeof($context->editions) > self::LIMIT_ARTICLES) {
throw new Db\ExceptionInput("tooLong", ['field' => "editions", 'action' => __FUNCTION__, 'max' => self::LIMIT_ARTICLES]); // @codeCoverageIgnore
throw new Db\ExceptionInput("tooLong", ['field' => "editions", 'action' => $this->caller(), 'max' => self::LIMIT_ARTICLES]); // @codeCoverageIgnore
}
list($inParams, $inTypes) = $this->generateIn($context->editions, "int");
$q->setWhere("latest_editions.edition in ($inParams)", $inTypes, $context->editions);
} elseif ($context->articles()) {
// if multiple specific articles have been requested, filter against the list
if (!$context->articles) {
throw new Db\ExceptionInput("tooShort", ['field' => "articles", 'action' => __FUNCTION__, 'min' => 1]); // must have at least one array element
throw new Db\ExceptionInput("tooShort", ['field' => "articles", 'action' => $this->caller(), 'min' => 1]); // must have at least one array element
} elseif (sizeof($context->articles) > self::LIMIT_ARTICLES) {
throw new Db\ExceptionInput("tooLong", ['field' => "articles", 'action' => __FUNCTION__, 'max' => self::LIMIT_ARTICLES]); // @codeCoverageIgnore
throw new Db\ExceptionInput("tooLong", ['field' => "articles", 'action' => $this->caller(), 'max' => self::LIMIT_ARTICLES]); // @codeCoverageIgnore
}
list($inParams, $inTypes) = $this->generateIn($context->articles, "int");
$q->setWhere("arsse_articles.id in ($inParams)", $inTypes, $context->articles);
@ -1255,12 +1255,21 @@ class Database {
// filter based on search terms
if ($context->searchTerms()) {
if (!$context->searchTerms) {
throw new Db\ExceptionInput("tooShort", ['field' => "searchTerms", 'action' => __FUNCTION__, 'min' => 1]); // must have at least one array element
throw new Db\ExceptionInput("tooShort", ['field' => "searchTerms", 'action' => $this->caller(), 'min' => 1]); // must have at least one array element
} elseif (sizeof($context->searchTerms) > self::LIMIT_TERMS) {
throw new Db\ExceptionInput("tooLong", ['field' => "searchTerms", 'action' => __FUNCTION__, 'max' => self::LIMIT_TERMS]);
throw new Db\ExceptionInput("tooLong", ['field' => "searchTerms", 'action' => $this->caller(), 'max' => self::LIMIT_TERMS]);
}
$q->setWhere(...$this->generateSearch($context->searchTerms, ["arsse_articles.title", "arsse_articles.content"]));
}
// filter based on search terms in note
if ($context->annotationTerms()) {
if (!$context->annotationTerms) {
throw new Db\ExceptionInput("tooShort", ['field' => "annotationTerms", 'action' => $this->caller(), 'min' => 1]); // must have at least one array element
} elseif (sizeof($context->annotationTerms) > self::LIMIT_TERMS) {
throw new Db\ExceptionInput("tooLong", ['field' => "annotationTerms", 'action' => $this->caller(), 'max' => self::LIMIT_TERMS]);
}
$q->setWhere(...$this->generateSearch($context->annotationTerms, ["arsse_marks.note"]));
}
// return the query
return $q;
}

View file

@ -34,6 +34,7 @@ class Context {
public $labelName;
public $labelled = null;
public $annotated = null;
public $annotationTerms = null;
public $searchTerms = null;
protected $props = [];
@ -184,6 +185,13 @@ class Context {
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function annotationTerms(array $spec = null) {
if (isset($spec)) {
$spec = $this->cleanStringArray($spec);
}
return $this->act(__FUNCTION__, func_num_args(), $spec);
}
public function searchTerms(array $spec = null) {
if (isset($spec)) {
$spec = $this->cleanStringArray($spec);

View file

@ -497,6 +497,11 @@ trait SeriesArticle {
// get items that match search terms
$compareIds([1,2,3], (new Context)->searchTerms(["Article"]));
$compareIds([1], (new Context)->searchTerms(["one", "first"]));
// get items that match search terms in note
$compareIds([2], (new Context)->annotationTerms(["some"]));
$compareIds([2], (new Context)->annotationTerms(["some", "note"]));
$compareIds([2], (new Context)->annotationTerms(["some note"]));
$compareIds([], (new Context)->annotationTerms(["some", "sauce"]));
}
public function testListArticlesOfAMissingFolder() {
@ -998,4 +1003,14 @@ trait SeriesArticle {
$this->assertException("tooLong", "Db", "ExceptionInput");
Arsse::$db->articleList($this->user, (new Context)->searchTerms(range(1, 105)));
}
public function testSearchTooFewTermsInNote() {
$this->assertException("tooShort", "Db", "ExceptionInput");
Arsse::$db->articleList($this->user, (new Context)->annotationTerms([]));
}
public function testSearchTooManyTermsInNote() {
$this->assertException("tooLong", "Db", "ExceptionInput");
Arsse::$db->articleList($this->user, (new Context)->annotationTerms(range(1, 105)));
}
}

View file

@ -94,6 +94,7 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
public function testTranslateAToken() {
$this->assertRegExp("/^[a-z][a-z0-9]*$/i", $this->drv->sqlToken("greatest"));
$this->assertRegExp("/^\"?[a-z][a-z0-9_\-]*\"?$/i", $this->drv->sqlToken("nocase"));
$this->assertRegExp("/^[a-z][a-z0-9]*$/i", $this->drv->sqlToken("like"));
$this->assertSame("distinct", $this->drv->sqlToken("distinct"));
}

View file

@ -50,6 +50,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
'labelled' => true,
'annotated' => true,
'searchTerms' => ["foo", "bar"],
'annotationTerms' => ["foo", "bar"],
];
$times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince'];
$c = new Context;
@ -83,7 +84,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
}
public function testCleanStringArrayValues() {
$methods = ["searchTerms"];
$methods = ["searchTerms", "annotationTerms"];
$now = new \DateTime;
$in = [1, 3.0, "ook", 0, true, false, null, $now, ""];
$out = ["1", "3", "ook", "0", valueInfo::normalize($now, ValueInfo::T_STRING)];