Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unanswered filter #131

Open
jaredmoody opened this issue Dec 9, 2012 · 34 comments
Open

Unanswered filter #131

jaredmoody opened this issue Dec 9, 2012 · 34 comments

Comments

@jaredmoody
Copy link
Contributor

It would be nice to create a filter on the questions tab for unanswered questions, a la stack overflow.

What do you think?

@PragTob
Copy link
Member

PragTob commented Dec 10, 2012

Cool idea!

@rhysforyou
Copy link
Contributor

I like it. We need to start mapping out some new features, this project's been stagnating for too long.

@PragTob
Copy link
Member

PragTob commented Dec 11, 2012

As for stagnating I personally rather put my free time into shoes4 in order to have a reliably running hacketyhack again, but that's a different story. Of course the web platform shouldn't stagnate so I'm all for new features :-)

@jaredmoody
Copy link
Contributor Author

I agree getting shoes working properly is more important, I'm just more familiar with web so this was a good place for me to start contributing.

This may not be the right place to discuss this, but what is/is there a plan for more lessons? That seems to be a popular request and I'd be happy to help move that forward. Maybe we could adapt content from someone else with permission?

Lastly, I'm very new to mongodb, can someone give me a tip about how to write a scope for unanswered questions? The whole no joins thing is throwing me :)

@steveklabnik
Copy link
Member

Right, the advantage of us being multiple people! I don't think that saying that globally shoes is more important; people are using the site right now, and we should be helping them too!

This may not be the right place to discuss this, but what is/is there a plan for more lessons?

There is, but I'm busy. As long as you're willing to let me revise them heavily, I'm all for you adding more lessons! We have a gem for that, hackety_hack-lessons.

@PragTob
Copy link
Member

PragTob commented Dec 12, 2012

@steveklabnik yep you're right! Personally my priorities are more with shoes these days :-)

Adding more lessons would be totally awesome. Would also be happy to revise.

As for mongo, sorry no idea - always new stuff to learn out there!

@trekr5
Copy link
Contributor

trekr5 commented Aug 12, 2013

Hello,

Please take a look at the following mockup done by Team Hackety Hack for the unanswered filter feature https://gomockingbird.com/mockingbird/#4a7borc/KC4JNQ

Let me know what you think. All input welcome!

@steveklabnik
Copy link
Member

Looks good!

@PragTob
Copy link
Member

PragTob commented Aug 12, 2013

looks good, but what other drop down options (except no answer) would there be? If there are no other options I'd rather make it a button/checkbox

@jacqueline-homan
Copy link

Hello,

Here's an additional mockup from our team for the unanswered questions filter: https://gomockingbird.com/mockingbird/#w6oglu4/mBiAW

I also have a question about that unanswered questions handling. Here's what I've been mulling over in my mind:

We need a user interface that tells the app that we want to see only unanswered questions. PragTob, you mentioned a button/checkbox or something to that effect that would either say "All" or "Unanswered" and direct the user accordingly.

But if you put that in the view where the questions are, why not just put the "search" feature there and then you wouldn't need a button/checkbox.

Do you guys want a separate search for un-answered questions versus a general search?

@PragTob
Copy link
Member

PragTob commented Aug 30, 2013

Sure later on this functionality should be with the search functionality. Right now there is no search functionality. So right now links/buttons/whatever that say "show only unanswered questions" are sufficient.

When we build search functionality this can be easily moved over, although we might want to keep the shortcut buttons.

@SoldierCoder
Copy link

I am of the opinion that to do this we will need to add either a count of the answers to Questions. I know someone will say, "wait, let the database give us our count." The problem comes in writing a scope that returns only unanswered questions. Everything I've seen of mongo_mapper says you can only do scopes that use the attributes of the object you are scoping. The closest thing to doing that is to select all questions then pare down that list like:
@all_questions.select {|q| (Answer.where(:question_id => q.id).count == 0)}

^^ returns a nice list of unanswered questions but it is not a scope and thus is not paginated or ordered as they would be if I could apply those scopes to one that would return unanswered questions.

@PragTob
Copy link
Member

PragTob commented Sep 9, 2013

Hi Ed,

after some looking in the mongo_mapper docs and through stackoverflow I also couldn't find out a clever database way to do this and it also seems like MongoDB isn't capable of this.

I'd slightly rephrase your query though: Question.all.select{|question| question.answers.empty?}

We probably should embed the answers document into the Questions document, but then we'd have to migrate old data so that's another story.

Cheers,
Tobi

@SoldierCoder
Copy link

Tobi,

Did you tell me that we were still using Active Record in places? Not for any data in Hackety.com right? What was the draw to Mongo, anyway?

On Sep 9, 2013, at 3:41 PM, Tobias Pfeiffer [email protected] wrote:

Hi Ed,

after some looking in the mongo_mapper docs and through stackoverflow I also couldn't find out a clever database way to do this and it also seems like MongoDB isn't capable of this.

I'd slightly rephrase your query though: Question.all.select{|question| question.answers.empty?}

We probably should embed the answers document into the Questions document, but then we'd have to migrate old data so that's another story.

Cheers,
Tobi


Reply to this email directly or view it on GitHub.

@PragTob
Copy link
Member

PragTob commented Sep 9, 2013

