hi
i am implimenting the search function using tags.
i have tables called streams and tags.
each entry of the table have a single or multiple tagnames(i am using acts_as_taggable_on_steroids for tagging).
streams table and correspong tagname to the table entries given below
name resolution codecname framerate tags dust.mpeg2 1920x1080 mpeg2 30fps mpeg2 1920x1080 mummy.264 1920x1080 h264 30fps h264 1920x1080 dust.aac na aac na aac amelie.mpeg2 720x480 mpeg2 25fps 720x480
I have implimented a search function it will take search string as input from the search box created and it will list out the corresponding stream names .
example: search box entry is: dust.aac output is :dust.aac
But my requirement is if i use the tag name as the search box entry i should get the details of streams from the stream table with tag matching to that streams. e.g: search box entry is:aac expected output is:dust.aac
i am getting the error like : Mysql::Error: Unknown column 'tag' in 'where clause': SELECT * FROM `streams` WHERE ((LOWER(tag) LIKE '%h%'))
below is the my application to impliment the search function based on tag name entry:
1)in index file i have added the code to create the search box:
Search: <input type="string" id="search_form" name="search" /> <img id="spinner" src="/images/indicator.gif" style="display: none;" /
<div id="results"></div> <%= observe_field 'search_form', :frequency => 0.5, :update => 'results', :url => { :controller => 'streams', :action=> 'get_results' }, :with => "'search_text=' + escape(value)", :loading => "document.getElementById ('spinner').style.display='inline'", :loaded => "document.getElementById('spinner').style.display='none'" %> this code is able to take the string what we enterd.
2)to do the search function i have added a method in controller like this: def get_results if request.xhr? if params['search_text'].strip.length > 0 terms = params['search_text'].split.collect do |word| "%#{word.downcase}%" end if blank? flash[:notice] = 'Stream was successfully updated.' else @streams = Stream.find_tagged_with( :all, :conditions => [ ( ["(LOWER(name) LIKE ?)"] * terms.size ).join(" AND "), * terms.flatten ] ) end end render :partial => "search" else redirect_to :action => "index" end throwing errors like: Mysql::Error: Column 'name' in where clause is ambiguous: SELECT DISTINCT streams.* FROM `streams` INNER JOIN taggings streams_taggings ON streams_taggings.taggable_id = streams.id AND streams_taggings.taggable_type = 'Stream' INNER JOIN tags streams_tags ON streams_tags.id = streams_taggings.tag_id WHERE ((LOWER(name) LIKE '%dust%') AND (streams_tags.name LIKE 'all')) 3)the result is collecting in _search.html.erb looks like
% if @streams %> <ul> <% for stream in @streams %> <li> <%= h(stream.name) %> </li> <% end %> </ul> <% end %>
i have to impliment the same functionality with tag name as the entry for search how can i do that. give some ideas to make it work.
thanks sriaknth