Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
ca457d19
Commit
ca457d19
authored
1 year ago
by
Anton Sattarov
Browse files
Options
Downloads
Patches
Plain Diff
add multi docs
parent
856471e8
Branches
feature/PRXS-1801-FullTextSearchInOneItem
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
search/search.go
+50
-0
50 additions, 0 deletions
search/search.go
search/search_test.go
+24
-7
24 additions, 7 deletions
search/search_test.go
with
74 additions
and
7 deletions
search/search.go
+
50
−
0
View file @
ca457d19
...
...
@@ -52,3 +52,53 @@ func ItemTextSearch(query string, item *items.Item) (*items.Item, []string, erro
return
item
,
fields
,
nil
}
func
ItemsTextSearch
(
query
string
,
itms
[]
*
items
.
Item
)
([]
*
items
.
Item
,
error
)
{
index
,
err
:=
bleve
.
NewMemOnly
(
bleve
.
NewIndexMapping
())
if
err
!=
nil
{
return
nil
,
err
}
im
:=
make
(
map
[
string
]
*
items
.
Item
,
len
(
itms
))
for
_
,
i
:=
range
itms
{
im
[
i
.
ID
]
=
i
if
err
=
index
.
Index
(
i
.
ID
,
i
);
err
!=
nil
{
return
nil
,
err
}
}
searchRequest
:=
bleve
.
NewSearchRequest
(
bleve
.
NewQueryStringQuery
(
query
))
searchRequest
.
Highlight
=
bleve
.
NewHighlight
()
searchResult
,
err
:=
index
.
Search
(
searchRequest
)
if
err
!=
nil
{
return
nil
,
err
}
if
searchResult
.
Total
==
0
{
return
nil
,
errors
.
New
(
"no results found"
)
}
result
:=
make
([]
*
items
.
Item
,
0
,
len
(
searchResult
.
Hits
))
for
_
,
hint
:=
range
searchResult
.
Hits
{
item
,
ok
:=
im
[
hint
.
ID
]
if
!
ok
{
return
nil
,
errors
.
New
(
"search result not match item"
)
}
for
key
,
value
:=
range
hint
.
Fragments
{
key
=
strings
.
TrimPrefix
(
key
,
"data."
)
if
key
==
"id"
{
item
.
Data
[
key
]
=
value
}
if
err
=
item
.
Set
(
key
,
value
);
err
!=
nil
{
return
nil
,
err
}
}
result
=
append
(
result
,
item
)
}
return
result
,
nil
}
This diff is collapsed.
Click to expand it.
search/search_test.go
+
24
−
7
View file @
ca457d19
...
...
@@ -2,13 +2,14 @@ package search
import
(
"encoding/json"
"strconv"
"testing"
"git.perx.ru/perxis/perxis-go/pkg/items"
"github.com/stretchr/testify/require"
)
func
BenchmarkItemTextSearch
(
b
*
testing
.
B
)
{
func
BenchmarkTextSearch
(
b
*
testing
.
B
)
{
jsonStr
:=
`{
"common": {
"environment_id": "cjfmbiaeibkll33i38g0",
...
...
@@ -35,14 +36,30 @@ func BenchmarkItemTextSearch(b *testing.B) {
}
}`
item
:=
&
items
.
Item
{
ID
:
"1"
}
query
:=
"cjfmbiaeibkll33i38fg"
d
:=
map
[
string
]
interface
{}{}
_
=
json
.
Unmarshal
([]
byte
(
jsonStr
),
&
d
)
item
.
Data
=
d
b
.
Run
(
"Item"
,
func
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
_
,
_
,
err
:=
ItemTextSearch
(
query
,
&
items
.
Item
{
ID
:
"1"
,
Data
:
d
})
require
.
NoError
(
b
,
err
)
}
})
var
itms
[]
*
items
.
Item
for
i
:=
0
;
i
<
100
;
i
++
{
itms
=
append
(
itms
,
&
items
.
Item
{
ID
:
strconv
.
Itoa
(
i
),
Data
:
d
})
}
b
.
Run
(
"Items"
,
func
(
b
*
testing
.
B
)
{
b
.
ReportAllocs
()
b
.
ResetTimer
()
for
i
:=
0
;
i
<
b
.
N
;
i
++
{
v
,
f
,
err
:=
ItemTextSearch
(
query
,
it
e
m
)
_
,
_
,
_
=
v
,
f
,
err
_
,
err
:=
Item
s
TextSearch
(
query
,
itm
s
)
require
.
NoError
(
b
,
err
)
}
})
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment