Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Sharkey
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Essem
Sharkey
Commits
40f5e67f
Commit
40f5e67f
authored
7 years ago
by
こぴなたみぽ
Browse files
Options
Downloads
Patches
Plain Diff
✌️
parent
143a3029
No related branches found
Branches containing commit
Tags
8.19.0
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/api/endpoints/posts/search.ts
+100
-30
100 additions, 30 deletions
src/api/endpoints/posts/search.ts
src/web/app/common/scripts/parse-search-query.ts
+5
-2
5 additions, 2 deletions
src/web/app/common/scripts/parse-search-query.ts
src/web/docs/search.ja.pug
+26
-3
26 additions, 3 deletions
src/web/docs/search.ja.pug
with
131 additions
and
35 deletions
src/api/endpoints/posts/search.ts
+
100
−
30
View file @
40f5e67f
...
...
@@ -34,13 +34,17 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
const
[
following
=
null
,
followingErr
]
=
$
(
params
.
following
).
optional
.
nullable
.
boolean
().
$
;
if
(
followingErr
)
return
rej
(
'
invalid following param
'
);
// Get '
include_
repl
ies
' parameter
const
[
includeReplies
=
true
,
includeReplies
Err
]
=
$
(
params
.
include_
repl
ies
).
optional
.
boolean
().
$
;
if
(
includeReplies
Err
)
return
rej
(
'
invalid
include_
repl
ies
param
'
);
// Get 'repl
y
' parameter
const
[
reply
=
null
,
reply
Err
]
=
$
(
params
.
repl
y
).
optional
.
nullable
.
boolean
().
$
;
if
(
reply
Err
)
return
rej
(
'
invalid repl
y
param
'
);
// Get 'with_media' parameter
const
[
withMedia
=
false
,
withMediaErr
]
=
$
(
params
.
with_media
).
optional
.
boolean
().
$
;
if
(
withMediaErr
)
return
rej
(
'
invalid with_media param
'
);
// Get 'repost' parameter
const
[
repost
=
null
,
repostErr
]
=
$
(
params
.
repost
).
optional
.
nullable
.
boolean
().
$
;
if
(
repostErr
)
return
rej
(
'
invalid repost param
'
);
// Get 'media' parameter
const
[
media
=
null
,
mediaErr
]
=
$
(
params
.
media
).
optional
.
nullable
.
boolean
().
$
;
if
(
mediaErr
)
return
rej
(
'
invalid media param
'
);
// Get 'since_date' parameter
const
[
sinceDate
,
sinceDateErr
]
=
$
(
params
.
since_date
).
optional
.
number
().
$
;
...
...
@@ -72,53 +76,119 @@ module.exports = (params, me) => new Promise(async (res, rej) => {
// If Elasticsearch is available, search by it
// If not, search by MongoDB
(
config
.
elasticsearch
.
enable
?
byElasticsearch
:
byNative
)
(
res
,
rej
,
me
,
text
,
user
,
following
,
includeReplies
,
withM
edia
,
sinceDate
,
untilDate
,
offset
,
limit
);
(
res
,
rej
,
me
,
text
,
user
,
following
,
reply
,
repost
,
m
edia
,
sinceDate
,
untilDate
,
offset
,
limit
);
});
// Search by MongoDB
async
function
byNative
(
res
,
rej
,
me
,
text
,
userId
,
following
,
includeReplies
,
withMedia
,
sinceDate
,
untilDate
,
offset
,
max
)
{
const
q
:
any
=
{};
async
function
byNative
(
res
,
rej
,
me
,
text
,
userId
,
following
,
reply
,
repost
,
media
,
sinceDate
,
untilDate
,
offset
,
max
)
{
const
q
:
any
=
{
$and
:
[]
};
const
push
=
q
.
$and
.
push
;
if
(
text
)
{
q
.
$and
=
text
.
split
(
'
'
).
map
(
x
=>
({
text
:
new
RegExp
(
escapeRegexp
(
x
))
}));
push
({
$and
:
text
.
split
(
'
'
).
map
(
x
=>
({
text
:
new
RegExp
(
escapeRegexp
(
x
))
}))
});
}
if
(
userId
)
{
q
.
user_id
=
userId
;
push
({
user_id
:
userId
});
}
if
(
following
!=
null
)
{
const
ids
=
await
getFriends
(
me
.
_id
,
false
);
q
.
user_id
=
{};
if
(
following
)
{
q
.
user_id
.
$in
=
ids
;
push
({
user_id
:
following
?
{
$in
:
ids
}
:
{
$nin
:
ids
}
});
}
if
(
reply
!=
null
)
{
if
(
reply
)
{
push
({
reply_id
:
{
$exists
:
true
,
$ne
:
null
}
});
}
else
{
q
.
user_id
.
$nin
=
ids
;
push
({
$or
:
[{
reply_id
:
{
$exists
:
false
}
},
{
reply_id
:
null
}]
});
}
}
if
(
!
includeReplies
)
{
q
.
reply_id
=
null
;
if
(
repost
!=
null
)
{
if
(
repost
)
{
push
({
repost_id
:
{
$exists
:
true
,
$ne
:
null
}
});
}
else
{
push
({
$or
:
[{
repost_id
:
{
$exists
:
false
}
},
{
repost_id
:
null
}]
});
}
}
if
(
withMedia
)
{
q
.
media_ids
=
{
$exists
:
true
,
$ne
:
null
};
if
(
media
!=
null
)
{
if
(
media
)
{
push
({
media_ids
:
{
$exists
:
true
,
$ne
:
null
}
});
}
else
{
push
({
$or
:
[{
media_ids
:
{
$exists
:
false
}
},
{
media_ids
:
null
}]
});
}
}
if
(
sinceDate
)
{
q
.
created_at
=
{
$gt
:
new
Date
(
sinceDate
)
};
push
({
created_at
:
{
$gt
:
new
Date
(
sinceDate
)
}
});
}
if
(
untilDate
)
{
if
(
q
.
created_at
==
undefined
)
q
.
created_at
=
{};
q
.
created_at
.
$lt
=
new
Date
(
untilDate
);
push
({
created_at
:
{
$lt
:
new
Date
(
untilDate
)
}
});
}
// Search posts
...
...
@@ -137,7 +207,7 @@ async function byNative(res, rej, me, text, userId, following, includeReplies, w
}
// Search by Elasticsearch
async
function
byElasticsearch
(
res
,
rej
,
me
,
text
,
userId
,
following
,
includeReplies
,
withM
edia
,
sinceDate
,
untilDate
,
offset
,
max
)
{
async
function
byElasticsearch
(
res
,
rej
,
me
,
text
,
userId
,
following
,
reply
,
repost
,
m
edia
,
sinceDate
,
untilDate
,
offset
,
max
)
{
const
es
=
require
(
'
../../db/elasticsearch
'
);
es
.
search
({
...
...
This diff is collapsed.
Click to expand it.
src/web/app/common/scripts/parse-search-query.ts
+
5
−
2
View file @
40f5e67f
...
...
@@ -14,10 +14,13 @@ export default function(qs: string) {
q
[
'
following
'
]
=
value
==
'
null
'
?
null
:
value
==
'
true
'
;
break
;
case
'
reply
'
:
q
[
'
include_replies
'
]
=
value
==
'
true
'
;
q
[
'
reply
'
]
=
value
==
'
null
'
?
null
:
value
==
'
true
'
;
break
;
case
'
repost
'
:
q
[
'
repost
'
]
=
value
==
'
null
'
?
null
:
value
==
'
true
'
;
break
;
case
'
media
'
:
q
[
'
with_
media
'
]
=
value
==
'
true
'
;
q
[
'
media
'
]
=
value
==
'
null
'
?
null
:
value
==
'
true
'
;
break
;
case
'
until
'
:
case
'
since
'
:
...
...
This diff is collapsed.
Click to expand it.
src/web/docs/search.ja.pug
+
26
−
3
View file @
40f5e67f
...
...
@@ -23,13 +23,36 @@ section
td ユーザー名。投稿者を限定します。
tr
td follow
td フォローしているユーザーのみに限定。(trueかfalse)
td
| true ... フォローしているユーザーに限定。
br
| false ... フォローしていないユーザーに限定。
br
| null ... 特に限定しない(デフォルト)
tr
td reply
td 返信を含めるか否か。(trueかfalse)
td
| true ... 返信に限定。
br
| false ... 返信でない投稿に限定。
br
| null ... 特に限定しない(デフォルト)
tr
td repost
td
| true ... Repostに限定。
br
| false ... Repostでない投稿に限定。
br
| null ... 特に限定しない(デフォルト)
tr
td media
td メディアが添付されているか。(trueかfalse)
td
| true ... メディアが添付されている投稿に限定。
br
| false ... メディアが添付されていない投稿に限定。
br
| null ... 特に限定しない(デフォルト)
tr
td until
td 上限の日時。(YYYY-MM-DD)
...
...
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