Not for any data, right. AR just seems to be hooked in to some parts of Rails pretty badly, see the discussion over here: #146 .

I wasn't around the project when it was first built and therefore not when the decision to use Mongo was made. So I don't know :-)

@jaredmoody
Copy link
Contributor Author

I'd vote for moving back to AR unless there's good reason that mongo was picked. It seems silly to try and model relational data with mongo; relational databases do this very well. I gave up on this filter since I'm not familiar with mongodb and I couldn't figure out how to do this otherwise simple thing.

@jrgifford
Copy link
Member

I'd second the motion @jaredmoody.

@abhirao
Copy link
Contributor

abhirao commented Sep 10, 2013

My concern would be mongo_mapper - don't think it is actively developed anymore.

This may be the query/scope you're looking for:

Question.where(:_id.nin => Answer.where(:question_id.exists => true).fields(:question_id).map(&:question_id).uniq)

I would hesitate from using it in prod because it really won't scale; it's loading all the answer ids. Joining in mongo is inefficient.

As has been suggested already I think the right way to do it in mongo would be to denormalize - start questions with an unanswered flag and flip the flag the first time an answer is provided.

@SoldierCoder
Copy link

There may be a way yet, Jared, but I tend to agree with you. Not just for the Unanswered Filter either. I recall there was more than one roadblock with trying to add Omniauthable authentications like Github, Twitter, Facebutt (er, I mean Facebook) and the like. If we were using AR it would have been done in the first week. On the other hand, I'd like to know why mongo was picked in the first place before second-guessing the original authors.

I'd vote for moving back to AR unless there's good reason that mongo was picked. It seems silly to try and model relational data with mongo; relational databases do this very well. I gave up on this filter since I'm not familiar with mongodb and I couldn't figure out how to do this otherwise simple thing.


Reply to this email directly or view it on GitHub.

@jacqueline-homan
Copy link

@jaredmoody and @jrgifford : I third it :)

Actually, it may be easier just redoing the app from scratch using AR and in Rails 4.0. That way, several issues can be taken care of in one fell swoop.

@steveklabnik
Copy link
Member

To be clear on the history: mongo is the datastore because at the time I originally wrote this code, mongo was my default data store that I wrote new projects with.

@SoldierCoder
Copy link

So, if it could be done, you'd be ok to switching to AR, or are there other overriding concerns?

On Sep 10, 2013, at 4:20 PM, Steve Klabnik [email protected] wrote:

To be clear on the history: mongo is the datastore because at the time I originally wrote this code, mongo was my default data store that I wrote new projects with.


Reply to this email directly or view it on GitHub.

@steveklabnik
Copy link
Member

I'd be okay with it.

The only concern is actually transferring the data over... always risky and stressful.

@PragTob
Copy link
Member

PragTob commented Sep 10, 2013

I'm also very concerned about moving the data over. I don't want to lose any data. Plus some application code has to be changed, we might use mongo features that you can not translate 1 to 1 etc.

@SoldierCoder
Copy link

Like what, for instance?

On Sep 10, 2013, at 6:14 PM, Tobias Pfeiffer [email protected] wrote:

I'm also very concerned about moving the data over. I don't want to lose any data. Plus some application code has to be changed, we might use mongo features that you can not translate 1 to 1 etc.


Reply to this email directly or view it on GitHub.

@PragTob
Copy link
Member

PragTob commented Sep 11, 2013

The model code has to be changed and translated to migrations (because atm we got the attributes defined in the model, which I actually like but that's another topic). MongoDB has kind of an own querying language which we use some times e.g. that $or, that can be translated easily though. I don't have the full overview, just mentioning the possibility.

Exchanging the ORM is not something a lot of people do in the Ruby world as far as I know :-)

@jacqueline-homan
Copy link

Hello again :)

I began an online course on MongoDB through 10Gen a couple days ago. Too bad it wasn't available earlier on in the Rails Girls SoC program. Also, tried Tobi's suggested syntax for the query while in pry (I LOVE pry), and that query works! I get a return of the questions I know for a fact have no answers. :) YAY! Now, on to fix the code block in the app accordingly. Thanks PragTob :)

@hcarreras
Copy link
Contributor

I see some inactivity... is someone working in this?

@PragTob
Copy link
Member

PragTob commented Nov 18, 2013

To my knowledge no one is actively working on this :-(

@hcarreras
Copy link
Contributor

Ok, I will work on this!

@PragTob
Copy link
Member

PragTob commented Nov 18, 2013

Thanks heaps 👍

@hcarreras
Copy link
Contributor

I would like to contribute, however, I don't understand how question work actually.
If I do rake routes to see all the routes it returns that question/ should be managed by the questions controller and the index action. But there is no index action defined if the controller questions!
Can someone explain to me how it works?
Thanks in advance!

@PragTob
Copy link
Member

PragTob commented Nov 20, 2013

That's some hardcore black magic.

E.g. The controller inherits from InheritedController which is part of the inherited resources gem to DRY up rails e.g. not have the same old actions rewritten in every control. You can hook into those actions or just overwrite the methods, there are a couple of samples in the code base.

Does this answer the question?

Tobi

@hcarreras
Copy link
Contributor

yeah actually it really looks like black magic!
thank you very much! I will try to understand better how it works before change anything. :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants