Partial implementation of: #47 The 2022.2.1 release currently live is based off of the TimetableAPI-Upgrade branch. Partial PIS code matching is now implemented in cases where x number of stops need skipping at the start of a route. Reviewed-on: #64
103 lines
1.5 KiB
TypeScript
103 lines
1.5 KiB
TypeScript
export function getPartialEndTiplocMatchPipeline(query: string[]) {
|
|
return [
|
|
{
|
|
$match: {
|
|
tiplocs: {
|
|
$all: query,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
$addFields: {
|
|
reversedTiplocs: {
|
|
$reverseArray: "$tiplocs",
|
|
},
|
|
query: {
|
|
$literal: query,
|
|
},
|
|
},
|
|
},
|
|
{
|
|
$addFields: {
|
|
reversedQuery: {
|
|
$reverseArray: "$query",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
$match: {
|
|
$expr: {
|
|
$eq: [
|
|
{
|
|
$slice: [
|
|
"$reversedTiplocs",
|
|
0,
|
|
{
|
|
$size: "$reversedQuery",
|
|
},
|
|
],
|
|
},
|
|
"$reversedQuery",
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
$addFields: {
|
|
skipStops: {
|
|
$subtract: [
|
|
{
|
|
$size: "$tiplocs",
|
|
},
|
|
{
|
|
$size: "$reversedQuery",
|
|
},
|
|
],
|
|
},
|
|
},
|
|
},
|
|
{
|
|
$sort: {
|
|
skipStops: 1,
|
|
},
|
|
},
|
|
{
|
|
$limit: 1,
|
|
},
|
|
{
|
|
$project: {
|
|
code: 1,
|
|
skipStops: 1,
|
|
toc: 1,
|
|
_id: 0,
|
|
},
|
|
},
|
|
];
|
|
}
|
|
|
|
export function getFullTiplocMatchPipeline(query: string[]) {
|
|
return [
|
|
{
|
|
$match: {
|
|
tiplocs: query,
|
|
},
|
|
},
|
|
{
|
|
$limit: 1,
|
|
},
|
|
{
|
|
$addFields: {
|
|
skipStops: 0,
|
|
},
|
|
},
|
|
{
|
|
$project: {
|
|
code: 1,
|
|
toc: 1,
|
|
skipStops: 1,
|
|
_id: 0,
|
|
},
|
|
},
|
|
];
|
|
}
|