Skip to content

Commit

Permalink
very little progress on search bar
Browse files Browse the repository at this point in the history
  • Loading branch information
autumn-ragland committed Apr 24, 2019
1 parent 484e3ad commit 002dbc2
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
2 changes: 2 additions & 0 deletions client/src/TwitterHome.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ class TwitterHome extends Component {
userObject: [],
tweetArray:[],
anotherMap:[],

theFinalPublicMap:[],
theFinalLoggedInMap:[],

searchResults:'',
mappedResults:[],
};
Expand Down
2 changes: 1 addition & 1 deletion server/models/TwitterUserSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ var TwitterUserSchema = new Schema({
tweets:[{tweetMessage:String, tweetImage:String, tweetPublic:Boolean}],
});

module.exports = mongoose.model("TwitterUser", TwitterUserSchema);
module.exports = mongoose.model("TwitterUser", TwitterUserSchema);
41 changes: 40 additions & 1 deletion server/routes/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ router.post('/searchTweets', (req, res) => {
for (let i = 0; i < parseInt(results.length); i++) {
for (let j = 0; j < results[i].tweets.length; j++) {
console.log(results[i].tweets[j].tweetMessage);
if((results[i].tweets[j].tweetMessage) === (req.body.searchBar)){
if ((results[i].tweets[j].tweetMessage) === (req.body.searchBar)) {
searchResults = results[i].tweets[j].tweetMessage;
console.log(results[i].tweets[j].tweetMessage)
}
Expand All @@ -171,6 +171,45 @@ router.post('/searchTweets', (req, res) => {
})
});

//search tweets 2.0
router.post('/searchTweets2', (req, res) => {
TwitterUserCollection.find(
{"tweets.tweetMessage": {"$regex": req.body.searchBar, "$options": "i"}}, (errors, results) => {
if (errors) res.send(errors);
else {
for (let i = 0; i < results.length; i++) {
for (let j = 0; j < results[i].tweets.length; j++) {
//add each tweet to a results collection
console.log(results[i].tweets[j].tweetMessage);
}
}
// resultsCollection.find({'tweetMessage': {"$regex": req.body.searchBar, "$options": "i"}}, (errors, results) => {
// if(errors) console.log(errors);
// else{
// if(results.length < 0) console.log(results);
// else console.log('no results')
// }
// });
res.send('check console')
}
})
});

//search tweet 3.0 BROKEN
router.post('/search3', (req, res) => {
TwitterUserCollection.findOne({'tweets.tweetMessage': req.body.searchBar}, {'tweets.$': 1}, (errors, results) => {
if (errors) res.send(errors);
else{
if (results) {
res.send(results.tweets[0].tweetMessage);
}
else{
res.send('no results')
}
}
})
});

//grab user
router.post('/searchUsers', (req, res) => {
TwitterUserCollection.findOne({username: req.body.username}, (errors, results) => {
Expand Down

0 comments on commit 002dbc2

Please sign in to comment.