logo
down
shadow

Rails 4 returning records from multiple tables matching a search term


Rails 4 returning records from multiple tables matching a search term

By : OneD1s
Date : November 17 2020, 11:58 AM
I wish did fix the issue. You should the built in querying tools as much as possible. So assuming you have a Page class and and Article class you can use select and where
code :
matched_pages = Page.select(:title, :slug, :created_at, :content)
matched_articles = Articles.select(:title, :slug, :created_at, :content)
words.each do |word|
  matched_pages = matched_pages.where(["title LIKE :word OR content LIKE :word", {word: "%#{word}%"}])
  matched_articles = matched_articles.where(["title LIKE :word OR content LIKE :word", {word: "%#{word}%"}])
end
@search_results = matched_pages + matched_articles
<% @search_results.each do |item| %>
  <tr>
    <td><%= item.title %></td>
    <td><%= item.slug %></td>
    <td><%= item.created_at %></td>
    <td><%= item.content %></td>
    <td><%= item.class.name.downcase %></td>
  </tr>
<% end %>


Share : facebook icon twitter icon
JqGrid Search returning only one of the matching records

JqGrid Search returning only one of the matching records


By : user3435971
Date : March 29 2020, 07:55 AM
will be helpful for those in need Based on the @Oleg reply the problem was solved.
Only one record shown was due to the horizontal scroll bar overlapping the last row. And when ignoreCase:true was added to the jqgrid the search done in the jqgrid is now case insensitive.
Solr: Searching a term in multiple, indexed fields and returning top 'N' hits from each search field

Solr: Searching a term in multiple, indexed fields and returning top 'N' hits from each search field


By : Thawsitt
Date : March 29 2020, 07:55 AM
may help you . Boost can't help you control the results and distribute 5 each in the top 10 results.
Probably you can check on Field Collapsing, where you can group per role (Manager and Name) and limit 5 results for the group.
Take search term, check for it in database, returning matching term MySQL php

Take search term, check for it in database, returning matching term MySQL php


By : Mikael G
Date : March 29 2020, 07:55 AM
I wish this help you this seems like such a simple error, but i'm completely stuck. Here is the code: , This is your current query,
code :
SELECT `sciname` FROM `wp_birds` WHERE $searchbird = `comname`
SELECT `sciname` FROM `wp_birds` WHERE  `comname` = '$searchbird' 
PHP/Javascript search form returning all rows instead of ones matching search term

PHP/Javascript search form returning all rows instead of ones matching search term


By : Anita
Date : March 29 2020, 07:55 AM
this will help I've created the following search form, there aren't any errors, but instead of showing the rows that are similar to the search term, I just get the whole list of rows from the selected table in the database and I'm not sure why? , Change the jquery code
code :
   data:{search: d}
 isset($_post['search'])
isset($_post['data'])
How can I get matching records from multiple tables

How can I get matching records from multiple tables


By : junmo
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , How can I get records from tables that match at least in two tables? For example, all accounts that have same name. There can be many tables. PostgreSQL is used as a database. , You seem to want a full join:
code :
select t1.id, t2.id, t3.id
from t1 full join
     t2
     using (name) full join
     t3
     using (name)
where ( (t1.id is not null)::int +
        (t2.id is not null)::int +
        (t3.id is not null)::int
      ) >= 2;
select t1.id, t2.id, t3.id
from (select name, min(id) as id from t1) t1 full join
     (select name, min(id) as id from t2) t2
     using (name) full join
     (select name, min(id) as id from t3) t3
     using (name)
where ( (t1.id is not null)::int +
        (t2.id is not null)::int +
        (t3.id is not null)::int
      ) >= 2;
Related Posts Related Posts :
  • how to create two custom registration forms in devise?
  • Rails 4 link_to Destroy not working in Getting Started tutorial
  • How does ruby on rails dynamically define `find_by_id`, `find_by_name` methods?
  • JBuilder dynamic keys for model attributes
  • `initialize': No such file or directory - getaddrinfo (Errno::ENOENT) when Rails new app
  • What is the Ruby equivalent of Node.js' socket.io?
  • Where rails store standard helpers?
  • how to check expected result matches any of give values in rspec?
  • Form submission to create multiple objects
  • Simple Twitter Login with Rails and Email confirmation
  • Where should helpful functions for my controller go in Rails?
  • Using session variable in the Model or the other way
  • Why can't I have ruby code and comments in Embedded Ruby?
  • Rails: How can I make an object available in all views?
  • Cannot enter simply form information into SQLite DB (Rails)
  • Rails - Retain form values on failed submission. Getting "First argument in form cannot contain nil or be empty&quo
  • How to handle STI and build related models automatically?
  • Suppress an error when saving a record in Rails
  • Rails AJAX reload the page. Why?
  • How to pass user attributes to action mailer
  • Custom Validator to Prevent an appointment from being scheduled too early in day?
  • Postgres Enable TCP/IP Connection
  • How do I avoid the circular argument reference warning in activesupport
  • Unable to push to heroku master because of rails/spring version error
  • deep nested routes in rails
  • Best approach to Users Profile Images in Rails App
  • RailsInstaller: Can I maintain the gem fold when re-installing a new version?
  • couldn't find file 'jquery-ui' i get this error even after having this file in my application.js
  • Ruby regex to split user and date text input
  • Tool like BetterErrors for JRuby?
  • redirect_to in action destroy ruby on rails
  • Where are the I18n.t link and reference paths?
  • Sending emails to multiple recipients in rails app
  • Rails, Devise, Sign up = write name in other Database
  • pass custom attribute on rspec factory_girl controller test
  • rails generate uses wrong version of Ruby
  • Duplicate Requests from a Browser
  • One action in Rails controller sends no data back
  • Local data (JSON) in Middleman inside a different path than /data
  • How to pass numbers in an array into a SQL statement
  • ActiveAdmin - Allow non-logged-in users to view but not edit resources
  • How to refactor this Model logic in Rails
  • :readonly key of belongs_to method doesn't work
  • Create a new view in directory
  • nested resources in devise
  • Yaml value with a leading `!`
  • Rails admin show username instead of User #5
  • Can't start WEBrick with Byebug on
  • Failing Rspec test of a FactoryGirl object
  • engine yard No application found matching remotes:
  • Rails 4 sessions cookie is not set
  • How do I flush a class method in Rails 4 using memcached?
  • AJAX form submitting in HTML rails 4
  • Using greater than or less than in a Rails Active Record query
  • Searching Post by Origin & Destination locations using Geokit-Rails
  • Deploying application to two different servers, with different production.rb contents
  • Spree with deface - Use deface to replace contents of block
  • I need to change date part of DateTime variable
  • Ruby on Rails 4 - Using Rake on Heroku
  • Ruby symbol setup
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org