Changes for page Context Search
Last modified by bougault on 2023/02/20 16:29
Summary
-
Page properties (1 modified, 0 added, 0 removed)
Details
- Page properties
-
- Content
-
... ... @@ -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,25 +67,35 @@ 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) { 68 + console.log(textSearch); 71 71 if(this.searchText !== "" || textSearch) { 72 - if(this.searchText !== this.prevSearchText) { 70 + // if(this.searchText !== this.prevSearchText) { 73 73 this.clearResults(); 74 74 this.prevSearchText = this.searchText; 75 75 this.fetchWikiSearch().then(results => { 76 - this.resultsCache = results; 74 + console.log('results', results); 75 + //this.resultsCache = results; 77 77 if(this.hasActiveFilters()) { 78 78 this.fetchFilterSearch().then(this.filterResults); 79 79 } else { 80 - this.results = results; 79 + this.results = results ? results : []; 81 81 } 82 82 }) 83 - } else if (this.searchText === this.prevSearchText && this.hasActiveFilters()) { 82 + /*} else if (this.searchText === this.prevSearchText && this.hasActiveFilters()) { 84 84 this.fetchFilterSearch().then(this.filterResults) 85 85 } else { 86 86 this.results = this.resultsCache; 87 87 } 87 + */ 88 88 } else { 89 + this.results = []; 89 89 this.clearResults(); 90 90 console.log("no search text, should return filter search results if any"); 91 91 this.fetchFilterSearch().then(collabs => { ... ... @@ -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); 103 + 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 - }); 108 + 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}" /> 135 + <input @change="${this.setNb}"" type="text" value="${this.nb}" /> 136 + <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,30 +150,21 @@ 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 } 167 167 customElements.define('clb-unified-search', UnifiedSearch); 168 168 169 - function handleXWikiSearch(searchString) { 158 + function handleXWikiSearch(searchString, offset, nb) { 170 170 return new Promise((resolve) => { 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, {163 + $.get(solrServiceURL, { 175 175 outputSyntax: 'plain', 176 176 media: 'json', 166 + nb: nb, 167 + offset: offset, 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}} 181 +<clb-unified-search></clb-unified-search>{{/html}}