mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
Fix alias handling
This commit is contained in:
parent
46e68aac60
commit
b06647838d
2 changed files with 12 additions and 13 deletions
|
@ -92,27 +92,26 @@ export class LocalAutocompleter {
|
||||||
* Get a Result object as the ith tag inside the file.
|
* Get a Result object as the ith tag inside the file.
|
||||||
*
|
*
|
||||||
* @param {number} i
|
* @param {number} i
|
||||||
* @returns {Result}
|
* @returns {[string, Result]}
|
||||||
*/
|
*/
|
||||||
getResultAt(i) {
|
getResultAt(i) {
|
||||||
const nameLocation = this.view.getUint32(this.referenceStart + i * 8, true);
|
const nameLocation = this.view.getUint32(this.referenceStart + i * 8, true);
|
||||||
const imageCount = this.view.getInt32(this.referenceStart + i * 8 + 4, true);
|
const imageCount = this.view.getInt32(this.referenceStart + i * 8 + 4, true);
|
||||||
|
const [ name, associations ] = this.getTagFromLocation(nameLocation);
|
||||||
|
|
||||||
if (imageCount < 0) {
|
if (imageCount < 0) {
|
||||||
// This is actually an alias, so follow it
|
// This is actually an alias, so follow it
|
||||||
return this.getResultAt(-imageCount);
|
return [ name, this.getResultAt(-imageCount)[1] ];
|
||||||
}
|
}
|
||||||
|
|
||||||
const [ name, associations ] = this.getTagFromLocation(nameLocation);
|
return [ name, { name, imageCount, associations } ];
|
||||||
|
|
||||||
return { name, imageCount, associations };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get a Result object as the ith tag inside the file, secondary ordering.
|
* Get a Result object as the ith tag inside the file, secondary ordering.
|
||||||
*
|
*
|
||||||
* @param {number} i
|
* @param {number} i
|
||||||
* @returns {Result}
|
* @returns {[string, Result]}
|
||||||
*/
|
*/
|
||||||
getSecondaryResultAt(i) {
|
getSecondaryResultAt(i) {
|
||||||
const referenceIndex = this.view.getUint32(this.secondaryStart + i * 4, true);
|
const referenceIndex = this.view.getUint32(this.secondaryStart + i * 4, true);
|
||||||
|
@ -122,7 +121,7 @@ export class LocalAutocompleter {
|
||||||
/**
|
/**
|
||||||
* Perform a binary search to fetch all results matching a condition.
|
* Perform a binary search to fetch all results matching a condition.
|
||||||
*
|
*
|
||||||
* @param {(i: number) => Result} getResult
|
* @param {(i: number) => [string, Result]} getResult
|
||||||
* @param {(name: string) => number} compare
|
* @param {(name: string) => number} compare
|
||||||
* @param {{[key: string]: Result}} results
|
* @param {{[key: string]: Result}} results
|
||||||
*/
|
*/
|
||||||
|
@ -136,9 +135,9 @@ export class LocalAutocompleter {
|
||||||
|
|
||||||
while (min < max - 1) {
|
while (min < max - 1) {
|
||||||
const med = (min + (max - min) / 2) | 0;
|
const med = (min + (max - min) / 2) | 0;
|
||||||
const { name } = getResult(med);
|
const sortKey = getResult(med)[0];
|
||||||
|
|
||||||
if (compare(name) >= 0) {
|
if (compare(sortKey) >= 0) {
|
||||||
// too large, go left
|
// too large, go left
|
||||||
max = med;
|
max = med;
|
||||||
}
|
}
|
||||||
|
@ -150,8 +149,8 @@ export class LocalAutocompleter {
|
||||||
|
|
||||||
// Scan forward until no more matches occur
|
// Scan forward until no more matches occur
|
||||||
while (min < this.numTags - 1) {
|
while (min < this.numTags - 1) {
|
||||||
const result = getResult(++min);
|
const [ sortKey, result ] = getResult(++min);
|
||||||
if (compare(result.name) !== 0) {
|
if (compare(sortKey) !== 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ defmodule Philomena.Autocomplete do
|
||||||
reference_indexes =
|
reference_indexes =
|
||||||
tags
|
tags
|
||||||
|> Enum.with_index()
|
|> Enum.with_index()
|
||||||
|> Enum.map(fn {name, index} -> {name, index} end)
|
|> Enum.map(fn {{name, _, _, _}, index} -> {name, index} end)
|
||||||
|> Map.new()
|
|> Map.new()
|
||||||
|
|
||||||
references =
|
references =
|
||||||
|
@ -90,7 +90,7 @@ defmodule Philomena.Autocomplete do
|
||||||
|
|
||||||
secondary_references =
|
secondary_references =
|
||||||
tags
|
tags
|
||||||
|> Enum.map(&{name_in_namespace(elem(&1, 0)), &1})
|
|> Enum.map(&{name_in_namespace(elem(&1, 0)), elem(&1, 0)})
|
||||||
|> Enum.sort()
|
|> Enum.sort()
|
||||||
|> Enum.reduce(<<>>, fn {_k, v}, secondary_references ->
|
|> Enum.reduce(<<>>, fn {_k, v}, secondary_references ->
|
||||||
target = Map.fetch!(reference_indexes, v)
|
target = Map.fetch!(reference_indexes, v)
|
||||||
|
|
Loading…
Reference in a new issue