Fix case insensitive search and display

This commit is contained in:
Chord 2019-12-30 16:21:55 -05:00
parent 0e4123fe98
commit 817796e181
2 changed files with 14 additions and 2 deletions

View file

@ -340,6 +340,13 @@ export async function get_account_logins(account_id, pagination) {
export async function search(term, pagination) {
const start_id = (pagination.page-1)*pagination.items_per_page;
term = term.replace(/%/g, "");
if (term.length < 3) {
return [];
}
const values = ['%'+term.toUpperCase()+'%', start_id, pagination.items_per_page];
try {
@ -347,8 +354,8 @@ export async function search(term, pagination) {
'WHERE upper(username) LIKE $1 '+
` ORDER BY username OFFSET $2 LIMIT $3`, values);
const characters = await pool.query('SELECT id, name, account_id, faction_id FROM characters ' +
'WHERE name LIKE $1 '+
` ORDER BY upper(name) OFFSET $2 LIMIT $3`, values);
'WHERE upper(name) LIKE $1 '+
` ORDER BY name OFFSET $2 LIMIT $3`, values);
pagination.item_count = 100;
pagination.page_count = Math.ceil(pagination.item_count / pagination.items_per_page);

View file

@ -50,6 +50,11 @@
<button type="submit" class="btn btn-primary mb-2">Search</button>
</form>
{#if results}
{#if results.length > 0}
<p>{results.length} results found.</p>
{:else}
<p>No results found.</p>
{/if}
<ol>
{#each results as result, i}
{#if result.type == "account"}