Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2015-12-05 15:11:48 +0000
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
46c905df8a65b9b38274d7580f70c739457acb31
46c905df
1 parent
c32d70ab
Added search name weighting. Closes #27.
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
9 deletions
app/Entity.php
database/migrations/2015_12_05_145049_fulltext_weighting.php
app/Entity.php
View file @
46c905d
...
...
@@ -134,20 +134,20 @@ abstract class Entity extends Model
$termString
.=
$term
.
'* '
;
}
$fields
=
implode
(
','
,
$fieldsToSearch
);
$search
=
static
::
whereRaw
(
'MATCH('
.
$fields
.
') AGAINST(? IN BOOLEAN MODE)'
,
[
$termString
]);
$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
]);
// Add additional where terms
foreach
(
$wheres
as
$whereTerm
)
{
$search
->
where
(
$whereTerm
[
0
],
$whereTerm
[
1
],
$whereTerm
[
2
]);
}
if
(
!
static
::
isA
(
'book'
))
{
$search
=
$search
->
with
(
'book'
);
}
if
(
static
::
isA
(
'page'
))
{
$search
=
$search
->
with
(
'chapter'
);
}
// Load in relations
if
(
!
static
::
isA
(
'book'
))
$search
=
$search
->
with
(
'book'
);
if
(
static
::
isA
(
'page'
))
$search
=
$search
->
with
(
'chapter'
);
return
$search
->
get
();
return
$search
->
orderBy
(
'title_relevance'
,
'desc'
)
->
get
();
}
/**
...
...
database/migrations/2015_12_05_145049_fulltext_weighting.php
0 → 100644
View file @
46c905d
<?php
use
Illuminate\Database\Schema\Blueprint
;
use
Illuminate\Database\Migrations\Migration
;
class
FulltextWeighting
extends
Migration
{
/**
* Run the migrations.
*
* @return void
*/
public
function
up
()
{
DB
::
statement
(
'ALTER TABLE pages ADD FULLTEXT name_search(name)'
);
DB
::
statement
(
'ALTER TABLE books ADD FULLTEXT name_search(name)'
);
DB
::
statement
(
'ALTER TABLE chapters ADD FULLTEXT name_search(name)'
);
}
/**
* Reverse the migrations.
*
* @return void
*/
public
function
down
()
{
Schema
::
table
(
'pages'
,
function
(
Blueprint
$table
)
{
$table
->
dropIndex
(
'name_search'
);
});
Schema
::
table
(
'books'
,
function
(
Blueprint
$table
)
{
$table
->
dropIndex
(
'name_search'
);
});
Schema
::
table
(
'chapters'
,
function
(
Blueprint
$table
)
{
$table
->
dropIndex
(
'name_search'
);
});
}
}
Please
register
or
sign in
to post a comment