Implement an basic search provider. Just search within the title and main note.

On the other hand, it implements consistent urls, which allow you to mark a
note, tag or color as a favorite in the browser to easily access the notes.
This commit is contained in:
Matias De lellis
2021-03-26 00:47:08 -03:00
parent 6bfdd955b1
commit 8f3b9ad73e
4 changed files with 259 additions and 50 deletions

View File

@@ -31,6 +31,34 @@ class NoteMapper extends QBMapper {
return $this->findEntity($qb);
}
/**
* @param string $userId
* @param string $queryStr
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found
* @throws \OCP\AppFramework\Db\MultipleObjectsReturnedException if more than one result
* @return Note[]
*/
public function findLike($userId, $queryStr, $offset = null, $limit = null) {
$qb = $this->db->getQueryBuilder();
$qb->select('*')
->from($this->tableName)
->where($qb->expr()->eq('user_id', $qb->createNamedParameter($userId, IQueryBuilder::PARAM_STR)))
->andWhere(
$qb->expr()->orX(
$qb->expr()->like($qb->func()->lower('title'), $qb->createParameter('query')),
$qb->expr()->like($qb->func()->lower('content'), $qb->createParameter('query'))
)
);
$query = '%' . $this->db->escapeLikeParameter(strtolower($queryStr)) . '%';
$qb->setParameter('query', $query);
$qb->setFirstResult($offset);
$qb->setMaxResults($limit);
return $this->findEntities($qb);
}
/**
* @param int $id
* @throws \OCP\AppFramework\Db\DoesNotExistException if not found