-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
232 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 16/7/24 | ||
* Time: 下午10:53 | ||
*/ | ||
|
||
namespace common\behaviors; | ||
|
||
|
||
use common\models\Article; | ||
use common\models\Search; | ||
use yii\base\Behavior; | ||
use yii\db\ActiveRecord; | ||
|
||
class XsBehavior extends Behavior | ||
{ | ||
public function events() | ||
{ | ||
return [ | ||
ActiveRecord::EVENT_AFTER_INSERT => [$this, 'afterSaveInternal'], | ||
ActiveRecord::EVENT_AFTER_UPDATE => [$this, 'afterSaveInternal'] | ||
]; | ||
} | ||
|
||
public function afterSaveInternal($event) | ||
{ | ||
$article = Article::findOne(['id' => $event->sender->id]); | ||
if (!empty($article)) { | ||
if ($event->name == 'afterInsert') { | ||
$search = new Search(); | ||
$search->article_id = $event->sender->id; | ||
$search->status = Article::STATUS_ACTIVE; | ||
} else { | ||
$search = Search::findOne($event->sender->id); | ||
$search->status = $article->status; | ||
} | ||
$search->title = $article->title; | ||
$search->content = $event->sender->content; | ||
$search->updated_at = $article->updated_at; | ||
$search->save(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
project.name = yii2cmf | ||
project.default_charset = utf-8 | ||
server.index = 8383 | ||
server.search = 8384 | ||
|
||
[article_id] | ||
type = id | ||
|
||
[title] | ||
type = title | ||
|
||
[content] | ||
type = body | ||
|
||
[status] | ||
index = self | ||
tokenizer = full | ||
|
||
[updated_at] | ||
type = numeric |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 16/7/24 | ||
* Time: 下午8:13 | ||
*/ | ||
|
||
namespace common\models; | ||
|
||
|
||
use hightman\xunsearch\ActiveRecord; | ||
use yii\data\ActiveDataProvider; | ||
|
||
class Search extends ActiveRecord | ||
{ | ||
public function search($q) | ||
{ | ||
$query = self::find()->where($q)->andWhere(['status' => 1]); | ||
$dataProvider = new ActiveDataProvider([ | ||
'query' => $query, | ||
'sort' => [ | ||
'defaultOrder' => [ | ||
'updated_at' => SORT_DESC, | ||
] | ||
] | ||
]); | ||
|
||
return $dataProvider; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
/** | ||
* Created by PhpStorm. | ||
* User: yidashi | ||
* Date: 16/7/24 | ||
* Time: 下午9:57 | ||
*/ | ||
|
||
namespace frontend\components; | ||
|
||
|
||
use common\models\Article; | ||
use yii\base\Component; | ||
use common\models\Search as SearchModel; | ||
use yii\data\ActiveDataProvider; | ||
|
||
class Search extends Component | ||
{ | ||
public function search($q) | ||
{ | ||
$search = new SearchModel(); | ||
return $search->search($q); | ||
} | ||
|
||
/** | ||
* 如果不用迅搜,则替换这个方法 | ||
*/ | ||
/*public function search($q) | ||
{ | ||
return new ActiveDataProvider([ | ||
'query' => Article::find()->published()->andWhere(['like', 'title', $q]) | ||
]); | ||
}*/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters