Local search ranks literal identifier matches by title, not by how often the term appears

Cerrado Apto para principiantes
#60 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
77/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
hugo, javascript
Área
search

Línea de trabajo

Empieza en assets/js/search-engine.js, donde se puntúan y comparan las consultas de identificadores literales. Usa la reproducción incluida en Node para confirmar el orden actual. Después, comprueba que, entre las páginas que coinciden en el mismo campo, un mayor número de apariciones mejora la posición, mientras que el orden de los títulos sigue sirviendo para desempatar. Vuelve a ejecutar la reproducción y confirma que Query reference aparece antes que Alpha notes.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

Version: v1.5.0 (84b93e4)

What happens

A query that contains _, . or - (for example top_k) skips Lunr and is matched literally in assets/js/search-engine.js. A page's score for the term is the weight of the highest field that contains it (title 100, keywords 80, headings 50, body 10), with no count of occurrences. Pages that mention the identifier only in body text all score 10, and compare() then orders them by title. A page that mentions the term once in passing ranks above the page that documents it.

On a 45-page docs site, top_k appears in the body of 15 pages, and the top five results are the first five titles in alphabetical order. The pages that define the parameter come later. With v1.1.0 the same query went through Lunr and ranked those pages first.

Minimal reproduction (no site build needed)

// node repro.cjs path/to/oink/assets/js/search-engine.js
global.window = {};
const engine = require(process.argv[2]);
const docs = [
  { ref: '/a/', title: 'Alpha notes', body: 'Benchmarks ran with top_k set to 10.' },
  { ref: '/q/', title: 'Query reference',
    body: 'top_k: number of results. Set top_k to 5 for short answers. top_k must be ' +
          'between 1 and 100. When top_k exceeds the candidate pool, fewer results return.' },
];
console.log(engine.create(docs, null, 10).query('top_k').map((r) => r.doc.title));

Output: [ 'Alpha notes', 'Query reference' ]. Renaming "Alpha notes" to "Zulu notes" reverses the order, so the title is the tie-breaker.

Expected

Among pages that match in the same field, the page where the term occurs more often ranks higher.

Possible direction

Add an occurrence count within a field tier, for example weight + min(count, 10), before falling back to the title order. search_keywords works as a per-page workaround today.

Lenguaje dominante
HTML
Estrellas
164
Forks
19
Merge medio
1 d 11 h
PR fusionados (30 d)
9

Preparar el entorno

  • Sin Dockerfile ni archivo de Docker Compose
  • Tiene una plantilla de pull request
  • Sin guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Issues similares

Más issues de Search

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.