Hi Chamrouen Not sure if you've got this figured out - as far as I can tell, you're using :select correctly. However, you need to use the 'indexes' method inside your define_index block - not 'index'.
-- Pat On 25/11/2010, at 7:43 PM, chamroeun ou wrote: > I write the following code at the Businesslisting model > > define_index do > index business_name, :sortable=>true > index service > index description > index district.ename, :as=>:district_name > end > > -----------Controller Code > Businesslisting.search params[:keywords], > :select=>"business_name,email,telephone" > > > > On Thu, Nov 25, 2010 at 2:47 PM, chamroeun ou <[email protected]> wrote: > Thanks for your quick response > > We want only specific columns to be populated in the search results > i have tried this > BusinessListing.search "foo", :select => "id, column_a, column_b" > > But it returned null > > -------------------- > > I also try indexes location.district_name, :as => :district_name. It > works. But it's a full association not just district_name column. What > we actually want is just the single column. > > > We are using ThinkingSpinx for our CambodiaZoom.com website > > Chamroeun > > On 11/25/10, Pat Allan <[email protected]> wrote: > > On 25/11/2010, at 3:11 PM, chamroeun wrote: > > > >> I am a rookie in Thinking Sphinx for Rails. > >> > >> I am developing a business directory search. I have 2 tables > >> BusinessListing and Location. > >> > >> When Sphinx found a record, it will give all the fields in the table. > >> How can i select only the needed fields? > > > > Did you want to search on specific fields? Or did you want only specific > > columns to be populated in the search results? > > > > For the first, you'll want to look at the :conditions option: > > http://freelancing-god.github.com/ts/en/searching.html#conditions > > > > And read up on extended search syntax for more complex situations: > > http://www.sphinxsearch.com/docs/manual-0.9.9.html#extended-syntax > > > > For just specific columns (ie: ActiveRecord's :select option), you can just > > use :select in a search query, and it gets passed through to the underlying > > ActiveRecord::Base.find request: > > BusinessListing.search "foo", :select => "id, column_a, column_b" > > > >> And in another case, i also need reference to another > >> table(Businesslisting=>Location(district name). i need to retrieve the > >> district name to include in the resultset of businesslisting. how can > >> i do that? > > > > To include columns from associations in your indexes, you can just refer to > > the associations in your define_index block: > > > > define_index do > > # ... > > indexes location.district_name, :as => :district_name > > # ... > > end > > > > Cheers > > > > -- > > Pat > > > > -- > > You received this message because you are subscribed to the Google Groups > > "Thinking Sphinx" group. > > To post to this group, send email to [email protected]. > > To unsubscribe from this group, send email to > > [email protected]. > > For more options, visit this group at > > http://groups.google.com/group/thinking-sphinx?hl=en. > > > > > > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/thinking-sphinx?hl=en. -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
