I have been using the dataview plugin in my personal knowledge organization system, and since I couldn’t perform queries without manipulating the code, I opted for an alternative solution. I’m new to programming, so I might make a lot of mistakes. What I did was create a query page for my general Zettelkasten, where I created columns associated with certain metadata in my vault. I used Dataviewjs to link those columns to the database. Here is the database code:
keyword::
ID-Z::
Naturaleza::
Concepto-clave::
Conceptos-padre::
alias::
Descripcion::
Periodo::
Status::
Autor::
Referente::
Capitulo::
Zettelkasten::
Padre::
Relacionado::
Contexto::
Otro::
Suceso::
Tipo::
Categoria-de-nota::
Segmento::
Categoria::
Subcategoria::
Proyectos::
Subproyectos::
sortby:: ID-Z
sortorder::
await dv.view("_METADATA/_02. dataview/_02.1. view_zettelkasten",
{ keyword: dv.current().keyword, IDZ: dv.current()["ID-Z"],
Naturaleza: dv.current().Naturaleza,
Conceptoclave: dv.current()["Concepto-clave"],
Conceptospadre: dv.current()["Conceptos-padre"],
alias: dv.current().alias,
Descripcion: dv.current().Descripcion,
Periodo: dv.current().Periodo,
Status: dv.current().Status,
Autor: dv.current().Autor,
Referente: dv.current().Referente,
Capitulo: dv.current().Capitulo,
Zettelkasten: dv.current().Zettelkasten,
Padre: dv.current().Padre,
Relacionado: dv.current().Relacionado,
Contexto: dv.current().Contexto,
Otro: dv.current().Otro,
Suceso: dv.current().Suceso,
Tipo: dv.current().Tipo,
Categoriadenota: dv.current()["Categoria-de-nota"],
Segmento: dv.current().Segmento,
Categoria: dv.current().Categoria,
Subcategoria: dv.current().Subcategoria,
Proyectos: dv.current().Proyectos,
Subproyectos: dv.current().Subproyectos,
sortby: dv.current().sortby, sortorder: dv.current().sortorder });
To filter and organize the notes, I created a script called “view_zettelkasten” with the help of Chat GPT to perform general queries in the vault using string matching with the query column. This is the associated script:
const current = dv.current();
const cPeriodo = new Date(dv.current().Periodo).getTime();
const cPeriodoop = !dv.current().Periodo ? "" : (dv.current().Periodo.toString().includes("<") ? "<" : (dv.current().Periodo.toString().includes(">") ? ">" : "==="));
const cFechadecreado = new Date(dv.current()["Fecha-de-creado"]).getTime();
const cFechadecreadoop = !dv.current()["Fecha-de-creado"] ? "" : (dv.current()["Fecha-de-creado"].toString().includes("<") ? "<" : (dv.current()["Fecha-de-creado"].toString().includes(">") ? ">" : "==="));
const cFechademodificado = new Date(dv.current()["Fecha-de-modificado"]).getTime();
const cFechademodificadoop = !dv.current()["Fecha-de-modificado"] ? "" : (dv.current()["Fecha-de-modificado"].toString().includes("<") ? "<" : (dv.current()["Fecha-de-modificado"].toString().includes(">") ? ">" : "==="));
const matchtags = (a, b) => {
for (const v of new Set(a)) {
if (
!b.some(e => e === v) ||
a.filter(e => e === v).length > b.filter(e => e === v).length
)
return false;
}
return true;
};
if (current.keyword || current["ID-Z"] || current.Naturaleza || current["Concepto-clave"] || current["Conceptos-padre"] || current.alias || current.Descripcion || current.Periodo || current.Status || current.Autor || current.Referente || current.Capitulo || current.Zettelkasten || current.Padre || current.Relacionado || current.Contexto || current.Otro || current.Suceso || current.Tipo || current["Categoria-de-nota"] || current.Segmento || current.Categoria || current.Subcategoria || current.Proyectos || current.Subproyectos) {
function passes(page) {
const splitLinks = (value) => {
if (typeof value !== 'string') return [];
return value.split(",").map(link => link.trim());
};
const includesLink = (field, value) => {
if (!page[field]) return false;
if (typeof value !== 'string') return false;
const links = splitLinks(page[field]);
return links.some(link => typeof link === 'string' && link.toLowerCase().includes(value.toLowerCase()));
};
// Add a new function to handle multiple links separated by commas
const includesMultipleLinks = (field, values) => {
if (!page[field]) return false;
const links = splitLinks(page[field]);
const valuesArray = splitLinks(values);
return valuesArray.every(value => links.some(link => link.toLowerCase().includes(value.toLowerCase())));
};
return (!current["ID-Z"] || includesLink("ID-Z", current["ID-Z"]))
&& (!current.Naturaleza || includesLink("Naturaleza", current.Naturaleza))
&& (!current["Concepto-clave"] || includesLink("Concepto-clave", current["Concepto-clave"]))
&& (!current["Conceptos-padre"] || includesLink("Conceptos-padre", current["Conceptos-padre"]))
&& (!current.alias || includesLink("alias", current.alias))
&& (!current.Descripcion || includesLink("Descripcion", current.Descripcion))
&& (!current.Periodo || includesLink("Periodo", current.Periodo))
&& (!current.Status || includesLink("Status", current.Status))
&& (!current.Autor || includesLink("Autor", current.Autor))
&& (!current.Referente || includesLink("Referente", current.Referente))
&& (!current.Capitulo || includesLink("Capitulo", current.Capitulo))
&& (!current.Zettelkasten || includesLink("Zettelkasten", current.Zettelkasten))
&& (!current.Padre || includesLink("Padre", current.Padre))
&& (!current.Relacionado || includesLink("Relacionado", current.Relacionado))
&& (!current.Contexto || includesLink("Contexto", current.Contexto))
&& (!current.Otro || includesLink("Otro", current.Otro))
&& (!current.Suceso || includesLink("Suceso", current.Suceso))
&& (!current.Tipo || includesLink("Tipo", current.Tipo))
&& (!current["Categoria-de-nota"] || includesLink("Categoria-de-nota", current["Categoria-de-nota"]))
&& (!current.Segmento || includesLink("Segmento", current.Segmento))
&& (!current.Categoria || includesLink("Categoria", current.Categoria))
&& (!current.Proyectos || includesLink("Proyectos", current.Proyectos))
&& (!current.Subproyectos || includesLink("Subproyectos", current.Subproyectos))
}
function keyword(page) {
return (!current.keyword || (page.content && page.content.toLowerCase().includes(current.keyword.toLowerCase()))
|| (page.Pregunta && page.Pregunta.toLowerCase().includes(current.keyword.toLowerCase())));
}
const pages = await Promise.all(
dv.pages('"04.apl DATA ANTROPO-CIENTÍFICA/04.H. Conceptos clave" OR "#Concepto-Clave" OR "05.apl ZETTELKASTEN"')
.where(passes)
.sort(p => p[current.sortby], current.sortorder)
.map(page => new Promise(async (resolve, reject) => {
const content = await dv.io.load(page.file.path);
resolve({
link: page.file.link,
IDZ: page["ID-Z"],
Naturaleza: page.Naturaleza,
Conceptoclave: page["Concepto-clave"],
Conceptospadre: page["Conceptos-padre"],
alias: page.alias,
Descripcion: page.Descripcion,
Periodo: page.Periodo,
Status: page.Status,
Autor: page.Autor,
Referente: page.Referente,
Capitulo: page.Capitulo,
Zettelkasten: page.Zettelkasten,
Padre: page.Padre,
Relacionado: page.Relacionado,
Contexto: page.Contexto,
Otro: page.Otro,
Suceso: page.Suceso,
Tipo: page.Tipo,
Categoriadenota: page["Categoria-de-nota"],
Segmento: page.Segmento,
Categoria: page.Categoria,
Subcategoria: page.Subcategoria,
Proyectos: page.Proyectos,
Subproyectos: page.Subproyectos,
content
});
}))
);
dv.table(
["Nota", "ID-Z", "Naturaleza", "Concepto-clave", "Conceptos-padre", "alias", "Descripcion", "Periodo", "Status", "Autor", "Referente", "Capitulo", "Zettelkasten", "Padre", "Relacionado", "Contexto", "Otro", "Suceso", "Tipo", "Categoria-de-nota", "Segmento", "Categoria", "Subcategoria", "Proyectos", "Subproyectos"],
pages
.filter(keyword)
.map(p => [
p.link,
p.IDZ,
p.Naturaleza,
p.Conceptoclave,
p.Conceptospadre,
p.alias,
p.Descripcion,
p.Periodo,
p.Status,
p.Autor,
p.Referente,
p.Capitulo,
p.Zettelkasten,
p.Padre,
p.Relacionado,
p.Contexto,
p.Otro,
p.Suceso,
p.Tipo,
p.Categoriadenota,
p.Segmento,
p.Categoria,
p.Subcategoria,
p.Proyectos,
p.Subproyectos
])
);
} else {
dv.paragraph("<font color=#ff0000>INTRODUZCA LOS TÉRMINOS DE BÚSQUEDA PARA LOS CRITERIOS DE LA BASE DE DATOS.</font>");
}
I managed to do that, but the problem arose when I tried to query notes that had multiple links in their metadata separated by commas.
For example, I wanted to query the “Author” criterion with “Kuhn, Thomas”, but in some notes where Kuhn appears, there are also other author links. For instance, in one of the notes, it appears like this: “Author:: [[Packer, Martin]], [[Kuhn, Thomas]]”.
When I try to make the query from my column, no notes appear no matter how much I try. I think the problem lies in not being able to identify when there are multiple links separated by commas. Does anyone have any ideas? Perhaps the problem is in the way I am searching or there may be an error in the code (I’m very new to this).
I appreciate any help or suggestions you can provide. Thank you very much!