2023-04-25 19:57:15 +02:00
|
|
|
import type { PutInput } from "upend/types";
|
2022-02-20 13:06:01 +01:00
|
|
|
import { query as queryFn } from "../lib/entity";
|
2023-05-22 20:57:06 +02:00
|
|
|
import api from "../lib/api";
|
2023-06-24 16:26:14 +02:00
|
|
|
import { ATTR_LABEL } from "upend/constants";
|
2022-01-27 20:56:00 +01:00
|
|
|
|
|
|
|
export function baseSearch(query: string) {
|
2022-02-04 23:04:38 +01:00
|
|
|
return queryFn(
|
2022-02-07 22:01:10 +01:00
|
|
|
`(or (matches (contains "${query}") ? ?) (matches ? (contains "${query}") ?) (matches ? ? (contains "${query}")))`
|
2022-02-04 23:04:38 +01:00
|
|
|
);
|
2022-01-27 20:56:00 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 21:28:42 +01:00
|
|
|
export function baseSearchOnce(query: string) {
|
2023-05-22 20:57:06 +02:00
|
|
|
return api.query(
|
2022-02-07 22:01:10 +01:00
|
|
|
`(or (matches (contains "${query}") ? ?) (matches ? (contains "${query}") ?) (matches ? ? (contains "${query}")))`
|
2022-02-04 23:04:38 +01:00
|
|
|
);
|
2022-01-27 21:28:42 +01:00
|
|
|
}
|
|
|
|
|
2022-01-27 20:56:00 +01:00
|
|
|
export async function createLabelled(label: string) {
|
2023-04-25 19:57:15 +02:00
|
|
|
let body: PutInput;
|
2022-02-09 20:34:52 +01:00
|
|
|
if (label.match("^[\\w]+://[\\w]")) {
|
|
|
|
body = {
|
|
|
|
entity: {
|
|
|
|
t: "Url",
|
|
|
|
c: label,
|
|
|
|
},
|
|
|
|
};
|
2023-07-28 20:19:12 +02:00
|
|
|
const [_, entity] = await api.putEntry(body);
|
|
|
|
return entity;
|
2022-02-09 20:34:52 +01:00
|
|
|
} else {
|
2023-07-28 20:19:12 +02:00
|
|
|
const [_, entity] = await api.putEntry({
|
|
|
|
entity: {
|
|
|
|
t: "Uuid",
|
2022-01-27 20:56:00 +01:00
|
|
|
},
|
2023-07-28 20:19:12 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
await api.putEntityAttribute(entity, ATTR_LABEL, { t: "String", c: label });
|
2022-02-09 20:34:52 +01:00
|
|
|
|
2023-07-28 20:19:12 +02:00
|
|
|
return entity;
|
2022-01-27 20:56:00 +01:00
|
|
|
}
|
|
|
|
}
|