Fixed issue with searching invalid chars and page-content compiliation

This commit is contained in:
Dan Brown 2015-12-29 15:37:13 +00:00
parent 05c4b2089c
commit 445f939822
6 changed files with 22 additions and 10 deletions

View File

@ -115,12 +115,12 @@ abstract class Entity extends Model
{
$termString = '';
foreach ($terms as $term) {
$termString .= $term . '* ';
$termString .= htmlentities($term) . '* ';
}
$fields = implode(',', $fieldsToSearch);
$termStringEscaped = \DB::connection()->getPdo()->quote($termString);
$search = static::addSelect(\DB::raw('*, MATCH(name) AGAINST('.$termStringEscaped.' IN BOOLEAN MODE) AS title_relevance'));
$search = $search->whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termString]);
$search = $search->whereRaw('MATCH(' . $fields . ') AGAINST(? IN BOOLEAN MODE)', [$termStringEscaped]);
// Add additional where terms
foreach ($wheres as $whereTerm) {

View File

@ -222,9 +222,9 @@ class BookRepo
*/
public function getBySearch($term)
{
$terms = explode(' ', preg_quote(trim($term)));
$terms = explode(' ', $term);
$books = $this->book->fullTextSearch(['name', 'description'], $terms);
$words = join('|', $terms);
$words = join('|', explode(' ', preg_quote(trim($term), '/')));
foreach ($books as $book) {
//highlight
$result = preg_replace('#' . $words . '#iu', "<span class=\"highlight\">\$0</span>", $book->getExcerpt(100));

View File

@ -129,9 +129,9 @@ class ChapterRepo
*/
public function getBySearch($term, $whereTerms = [])
{
$terms = explode(' ', preg_quote(trim($term)));
$terms = explode(' ', $term);
$chapters = $this->chapter->fullTextSearch(['name', 'description'], $terms, $whereTerms);
$words = join('|', $terms);
$words = join('|', explode(' ', preg_quote(trim($term), '/')));
foreach ($chapters as $chapter) {
//highlight
$result = preg_replace('#' . $words . '#iu', "<span class=\"highlight\">\$0</span>", $chapter->getExcerpt(100));

View File

@ -177,11 +177,11 @@ class PageRepo
*/
public function getBySearch($term, $whereTerms = [])
{
$terms = explode(' ', preg_quote(trim($term)));
$terms = explode(' ', $term);
$pages = $this->page->fullTextSearch(['name', 'text'], $terms, $whereTerms);
// Add highlights to page text.
$words = join('|', $terms);
$words = join('|', explode(' ', preg_quote(trim($term), '/')));
//lookahead/behind assertions ensures cut between words
$s = '\s\x00-/:-@\[-`{-~'; //character set for start/end of words

View File

@ -1,3 +1,5 @@
<h1 id="bkmrk-page-title">{{$page->name}}</h1>
<div v-pre>
<h1 id="bkmrk-page-title">{{$page->name}}</h1>
{!! $page->html !!}
{!! $page->html !!}
</div>

View File

@ -170,6 +170,16 @@ class EntityTest extends TestCase
->seePageIs($page->getUrl());
}
public function testInvalidPageSearch()
{
$this->asAdmin()
->visit('/')
->type('<p>test</p>', 'term')
->press('header-search-box-button')
->see('Search Results')
->seeStatusCode(200);
}
public function testEntitiesViewableAfterCreatorDeletion()
{