0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-11 09:02:44 +00:00

remove regex search

This commit is contained in:
Víctor Losada Hernández
2024-05-18 23:07:43 +02:00
parent 97ef56f905
commit a711f8eb89
2 changed files with 3 additions and 18 deletions

View File

@@ -187,7 +187,7 @@ const ArchivePage = createClass({
placeholder="v3 Reference Document" placeholder="v3 Reference Document"
/> />
</label> </label>
<small>Tip! you can use <a href="https://regexlearn.com/learn">RegEx</a> if you format your query as <code>/title/</code></small> <small>Tip! you can use <code>-</code> to negate words, and <code>"word"</code> to specify an exact string.</small>
<label> <label>
Results per page Results per page
<input <input

View File

@@ -2,21 +2,6 @@ const HomebrewModel = require('./homebrew.model.js').model;
const router = require('express').Router(); const router = require('express').Router();
const asyncHandler = require('express-async-handler'); const asyncHandler = require('express-async-handler');
const buildTitleConditionsArray = (title) => {
if (title.startsWith('/') && title.endsWith('/')) {
return [
{
title: {
$regex: title.slice(1, -1),
$options: 'i',
},
},
];
} else {
return buildTitleConditions(title);
}
};
const buildTitleConditions = (inputString) => { const buildTitleConditions = (inputString) => {
return [ return [
{ {
@@ -80,7 +65,7 @@ const archive = {
const skip = (page - 1) * pageSize; const skip = (page - 1) * pageSize;
const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3);
const titleConditionsArray = buildTitleConditionsArray(title); const titleConditionsArray = buildTitleConditions(title);
const titleQuery = { const titleQuery = {
$and: [brewsQuery, ...titleConditionsArray], $and: [brewsQuery, ...titleConditionsArray],
@@ -110,7 +95,7 @@ const archive = {
const title = req.query.title || ''; const title = req.query.title || '';
const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3); const brewsQuery = buildBrewsQuery(req.query.legacy, req.query.v3);
const titleConditionsArray = buildTitleConditionsArray(title); const titleConditionsArray = buildTitleConditions(title);
const titleQuery = { const titleQuery = {
$and: [brewsQuery, ...titleConditionsArray], $and: [brewsQuery, ...titleConditionsArray],