Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
my-yaf-project
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenchuanwen
my-yaf-project
Commits
5f237560
Commit
5f237560
authored
Aug 22, 2018
by
wwccw0591
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
pc
parent
0c2383cd
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
74 additions
and
34 deletions
+74
-34
Search.php
application/controllers/Search.php
+7
-0
SearchService.php
application/models/Business/Search/SearchService.php
+16
-0
ElasticsTool.php
application/models/Elastics/ElasticsTool.php
+33
-34
createIkIndex.php
public/test/Search/createIkIndex.php
+18
-0
No files found.
application/controllers/Search.php
View file @
5f237560
...
...
@@ -11,6 +11,13 @@ class SearchController extends \Our\Controller_AbstractIndex {
$res
=
$serchService
->
createShopKeeperOrders
();
$this
->
success
(
$res
);
}
public
function
createIkIndexAction
()
{
$serchService
=
\Business\Search\SearchServiceModel
::
getInstance
();
$res
=
$serchService
->
createShopKeeperIkOrders
();
$this
->
success
(
$res
);
}
public
function
insertRowAction
()
{
...
...
application/models/Business/Search/SearchService.php
View file @
5f237560
...
...
@@ -25,6 +25,22 @@ class SearchServiceModel extends \Business\AbstractModel
$res
=
$elasticsToolElasticssearch
->
createIndexDetail
();
return
$res
;
}
public
function
createShopKeeperIkOrders
()
{
$elasticsToolElasticssearch
=
\Elastics\ElasticsToolModel
::
getInstance
(
'orders'
);
$delRes
=
$elasticsToolElasticssearch
->
deleteIndex
();
$createRes
=
$elasticsToolElasticssearch
->
createIkField
();
$postData
=
array
(
[
'goodsName'
=>
""闺蜜"崔顺实被韩检方传唤 韩总统府促彻查真相"
],
[
'goodsName'
=>
"韩举行"护国训练" 青瓦台:决不许国家安全出问题"
],
[
'goodsName'
=>
"韩举行"护国训练" 青瓦台:决不许国家安全出问题"
],
[
'goodsName'
=>
"媒体称FBI已经取得搜查令 检视希拉里电邮"
],
[
'goodsName'
=>
"村上春树获安徒生奖 演讲中谈及欧洲排外问题"
],
[
'goodsName'
=>
"希拉里团队炮轰FBI 参院民主党领袖批其“违法”"
],
);
$res
=
$elasticsToolElasticssearch
->
postBulkDoc
(
$postData
);
return
$res
;
}
public
function
insertRows
()
{
...
...
application/models/Elastics/ElasticsTool.php
View file @
5f237560
...
...
@@ -4,6 +4,7 @@ namespace Elastics;
use
Elasticsearch\ClientBuilder
;
use
Error\CodeConfigModel
;
use
Error\ErrorModel
;
use
Our\ApiConst
;
use
Our\NameConst
;
/**
...
...
@@ -152,21 +153,20 @@ class ElasticsToolModel
$response
=
$this
->
client
->
update
(
$updateParams
);
}
public
function
search
(
)
//一般传where就可以了,
public
function
search
Match
(
$where
,
$pageIndex
=
ApiConst
::
pageIndex
,
$pageSize
=
ApiConst
::
pageSize
,
$sort
=
array
(
'_score'
=>
array
(
'order'
=>
'desc'
))
)
{
$searchParams
[
'index'
]
=
'my_index'
;
$searchParams
[
'type'
]
=
'my_index'
;
$
searchParams
[
'from'
]
=
0
;
$searchParams
[
'
size'
]
=
100
;
$searchParams
[
's
ort'
]
=
array
(
'_score'
=>
array
(
'order'
=>
'desc'
)
$searchParams
[
'index'
]
=
$this
->
dbName
;
$searchParams
[
'type'
]
=
$this
->
tbName
;
$
from
=
(
$pageIndex
-
ApiConst
::
one
)
*
$pageSize
;
$searchParams
[
'
from'
]
=
$from
;
$searchParams
[
's
ize'
]
=
$pageSize
;
$searchParams
[
'sort'
]
=
$sort
;
$searchParams
[
'query'
]
=
array
(
'match'
=>
$where
);
// $searchParams['body']['query']['match']['testField'] = 'abc';
$retDoc
=
$this
->
client
->
search
(
$searchParams
);
print_r
(
$retDoc
)
;
return
$retDoc
;
}
public
function
getDocById
(
$id
)
...
...
@@ -243,7 +243,21 @@ class ElasticsToolModel
$res
=
$this
->
client
->
index
(
$params
);
return
$res
;
}
//插入多条 Document:
public
function
postBulkDoc
(
$rows
){
foreach
(
$rows
as
$row
){
$params
[
'body'
][]
=
[
'index'
=>
[
'_index'
=>
$this
->
dbName
,
'_type'
=>
$this
->
tbName
,
]
];
$params
[
'body'
][]
=
$row
;
}
$res
=
$this
->
client
->
bulk
(
$params
);
return
$res
;
}
public
function
createIkField
(){
$params
=
[
'index'
=>
$this
->
dbName
,
//索引名称
...
...
@@ -256,31 +270,16 @@ class ElasticsToolModel
]
)
),
'number_of_replicas'
=>
1
//主分片的副本数
],
'mappings'
=>
[
//映射
'_default_'
=>
[
//默认配置,每个类型缺省的配置使用默认配置
'
_source
'
=>
[
// 存储原始文档
$this
->
tbName
=>
[
//默认配置,每个类型缺省的配置使用默认配置
'
dynamic
'
=>
[
// 存储原始文档
'enabled'
=>
'true'
],
'properties'
=>
[
//配置数据结构与类型
'name'
=>
[
//字段1
'type'
=>
'string'
,
//类型 string、integer、float、double、boolean、date
'index'
=>
'analyzed'
,
//索引是否精确值 analyzed not_analyzed
],
'age'
=>
[
//字段2
'type'
=>
'integer'
,
],
'sex'
=>
[
//字段3
'type'
=>
'string'
,
'index'
=>
'not_analyzed'
,
],
]
],
$this
->
tbName
=>
[
'properties'
=>
[
'phone'
=>
[
'type'
=>
'string'
,
'goodsName'
=>
[
//字段1
"type"
=>
"string"
,
"analyzer"
=>
"ik_max_word"
],
]
],
...
...
@@ -305,7 +304,7 @@ class ElasticsToolModel
]
]
];
$res
=
$this
->
es
->
indices
()
->
putMapping
(
$params
);
$res
=
$this
->
client
->
indices
()
->
putMapping
(
$params
);
return
$res
;
}
...
...
@@ -318,7 +317,7 @@ class ElasticsToolModel
'query'
=>
$query
]
];
$res
=
$this
->
es
->
search
(
$params
);
$res
=
$this
->
client
->
search
(
$params
);
return
$res
;
}
//查看mapping
...
...
public/test/Search/createIkIndex.php
0 → 100644
View file @
5f237560
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html
xmlns=
"http://www.w3.org/1999/xhtml"
>
<head>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<title>
简单的html5 File测试 for pic2base64
</title>
<style>
</style>
</head>
<body>
<form
action=
"/search/createIkIndex"
method=
"post"
>
用户登录状态key:
<input
name=
"data[key]"
value=
"52da049f7e2fbf0e10da32dfe909850e"
/><br
/>
<p
id=
"img_area"
></p>
<input
type=
"submit"
value=
"提交"
>
</form>
</body>
</html>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment