Searching sub-models with Ferret - ruby-on-rails

I have a rails app in which I am trying to do some full text searching on. Ferret seems to be the most popular choice. However, I have an issue.
I have a 'thing' which contains an id which determines if a user can see it (and therefore search it), but I want to search sub-models of this 'thing' which are related to my 'thing' but don't directly contain any references back to the user.
Therefore, how do I implement it? Is there a clever way of implementing this, or do I need to dirty my models with a link to the domain identifier?

I think it would be very wrong to assume that Ferret is the most popular choice for this. Most people I know have ditched Ferret and replaced it with Sphinx. And the people who can't use Sphinx for some reason have opted for Xapian.
That said, the answer to your question is likely to be largely the same regardless of the indexing system you choose:
When you're dealing with permissions and indexing, you can't effectively index anything related to the permissions system because it's going to be user-specific. All your permissions stuff needs to live in your models/controllers somewhere. I'm fond of putting all my permissions stuff in a module and then including it in my model, so that I can easily share it between models.
Pagination can be a real pain for this kind of thing because you request 10 items from your search engine, and then your permissions code rejects 5 of those items, which means you have to keep running searches until you have your first ten items to display. And now when you want page two, well, things turn into a real mess then. Heaven forbid they decide to skip straight to page ten, because now you can't do tricks like giving a start ID instead of a page number. Really, it's not something you want to do at all if you can help it.
There really are no "clever" ways of getting around the mismatch between permissions and full-text indexing. At least, none that I know of. It's just a pain.
I suggested to my boss when we first started out that the only sane solution was an egalitarian permissions system: If we gave you a username and password, then you have access. He wasn't a fan.

Related

Integrating GCS on a staging Jekyll website

We currently have a staging website, which has an IP address like xx.xx.xxx.xxx and we would like to have integrated and tested GCS on it before pushing it live. Is it possible?
Otherwise, is there any alternative to GCS to add a search bar in a Jekyll blog without using plugin?
Thanks!
PART I: Google
Google custom search cannot index an application that isn't available to the internet.
No, that's not entirely true. You can arrange something with Google (in theory, never done it) but it doesn't look easy. Or cheap.
You could set up a custom search for an unrelated site and embed those results in your local page, if you want to test out CSS prior to launch.
Remember, Google Custom Search also comes with ads, unless you pay. And the results tend to look like they came from Google.
PART II: Alternatives
I've looked into this extensively and I haven't come up with a good answer. Here are some not-so-good answers:
1) Tapir Search. This actually worked pretty well, but appears to have died. They do have recent twitter activity, however, so maybe worth checking back in a bit. twitter. It's basically a (free) front end for an elasticsearch server. I think. Neat service, obviously not super-dependable.
2) Go javascript. Lunr for example. There are many, many similar solutions available. Sadly, they are client-side and doing a full-text search on even a smallish blog type site can be very slow. Works okay if you limit the search to titles, but then...you're only searching titles.
3) Build a search engine server. Maybe some breed of Lucene. Upside: very robust search while keeping the snappy response of a flat HTML site. Downside: building and maintaining a search engine server is difficult, expensive and probably overkill.
4) Hosted search engine. Algolia for example. They're basically doing 3) for you. Relatively expensive (~$50/month) but well worth the cost, because, seriously, search engine servers are finicky and prone to explosions. I've never gone this route with Jekyll because I've never had a Jekyll project I was quite that serious about, but I did consider it.
If anyone has anything to add, I'd love to hear it. This question has been irritating me for a while.

Ruby on Rails friends list feature

I'm new here and I thought I could ask a topic about creating a friend's list for users in my small rails project, since I couldn't find an answer specific enough to what I'm looking for.
I'm trying to make a basic friend request, so that I can have users in a database use a 'friend' function to keep track of players they like, so that they can keep in contact, etc. I currently am thinking that I need to use a has_many relation in regards to setting things up, but I'm not quite sure where to take it from there, besides just having each user have a list of names they wish to keep. If that's how it's done, how would I code that so each user has a list of users they wish to keep, as well as remove, add, email, etc?
It depends on how much complete and complex you want to implement it into your project.
You may want to use a gem, like amistad or has_friendship, which are plain simple to install and use. You also have socialization, which has a follow/mention/like usage like Twitter does.
If you want to learn how to code that from scratch (e.g. educational purposes), this railscast is pretty good at explaining how to implement that feature.
And if you want something even more complex, you have some gems that gives you features that you usually have at a social network (friends, photos, personal blogs and so on...): social_stream or diaspora

Deciding between using an array attribute or a nested model

Possibly a fairly basic question, but bear with me.
I'm building a page which has a number of pieces of modular content, represented by a ContentBlock model. Each ContentBlock has at least one link, each of which has a couple of different attributes. My initial approach was to just add these links as an array to the model, as there didn't seem to be any real need to store them separately in the database, and they don't have any logic of their own. Now that I'm looking at building a form for creating/editing a ContentBlock though, it seems like it would be much easier to build if there was a separate, nested model for the links.
I'm strongly considering converting to using a model, but my gut feeling is that it's kind of "wrong" to store something like as relatively trivial as the links are in the DB. Given I am still getting used to working with Rails, is this feeling misplaced? Should I just create models for anything and everything? Or should I be looking for some sort of minimum criteria before I do?
It is definitely easier to create forms for nested models. Since your links have attributes, I'd suggest making a model. I tend to err on the side of making models for concepts that can't easily fit into fields. If you're worried about query performance, you can always do eager loading.
I think depends on how much data you plan on managing, what you want to do against that data, what that data represents, etc...
One project we had was to build something that allowed creation of recipes for a group of restaurants. Recipe (some text, like instructions, etc...) -> Ingredient, we went with an array, as these were all single lined text and there would never be more than several hand fulls. Also, the ingredients had no further dependencies. The Recipes would only be rendered out to html and there would be no searching against them (not against the db at least).
Another project required building a Page, very similar to yours, but each "component" of the page did different things and some where linked to other objects in the app, like Videos and other assets, templates, etc... We had seen people do this type of stuff entire through a wysiwyg or through some JS way and saved the entire payload/structure in the DB. We found both to be extremely messy.
And one concern that came up was what happened if an asset/associated object was mistakenly or purposely deleted but lived throughout many pages. Using models allowed to ensure that if something got removed, it got removed within all it's linked associations (though this posed problems of it's own, but more regarding the page making sense when displayed more than anything else).
Also, our Page had the potential of becoming extremely large with different types of components with different looks and inter-activities, that this really was the only way we could properly manage it.
So I would look at your requirements and plan accordingly, context matters. And if you have to change it (which happens, a lot) then you'll change it.

Web-based form-builder for users in Ruby/Rails

