| ... |
... |
@@ -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,11 +27,6 @@ |
| 27 |
27 |
a { |
| 28 |
28 |
color: var(--color-brand-primary, blue); |
| 29 |
29 |
} |
| 30 |
|
- .rawResults { |
| 31 |
|
- display: flex; |
| 32 |
|
- font-size: 12px; |
| 33 |
|
- margin-top: 2em; |
| 34 |
|
- } |
| 35 |
35 |
`; |
| 36 |
36 |
constructor() { |
| 37 |
37 |
super(); |
| ... |
... |
@@ -44,6 +44,8 @@ |
| 44 |
44 |
this.filterUrl = new URL(`${document.location.origin}/rest/v1/collabs?search=&offset=0&orderField=title&order=asc&limit=10000&favorite=false&roles=`); |
| 45 |
45 |
this.results = []; |
| 46 |
46 |
this.resultsCache = []; |
|
42 |
+ this.offset = 0; |
|
43 |
+ this.nb = 10; |
| 47 |
47 |
} |
| 48 |
48 |
firstUpdated() { |
| 49 |
49 |
this.renderRoot.getElementById('searchInput').focus(); |
| ... |
... |
@@ -61,24 +61,31 @@ |
| 61 |
61 |
setSearchText(e) { |
| 62 |
62 |
this.searchText = e.target.value; |
| 63 |
63 |
} |
|
61 |
+ setOffset(e) { |
|
62 |
+ this.offset = e.target.value; |
|
63 |
+ } |
|
64 |
+ setNb(e) { |
|
65 |
+ this.nb = e.target.value; |
|
66 |
+ } |
| 64 |
64 |
handleSearch(textSearch) { |
| 65 |
65 |
if(this.searchText !== "" || textSearch) { |
| 66 |
|
- if(this.searchText !== this.prevSearchText) { |
|
69 |
+ // if(this.searchText !== this.prevSearchText) { |
| 67 |
67 |
this.clearResults(); |
| 68 |
68 |
this.prevSearchText = this.searchText; |
| 69 |
69 |
this.fetchWikiSearch().then(results => { |
| 70 |
|
- this.resultsCache = results; |
|
73 |
+ //this.resultsCache = results; |
| 71 |
71 |
if(this.hasActiveFilters()) { |
| 72 |
72 |
this.fetchFilterSearch().then(this.filterResults); |
| 73 |
73 |
} else { |
| 74 |
|
- this.results = results; |
|
77 |
+ this.results = results ? results || []; |
| 75 |
75 |
} |
| 76 |
76 |
}) |
| 77 |
|
- } else if (this.searchText === this.prevSearchText && this.hasActiveFilters()) { |
|
80 |
+ /*} else if (this.searchText === this.prevSearchText && this.hasActiveFilters()) { |
| 78 |
78 |
this.fetchFilterSearch().then(this.filterResults) |
| 79 |
79 |
} else { |
| 80 |
80 |
this.results = this.resultsCache; |
| 81 |
81 |
} |
|
85 |
+ */ |
| 82 |
82 |
} else { |
| 83 |
83 |
this.clearResults(); |
| 84 |
84 |
console.log("no search text, should return filter search results if any"); |
| ... |
... |
@@ -93,15 +93,12 @@ |
| 93 |
93 |
} |
| 94 |
94 |
fetchWikiSearch() { |
| 95 |
95 |
// request should be built from component, not from "external" dependency. Leave it here like this for POC. |
| 96 |
|
- return handleXWikiSearch(this.searchText); |
|
100 |
+ return handleXWikiSearch(this.searchText, this.offset, this.nb); |
| 97 |
97 |
} |
| 98 |
98 |
fetchFilterSearch() { |
| 99 |
99 |
return new Promise((resolve) => { |
| 100 |
100 |
if(this.hasActiveFilters()) { |
| 101 |
|
- fetch(this.filterUrl).then(res => res.json()).then((res) => { |
| 102 |
|
- this.collabFiltersResults = res; |
| 103 |
|
- resolve(res); |
| 104 |
|
- }); |
|
105 |
+ fetch(this.filterUrl).then(res => res.json()).then((res) => resolve(res)); |
| 105 |
105 |
} else { |
| 106 |
106 |
resolve([]); |
| 107 |
107 |
} |
| ... |
... |
@@ -128,6 +128,8 @@ |
| 128 |
128 |
<div> |
| 129 |
129 |
<div> |
| 130 |
130 |
<input id="searchInput" @change="${this.setSearchText}" type="text" placeholder="Search..." @keypress="${this.handleKeyPress}" /> |
|
132 |
+ <input @change="${this.setNb}"" type="text" value="${this.nb}" /> |
|
133 |
+ <input @change="${this.setOffset}"" type="text" value="${this.offset}" /> |
| 131 |
131 |
<button @click="${() => this.handleSearch(true)}">Search</button> |
| 132 |
132 |
</div> |
| 133 |
133 |
<div> |
| ... |
... |
@@ -144,30 +144,21 @@ |
| 144 |
144 |
</div> |
| 145 |
145 |
`)} |
| 146 |
146 |
</div> |
| 147 |
|
- <div class="rawResults"> |
| 148 |
|
- <div> |
| 149 |
|
- <strong>XWiki Search Results</strong> |
| 150 |
|
- <pre>${JSON.stringify(this.resultsCache, null, 2)}</pre> |
| 151 |
|
- </div> |
| 152 |
|
- <div> |
| 153 |
|
- <strong>Collab Search Results (Filters)</strong> |
| 154 |
|
- <pre>${JSON.stringify(this.collabFiltersResults, null, 2)}</pre> |
| 155 |
|
- </div> |
| 156 |
|
- </div> |
| 157 |
|
-</div> |
| 158 |
158 |
` |
| 159 |
159 |
} |
| 160 |
160 |
} |
| 161 |
161 |
customElements.define('clb-unified-search', UnifiedSearch); |
| 162 |
162 |
|
| 163 |
|
- function handleXWikiSearch(searchString) { |
|
155 |
+ function handleXWikiSearch(searchString, offset, nb) { |
| 164 |
164 |
return new Promise((resolve) => { |
| 165 |
165 |
require(['jquery'], function($) { |
| 166 |
166 |
const solrServiceURL = new XWiki.Document('SuggestSolrService', 'XWiki').getURL('get'); |
| 167 |
167 |
//contextSearchButton.addEventListener('click', function() { |
| 168 |
|
- $.post(solrServiceURL, { |
|
160 |
+ $.get(solrServiceURL, { |
| 169 |
169 |
outputSyntax: 'plain', |
| 170 |
170 |
media: 'json', |
|
163 |
+ nb: nb, |
|
164 |
+ offset: offset, |
| 171 |
171 |
query: [ |
| 172 |
172 |
'q="__INPUT__"~100', |
| 173 |
173 |
'fq=type:DOCUMENT', |
| ... |
... |
@@ -181,5 +181,4 @@ |
| 181 |
181 |
} |
| 182 |
182 |
}); |
| 183 |
183 |
</script> |
| 184 |
|
-<clb-unified-search></clb-unified-search> |
| 185 |
|
-{{/html}} |
|
178 |
+<clb-unified-search></clb-unified-search>{{/html}} |