This commit is contained in:
“spicecat” 2022-07-28 20:50:42 -04:00
commit 1b3f87f732
5 changed files with 100 additions and 17 deletions

View file

@ -8,6 +8,7 @@
"@emotion/styled": "^11.9.3",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.9.1",
"acorn": "^8.8.0",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.1",
"formik": "^2.2.9",

View file

@ -15,12 +15,15 @@ import { searchQuestions } from 'services/questionsServices';
const recent = {};
const best = { sort: 'u' };
const interesting = {
match: { answers: 0 },
const interesting = { match: JSON.stringify({ 'answers': 0 }), sort: 'uvc' }
/*const interesting = {
match: { answers : 0 },
sort: 'uvc',
};
};*/
const hot = {
match: { hasAcceptedAnswer: false },
match: JSON.stringify({ hasAcceptedAnswer: false }),
sort: 'uvac',
};
const sortObjArr = [recent, best, interesting, hot];
@ -31,6 +34,7 @@ export default function Buffet() {
const [sort, setSort] = useState(0);
const getData = async () => {
const { error, questions } = await searchQuestions(sortObjArr[sort]);
if (error) {
setError(error);

View file

@ -5,17 +5,73 @@ import { SearchForm } from 'controllers/FormControllers';
import { PaginatedList } from 'controllers';
import { ListQuestion } from 'components';
import { searchQuestions } from 'services/questionsServices';
import { useEffect } from 'react';
export default function Search() {
const [searchParams] = useSearchParams()
const [searchParams, setSearchParams] = useSearchParams()
useEffect(()=>{
setSearchParams()
}, [])
const getData = async () => {
const createdAt = searchParams.get('createdAt');
const creator = searchParams.get('creator');
const text = searchParams.get('text');
const title = searchParams.get('title');
console.log(new Date(createdAt))
const { questions } = await searchQuestions({ regexMatch: { creator, text, title } })
let match = {};
let regexMatch = {}
let time ={};
let newdate = searchParams.get('createdAt');
if(newdate){
newdate = new Date(newdate)
time["$gte"] = parseInt(newdate.getTime());
newdate.setDate(newdate.getDate() + 1)
time["$lte"] = newdate.getTime()
match = JSON.stringify({"createdAt" : time})
}
if(searchParams.get('creator')){regexMatch["creator"] = searchParams.get('creator')};
if(searchParams.get('text')){
const fields = searchParams.get('text');
let arr = fields.split(" ")
let matchString = "";
for(var i = 0; i< arr.length; i++){
matchString += "(" + arr[i] + ")"
if(i < arr.length-1){
matchString += " | "
}
}
regexMatch["text"] = matchString + " /gmi";
};
if(searchParams.get('title')){
const fields = searchParams.get('title');
let arr = fields.split(" ")
let matchString = "";
for(var i = 0; i< arr.length; i++){
matchString += "(" + arr[i] + ")"
if(i < arr.length-1){
matchString += " | "
}
}
regexMatch["title"] = matchString + " /gi";
};
const { questions } = await searchQuestions({ regexMatch, match})
return questions;
}

View file

@ -118,11 +118,10 @@ const searchFields = [
id: 'text',
label: 'Text',
},
// {
// id: 'createdAt',
// label: 'Date',
// type: 'date',
// },
{
id: 'createdAt',
type: 'date',
},
{
id: 'creator',
label: 'Creator',

25
package-lock.json generated
View file

@ -21,6 +21,7 @@
"@emotion/styled": "^11.9.3",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.9.1",
"acorn": "^8.8.0",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.1",
"formik": "^2.2.9",
@ -41,6 +42,17 @@
"yup": "^0.32.11"
}
},
"client/node_modules/acorn": {
"version": "8.8.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz",
"integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w==",
"bin": {
"acorn": "bin/acorn"
},
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/@ampproject/remapping": {
"version": "2.2.0",
"license": "Apache-2.0",
@ -5968,7 +5980,8 @@
},
"node_modules/cors": {
"version": "2.8.5",
"license": "MIT",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"dependencies": {
"object-assign": "^4",
"vary": "^1"
@ -23824,6 +23837,8 @@
},
"cors": {
"version": "2.8.5",
"resolved": "https://registry.npmjs.org/cors/-/cors-2.8.5.tgz",
"integrity": "sha512-KIHbLJqu73RGr/hnbrO9uBeixNGuvSQjul/jdFvS/KFSIH1hWVd1ng7zOHx+YrEfInLG7q4n6GHQ9cDtxv/P6g==",
"requires": {
"object-assign": "^4",
"vary": "^1"
@ -29446,6 +29461,7 @@
"@emotion/styled": "^11.9.3",
"@mui/icons-material": "^5.8.4",
"@mui/material": "^5.9.1",
"acorn": "*",
"crypto-js": "^4.1.1",
"dotenv": "^16.0.1",
"formik": "^2.2.9",
@ -29464,6 +29480,13 @@
"superagent-throttle": "^1.0.1",
"universal-cookie": "^4.0.4",
"yup": "^0.32.11"
},
"dependencies": {
"acorn": {
"version": "8.8.0",
"resolved": "https://registry.npmjs.org/acorn/-/acorn-8.8.0.tgz",
"integrity": "sha512-QOxyigPVrpZ2GXT+PFyZTl6TtOFc5egxHIP9IlQ+RbupQuX4RkT/Bee4/kQuC02Xkzg84JcT7oLYtDIQxp+v7w=="
}
}
},
"qs": {