First time posting in Stack Overflow, hope I'm doing this right.
I'm writing an app with Ruby on Rails right now. Without disclosing too much, the premise is that we have organizations and normal users. Organizations have events, which require users to answer a questionnaire before participating.
I'm pretty sure about these models / relationships that I will be using (this isn't really that important/pertinent to my question i think, but just wanted to give background):
organization (one to many) events
event (one to one) quesitonnaire)
questionnaire (one to many) users
(specific) response (one to one) user
The part I have a question about is how to implement the questionnaire. I want to give the ability to Organizations to essentially write / build their own forms. I'd like to stay away from them using code if that's possible (ie any DSL and whatnot).
I suppose the easiest way to do this is to give them a set number of text-area responses, so that I can consistently store the data and don't have to hassle around with how to configure storing this data (for example, maybe each event can only have exactly 5 responses to be filled in by textfield response by the user).
My ideal would be for the organization to be able to dynamically generate the forms on their own - maybe one questionnaire will have 1 text input, followed by 3 multiple choices, and maybe 2 short answers at the end; another one may have 5 multiple choices, and 1 short answer; yet another questionnaire might only have 1 text input...you get the idea.
So I see two parts of this problem - the first is the user interface for the organization to create the questionnaire. i'm imagining this wouldn't be terribly hard - ask them how many of each response type (MC, short answer) they would like to put into the form, give them the ability to rearrange them, etc.
The second part of the problem (what I'm more concenred about) is how to store/access this data. I'm guessing there's no dynamic-attribute sort of deal in ruby - storing some field with an unspecified number of parts and whatnot. i suppose i could make them all individual models (ie a question_response model, with :question, :response_type, :response, etc), but I'm fairly certain that's probably inefficient.
My initial guess is probably to serialize the data / use json; I worked briefly with Drupal 6 and this seems to be the way they did it. I was wondering if anyone else had any experience / suggestions though? I'm pretty new to Ruby so I was wondering if there's a gem out there or something that would help with what I'm trying to do.
Thanks!
You might want to look at the Surveyor gem
http://vimeo.com/7051279
*slightly old how-to video
https://github.com/breakpointer/surveyor
Surveyor does come with it's own DSL which is relatively easy to use (although can be abit restrictive at times). The data is saved as a set of question - answer values, so there is no actual specific model (beyond Surveys -> Questions (question_groups) -> Answers).
Originally I did look at having people submit their own Surveyor DSL specs - which would then be used to generate the actual survey via a Rake command.
I think if you need to build a dynamic model (and save the data) it is possible, although I am not not sure if you'll be able to get the Rake tasks to run to build the actual tables in a dynamic way due to permission restrictions.
Have a look at http://ruby-metaprogramming.rubylearning.com/ and Metaprogramming Ruby: Program Like the Ruby Pros by Paolo Perrotta, for some starters.

Simple Framework or CMS for a trading platform?

I have a relatively simple site on my hands, and have for nearly a year, but I can't seem to find a platform to build it on that doesn't fight back at the way I want to do things. Here are the key features:
Customizable profiles. Profile tags.
Two primary content types: Haves & Wants
Both content types searchable/taggable and expire with a "Taken" symbol if user chooses.
Private messaging.
Daily cron attempts to find matches of Haves and Wants with similar tags and uses email alerts.
I think I can understand the logic of building this in Rails... but I'm too much of a noob to execute it. Is there a easier framework or cms out there that can produce something like this?
Additional information: We currently are using a modified version of the Classipress template for wordpress. It got us a little ways through development... but we can't seem to convince wordpress to post more than one type of content or tags. http://mybarterhub.com/
I wouldn't attempt something like this on Wordpress (not what it was designed for), but any of the frameworks you mention are more than capable. Have you looked at Drupal? I think it hits a sweet spot of allowing you to do a lot without actually programming, but also allowing programmers to customize it heavily through modules. It has a lot of the community and taxonomy features you need -- either built in or available through common modules.
If you're unable to get too deep into a framework like CakePHP, I would say Drupal is your best bet. Drupal is pretty non-coder friendly, but if you're going to make it work for projects that are more complex than out-of-the-box type situations, there's a slight learning curve.
There's at least one module that lets you use a custom Content Type for the user profile, which should allow you to tag profiles (the profile content type nodes) using the taxonomy module. Users in Drupal aren't nodes, so I'm guessing that's why tagging them wasn't working for you.
As for searches, all content should be indexed and searchable in Drupal as long as it's set up to do so. I'm not sure what modules are available for specifically searching by Taxonomy term, but, if you're using a tag system and you want to present haves/wants by tag, that's easy enough to set up with the wonderful Views module. A while ago I think I set up views that mirrored the taxonomy vocab/term structure and just redirected to the view using a Taxonomy Redirect module when someone clicked on a tag.
I think that if you can't make it work in Drupal for some reason (or you really don't like Drupal), you'd have to get into CakePHP or one of the other frameworks out there, but Drupal is definitely able to accomplish what you're aiming to do, probably without any custom PHP coding involved if you got all the right modules together.

Resources