Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
X
xwiki-platform
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
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
XWiki
xwiki-platform
Commits
5f8684dc
Commit
5f8684dc
authored
6 years ago
by
Adel Atallah
Browse files
Options
Downloads
Patches
Plain Diff
XWIKI-15568: Create a generic page picker
* Improve the Page search by making only one HQL query.
parent
a85dc84c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/BaseSearchResult.java
+29
-42
29 additions, 42 deletions
...a/org/xwiki/rest/internal/resources/BaseSearchResult.java
with
29 additions
and
42 deletions
xwiki-platform-core/xwiki-platform-rest/xwiki-platform-rest-server/src/main/java/org/xwiki/rest/internal/resources/BaseSearchResult.java
+
29
−
42
View file @
5f8684dc
...
...
@@ -153,10 +153,8 @@ protected List<SearchResult> searchPages(List<SearchScope> searchScopes, String
/* This try is just needed for executing the finally clause. */
try
{
List
<
SearchResult
>
result
=
new
ArrayList
<
SearchResult
>();
if
(
keywords
==
null
)
{
return
result
;
return
new
ArrayList
<>()
;
}
Formatter
f
=
new
Formatter
();
...
...
@@ -173,11 +171,11 @@ protected List<SearchResult> searchPages(List<SearchScope> searchScopes, String
}
if
(
space
!=
null
)
{
f
.
format
(
"select distinct doc.fullName, doc.space, doc.name, doc.language"
);
f
.
format
(
"select distinct doc.fullName, doc.space, doc.name, doc.language
, doc.defaultLanguage
"
);
f
.
format
(
addColumn
);
f
.
format
(
" from XWikiDocument as doc where doc.space = :space and ( "
);
}
else
{
f
.
format
(
"select distinct doc.fullName, doc.space, doc.name, doc.language"
);
f
.
format
(
"select distinct doc.fullName, doc.space, doc.name, doc.language
, doc.defaultLanguage
"
);
f
.
format
(
addColumn
);
f
.
format
(
" from XWikiDocument as doc where ( "
);
}
...
...
@@ -209,16 +207,11 @@ protected List<SearchResult> searchPages(List<SearchScope> searchScopes, String
/* If we don't find any scope related to pages then return empty results */
if
(
acceptedScopes
==
0
)
{
return
result
;
return
new
ArrayList
<>()
;
}
f
.
format
(
") "
);
if
(
isLocaleAware
)
{
// The language of the default document is always "" and its default language is the actual language
f
.
format
(
"and (doc.language = :language or (doc.language = '' and doc.defaultLanguage = :language)) "
);
}
/* Build the order clause. */
String
orderClause
=
null
;
if
(
StringUtils
.
isBlank
(
orderField
))
{
...
...
@@ -233,19 +226,34 @@ protected List<SearchResult> searchPages(List<SearchScope> searchScopes, String
}
// Add ordering
f
.
format
(
"order by %s"
,
orderClause
);
if
(
isLocaleAware
)
{
// 1) Search pages using the user locale (e.g. fr_CA)
// 2) Search pages using the user language (e.g. if locale = fr_CA then language = fr)
// 3) Search pages using their default language
// 4) Search remaining pages
// Note: The language of the default document is always "" and its default language is the real language
orderClause
=
"case"
+
" when (doc.language = :locale or (doc.language = '' and doc.defaultLanguage ="
+
" :locale)) then '0'"
+
" when (doc.language = :language or (doc.language = '' and doc.defaultLanguage ="
+
" :language)) then '1'"
+
" when doc.language = '' then '2'"
+
" else '3'"
+
" end, "
+
orderClause
;
}
f
.
format
(
"order by %s"
,
orderClause
);
String
queryString
=
f
.
toString
();
Locale
userLocale
=
contextProvider
.
get
().
getLocale
();
String
locale
=
userLocale
.
toString
();
String
language
=
userLocale
.
getLanguage
();
Set
<
String
>
seenPages
=
new
HashSet
<>();
int
limit
=
number
;
Query
query
=
this
.
queryManager
.
createQuery
(
queryString
,
Query
.
XW
QL
)
Query
query
=
this
.
queryManager
.
createQuery
(
queryString
,
Query
.
H
QL
)
.
bindValue
(
"keywords"
,
String
.
format
(
"%%%s%%"
,
keywords
.
toUpperCase
()))
.
addFilter
(
Utils
.
getHiddenQueryFilter
(
this
.
componentManager
)).
setOffset
(
start
).
setLimit
(
number
);
.
addFilter
(
Utils
.
getHiddenQueryFilter
(
this
.
componentManager
)).
setOffset
(
start
)
.
setLimit
(
number
*
4
);
// Worst case scenario when making the locale aware query (see above)
if
(
space
!=
null
)
{
query
.
bindValue
(
"space"
,
space
);
...
...
@@ -253,31 +261,11 @@ protected List<SearchResult> searchPages(List<SearchScope> searchScopes, String
// Search only pages translated in the user locale (e.g. fr_CA)
if
(
isLocaleAware
)
{
query
.
bindValue
(
"language"
,
locale
);
}
result
.
addAll
(
getPagesSearchResults
(
query
.
execute
(),
wikiName
,
withPrettyNames
,
limit
,
isLocaleAware
,
seenPages
));
limit
=
number
-
result
.
size
();
// Search pages with the user language (e.g. if locale = fr_CA then language = fr)
if
(
limit
>
0
&&
isLocaleAware
&&
!
locale
.
equals
(
language
))
{
query
.
bindValue
(
"locale"
,
locale
);
query
.
bindValue
(
"language"
,
language
);
query
.
setLimit
(
limit
);
result
.
addAll
(
getPagesSearchResults
(
query
.
execute
(),
wikiName
,
withPrettyNames
,
limit
,
isLocaleAware
,
seenPages
));
limit
=
number
-
result
.
size
();
}
// Search pages with their default language
if
(
limit
>
0
&&
isLocaleAware
)
{
query
.
bindValue
(
"language"
,
""
);
query
.
setLimit
(
limit
);
result
.
addAll
(
getPagesSearchResults
(
query
.
execute
(),
wikiName
,
withPrettyNames
,
limit
,
isLocaleAware
,
seenPages
));
}
return
result
;
return
getPagesSearchResults
(
query
.
execute
(),
wikiName
,
withPrettyNames
,
number
,
isLocaleAware
)
;
}
finally
{
Utils
.
getXWikiContext
(
componentManager
).
setWikiId
(
database
);
}
...
...
@@ -290,16 +278,15 @@ protected List<SearchResult> searchPages(List<SearchScope> searchScopes, String
* @param wikiName the wiki name
* @param withPrettyNames render the author name
* @param limit the maximum number of results
* @param withUniquePages only add none seen pages
* @param seenPages seen pages names
* @param withUniquePages add pages only once
* @return the list of {@link SearchResult}
* @throws XWikiException
*/
protected
List
<
SearchResult
>
getPagesSearchResults
(
List
<
Object
>
queryResult
,
String
wikiName
,
Boolean
withPrettyNames
,
int
limit
,
Boolean
withUniquePages
,
Set
<
String
>
seenPages
)
throws
XWikiException
Boolean
withPrettyNames
,
int
limit
,
Boolean
withUniquePages
)
throws
XWikiException
{
List
<
SearchResult
>
result
=
new
ArrayList
<>();
Set
<
String
>
seenPages
=
new
HashSet
<>();
XWiki
xwikiApi
=
Utils
.
getXWikiApi
(
componentManager
);
for
(
Object
object
:
queryResult
)
{
...
...
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