Merge pull request #34884 from overleaf/em-already-in-your-library

Library import: flag entries that are already in the user's library

GitOrigin-RevId: f3c92fb59283631e1a9e78d2e08a3a365981df45
This commit is contained in:
Eric Mc Sween
2026-06-26 08:07:21 +00:00
committed by Copybot
parent 75f7f82a3f
commit 4fb8608908
4 changed files with 45 additions and 5 deletions
@@ -4,6 +4,7 @@ import logger from '@overleaf/logger'
import { db } from '../app/src/infrastructure/mongodb.mjs'
import {
buildSearchTokens,
buildMatchTokens,
docSchema,
} from '../modules/library/app/src/LibraryReferenceRepository.mts'
import { tokenize } from '../modules/library/app/src/bibtex-search-tokens.mts'
@@ -21,10 +22,10 @@ function usage() {
{},
`Usage: node backfill_library_references_search.mjs [options]
Populates searchKey and searchTokens on libraryReferences so the
account-level library search can index them. Also unsets the obsolete
fields.$[].searchValue. Safe to rerun; picks up only un-indexed rows
by default.
Populates searchKey, searchTokens and matchTokens on libraryReferences so
the account-level library search and import duplicate-detection can index
them. Also unsets the obsolete fields.$[].searchValue. Safe to rerun; picks
up only un-indexed rows by default.
Options:
--commit Apply changes. Without this, runs as a dry run.
@@ -73,11 +74,12 @@ async function backfill(trackProgress) {
})
const searchKey = tokenize(doc.key)
const searchTokens = buildSearchTokens(entry)
const matchTokens = buildMatchTokens(entry)
ops.push({
updateOne: {
filter: { _id: doc._id },
update: {
$set: { searchKey, searchTokens },
$set: { searchKey, searchTokens, matchTokens },
$unset: { 'fields.$[].searchValue': 1 },
},
},