| ... |
... |
@@ -1,5 +1,5 @@ |
| 1 |
|
-{{html clean="false"}} |
| 2 |
|
-<!-- |
|
1 |
+ |
|
2 |
+{{html clean="false"}}<!-- |
| 3 |
3 |
!!! POC. Code must be reviewed / optimized and packaged for use in production !!! |
| 4 |
4 |
!!! Many optimisations can be done !!! |
| 5 |
5 |
--> |
| ... |
... |
@@ -27,16 +27,6 @@ |
| 27 |
27 |
a { |
| 28 |
28 |
color: var(--color-brand-primary, blue); |
| 29 |
29 |
} |
| 30 |
|
- .rawResults { |
| 31 |
|
- width: 100%; |
| 32 |
|
- display: flex; |
| 33 |
|
- font-size: 12px; |
| 34 |
|
- margin-top: 2em; |
| 35 |
|
- } |
| 36 |
|
- .rawResults ul { |
| 37 |
|
- list-style-type: none; |
| 38 |
|
- padding: 0; |
| 39 |
|
- } |
| 40 |
40 |
`; |
| 41 |
41 |
constructor() { |
| 42 |
42 |
super(); |
| ... |
... |
@@ -49,7 +49,8 @@ |
| 49 |
49 |
this.filterUrl = new URL(`${document.location.origin}/rest/v1/collabs?search=&offset=0&orderField=title&order=asc&limit=10000&favorite=false&roles=`); |
| 50 |
50 |
this.results = []; |
| 51 |
51 |
this.resultsCache = []; |
| 52 |
|
- this.collabFiltersResults = []; |
|
42 |
+ this.offset = 0; |
|
43 |
+ this.nb = 10; |
| 53 |
53 |
} |
| 54 |
54 |
firstUpdated() { |
| 55 |
55 |
this.renderRoot.getElementById('searchInput').focus(); |
| ... |
... |
@@ -67,6 +67,12 @@ |
| 67 |
67 |
setSearchText(e) { |
| 68 |
68 |
this.searchText = e.target.value; |
| 69 |
69 |
} |
|
61 |
+ setOffset(e) { |
|
62 |
+ this.offset = e.target.value; |
|
63 |
+ } |
|
64 |
+ setNb(e) { |
|
65 |
+ this.nb = e.target.value; |
|
66 |
+ } |
| 70 |
70 |
handleSearch(textSearch) { |
| 71 |
71 |
if(this.searchText !== "" || textSearch) { |
| 72 |
72 |
if(this.searchText !== this.prevSearchText) { |
| ... |
... |
@@ -99,15 +99,12 @@ |
| 99 |
99 |
} |
| 100 |
100 |
fetchWikiSearch() { |
| 101 |
101 |
// request should be built from component, not from "external" dependency. Leave it here like this for POC. |
| 102 |
|
- return handleXWikiSearch(this.searchText); |
|
99 |
+ return handleXWikiSearch(this.searchText, this.offset, this.nb); |
| 103 |
103 |
} |
| 104 |
104 |
fetchFilterSearch() { |
| 105 |
105 |
return new Promise((resolve) => { |
| 106 |
106 |
if(this.hasActiveFilters()) { |
| 107 |
|
- fetch(this.filterUrl).then(res => res.json()).then((res) => { |
| 108 |
|
- this.collabFiltersResults = res; |
| 109 |
|
- resolve(res); |
| 110 |
|
- }); |
|
104 |
+ fetch(this.filterUrl).then(res => res.json()).then((res) => resolve(res)); |
| 111 |
111 |
} else { |
| 112 |
112 |
resolve([]); |
| 113 |
113 |
} |
| ... |
... |
@@ -134,6 +134,8 @@ |
| 134 |
134 |
<div> |
| 135 |
135 |
<div> |
| 136 |
136 |
<input id="searchInput" @change="${this.setSearchText}" type="text" placeholder="Search..." @keypress="${this.handleKeyPress}" /> |
|
131 |
+ <input @change="${this.setNb}"" type="text" value="${this.nb}" /> |
|
132 |
+ <input @change="${this.setOffset}"" type="text" value="${this.offset}" /> |
| 137 |
137 |
<button @click="${() => this.handleSearch(true)}">Search</button> |
| 138 |
138 |
</div> |
| 139 |
139 |
<div> |
| ... |
... |
@@ -150,17 +150,6 @@ |
| 150 |
150 |
</div> |
| 151 |
151 |
`)} |
| 152 |
152 |
</div> |
| 153 |
|
- <div class="rawResults"> |
| 154 |
|
- <div> |
| 155 |
|
- <strong>XWiki Search Results</strong> |
| 156 |
|
- <ul>${this.resultsCache.map((res) => html`<li>${res.space}</li>`)}</ul> |
| 157 |
|
- </div> |
| 158 |
|
- <div> |
| 159 |
|
- <strong>Collab Search Results (Filters)</strong> |
| 160 |
|
- <ul>${this.collabFiltersResults.map((res) => html`<li>${res.name}</li>`)}</ul> |
| 161 |
|
- </div> |
| 162 |
|
- </div> |
| 163 |
|
-</div> |
| 164 |
164 |
` |
| 165 |
165 |
} |
| 166 |
166 |
} |
| ... |
... |
@@ -171,9 +171,11 @@ |
| 171 |
171 |
require(['jquery'], function($) { |
| 172 |
172 |
const solrServiceURL = new XWiki.Document('SuggestSolrService', 'XWiki').getURL('get'); |
| 173 |
173 |
//contextSearchButton.addEventListener('click', function() { |
| 174 |
|
- $.post(solrServiceURL, { |
|
159 |
+ $.get(solrServiceURL, { |
| 175 |
175 |
outputSyntax: 'plain', |
| 176 |
176 |
media: 'json', |
|
162 |
+ nb:100, |
|
163 |
+ offset:10, |
| 177 |
177 |
query: [ |
| 178 |
178 |
'q="__INPUT__"~100', |
| 179 |
179 |
'fq=type:DOCUMENT', |
| ... |
... |
@@ -187,5 +187,4 @@ |
| 187 |
187 |
} |
| 188 |
188 |
}); |
| 189 |
189 |
</script> |
| 190 |
|
-<clb-unified-search></clb-unified-search> |
| 191 |
|
-{{/html}} |
|
177 |
+<clb-unified-search></clb-unified-search>{{/html}} |