mirror of
https://code.mensbeam.com/MensBeam/Arsse.git
synced 2024-12-23 09:02:41 +00:00
Add ability to search note text
This commit is contained in:
parent
bc3182a961
commit
2df7c25b66
5 changed files with 41 additions and 7 deletions
|
@ -1184,18 +1184,18 @@ class Database {
|
||||||
if ($context->editions()) {
|
if ($context->editions()) {
|
||||||
// if multiple specific editions have been requested, filter against the list
|
// if multiple specific editions have been requested, filter against the list
|
||||||
if (!$context->editions) {
|
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) {
|
} 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");
|
list($inParams, $inTypes) = $this->generateIn($context->editions, "int");
|
||||||
$q->setWhere("latest_editions.edition in ($inParams)", $inTypes, $context->editions);
|
$q->setWhere("latest_editions.edition in ($inParams)", $inTypes, $context->editions);
|
||||||
} elseif ($context->articles()) {
|
} elseif ($context->articles()) {
|
||||||
// if multiple specific articles have been requested, filter against the list
|
// if multiple specific articles have been requested, filter against the list
|
||||||
if (!$context->articles) {
|
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) {
|
} 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");
|
list($inParams, $inTypes) = $this->generateIn($context->articles, "int");
|
||||||
$q->setWhere("arsse_articles.id in ($inParams)", $inTypes, $context->articles);
|
$q->setWhere("arsse_articles.id in ($inParams)", $inTypes, $context->articles);
|
||||||
|
@ -1255,12 +1255,21 @@ class Database {
|
||||||
// filter based on search terms
|
// filter based on search terms
|
||||||
if ($context->searchTerms()) {
|
if ($context->searchTerms()) {
|
||||||
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) {
|
} 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"]));
|
$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 the query
|
||||||
return $q;
|
return $q;
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ class Context {
|
||||||
public $labelName;
|
public $labelName;
|
||||||
public $labelled = null;
|
public $labelled = null;
|
||||||
public $annotated = null;
|
public $annotated = null;
|
||||||
|
public $annotationTerms = null;
|
||||||
public $searchTerms = null;
|
public $searchTerms = null;
|
||||||
|
|
||||||
protected $props = [];
|
protected $props = [];
|
||||||
|
@ -184,6 +185,13 @@ class Context {
|
||||||
return $this->act(__FUNCTION__, func_num_args(), $spec);
|
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) {
|
public function searchTerms(array $spec = null) {
|
||||||
if (isset($spec)) {
|
if (isset($spec)) {
|
||||||
$spec = $this->cleanStringArray($spec);
|
$spec = $this->cleanStringArray($spec);
|
||||||
|
|
|
@ -497,6 +497,11 @@ trait SeriesArticle {
|
||||||
// get items that match search terms
|
// get items that match search terms
|
||||||
$compareIds([1,2,3], (new Context)->searchTerms(["Article"]));
|
$compareIds([1,2,3], (new Context)->searchTerms(["Article"]));
|
||||||
$compareIds([1], (new Context)->searchTerms(["one", "first"]));
|
$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() {
|
public function testListArticlesOfAMissingFolder() {
|
||||||
|
@ -998,4 +1003,14 @@ trait SeriesArticle {
|
||||||
$this->assertException("tooLong", "Db", "ExceptionInput");
|
$this->assertException("tooLong", "Db", "ExceptionInput");
|
||||||
Arsse::$db->articleList($this->user, (new Context)->searchTerms(range(1, 105)));
|
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)));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,6 +94,7 @@ abstract class BaseDriver extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
public function testTranslateAToken() {
|
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("greatest"));
|
||||||
$this->assertRegExp("/^\"?[a-z][a-z0-9_\-]*\"?$/i", $this->drv->sqlToken("nocase"));
|
$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"));
|
$this->assertSame("distinct", $this->drv->sqlToken("distinct"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -50,6 +50,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
'labelled' => true,
|
'labelled' => true,
|
||||||
'annotated' => true,
|
'annotated' => true,
|
||||||
'searchTerms' => ["foo", "bar"],
|
'searchTerms' => ["foo", "bar"],
|
||||||
|
'annotationTerms' => ["foo", "bar"],
|
||||||
];
|
];
|
||||||
$times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince'];
|
$times = ['modifiedSince','notModifiedSince','markedSince','notMarkedSince'];
|
||||||
$c = new Context;
|
$c = new Context;
|
||||||
|
@ -83,7 +84,7 @@ class TestContext extends \JKingWeb\Arsse\Test\AbstractTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testCleanStringArrayValues() {
|
public function testCleanStringArrayValues() {
|
||||||
$methods = ["searchTerms"];
|
$methods = ["searchTerms", "annotationTerms"];
|
||||||
$now = new \DateTime;
|
$now = new \DateTime;
|
||||||
$in = [1, 3.0, "ook", 0, true, false, null, $now, ""];
|
$in = [1, 3.0, "ook", 0, true, false, null, $now, ""];
|
||||||
$out = ["1", "3", "ook", "0", valueInfo::normalize($now, ValueInfo::T_STRING)];
|
$out = ["1", "3", "ook", "0", valueInfo::normalize($now, ValueInfo::T_STRING)];
|
||||||
|
|
Loading…
Reference in a new issue