Sorry, I wasn’t clear - this code:
<ul>
<% class_facets(@facets) do |option, count| %>
<li><%= link_to "#{option} (#{count})", :params => {facet => option, :page
=> 1} %></li>
<% end %>
</ul>
Should replace this code:
<% @facets.each do |facet, facet_options| %>
<% facet %>
<ul>
<% facet_options.each do |option, count| %>
<li><%= link_to "#{option} (#{count})", :params => {facet => option,
:page => 1} %></li>
<% end %>
</ul>
<% end %>
This means you’re no longer iterating through all facets, just using the
results from one of them to get what you need.
—
Pat
On 26 Mar 2014, at 10:27 pm, Георгий Погосян <[email protected]> wrote:
> Pat, you will be laughing, but you have just solved the second problem) The
> first problem is still exist)
> The result after you update:
> All (6)
> sphinx_internal_class
> Page (3)
> Catalog (3)
> Article (0)
> Product (0)
> SpecialOffer (0)
> class
> Page (3)
> Catalog (3)
> Article (0)
> Product (0)
> SpecialOffer (0)
>
> среда, 26 марта 2014 г., 15:14:31 UTC+4 пользователь Pat Allan написал:
> Unfortunately, Sphinx doesn’t return any information for facets that have no
> values. As for the first problem, if you only want one facet, then you can
> just use that facet and give it whatever label you like (if it needs a
> label). Here’s an approach that may work:
>
> # in a helper:
> def class_facets(facets)
> %w( Page Catalog Article Product SpecialOffer ).each do |class_name|
> yield class_name, facets[:class][class_name] || 0
> end
> end
>
> # in the view
> <ul>
> <% class_facets(@facets) do |option, count| %>
> <li><%= link_to "#{option} (#{count})", :params => {facet => option,
> :page => 1} %></li>
> <% end %>
> </ul>
>
> —
> Pat
>
> On 26 Mar 2014, at 10:08 pm, Георгий Погосян <[email protected]> wrote:
>
> > The first problem, Yes you're right - is that i have two sets of facet
> > results and the second problem that i have 5 models, but facet shows only 2
> > of them, but i want tho have something like this
> > Total (20)
> > Page (5)
> > Catalog (10)
> > Article (0)
> > Product (0)
> > SpecialOffer (5)
> >
> > среда, 26 марта 2014 г., 15:04:02 UTC+4 пользователь Pat Allan написал:
> > I think I’ve misunderstood your original question.
> >
> > Is the problem that you’re getting two sets of facet results?
> >
> > On 26 Mar 2014, at 10:00 pm, Георгий Погосян <[email protected]> wrote:
> >
> >> The result is correct - 6. The query is in Page (3) and Catalog (3)
> >>
> >> среда, 26 марта 2014 г., 14:54:47 UTC+4 пользователь Pat Allan написал:
> >> What’s the output of @results.total_entries ?
> >>
> >> On 26 Mar 2014, at 9:53 pm, Георгий Погосян <[email protected]> wrote:
> >>
> >>> No, the same result
> >>>
> >>> среда, 26 марта 2014 г., 14:30:50 UTC+4 пользователь Pat Allan написал:
> >>> What if you try getting the facets directly, instead of via the search:
> >>>
> >>> @facets = ThinkingSphinx.facets params[:query]
> >>>
> >>> I think the per_page and page options may be getting in the way of the
> >>> full set of results.
> >>>
> >>> On 26 Mar 2014, at 9:19 pm, Георгий Погосян <[email protected]> wrote:
> >>>
> >>>> Hi, Pat!
> >>>>
> >>>> I can't understand how to get the model_names on which there is proper
> >>>> indexing and search on the search results page.
> >>>> The idea is to show the total entries for each model.
> >>>> For example: Total (40)
> >>>> Pages (10)
> >>>> Products (30)
> >>>>
> >>>> If I understand correctly now it is realized through the facet. I did as
> >>>> in the example, but the result is not what I need.
> >>>>
> >>>> Here's my SearchController:
> >>>> @results = ThinkingSphinx.search(params[:query], :page => params[:page],
> >>>> :order => 'created_at DESC', :per_page => 10)
> >>>> @facets = @results.facets
> >>>>
> >>>> View:
> >>>> <ul class="detailed">
> >>>> <%= @results.total_entries %>
> >>>> <% @facets.each do |facet, facet_options| %>
> >>>> <% facet %>
> >>>> <ul>
> >>>> <% facet_options.each do |option, count| %>
> >>>> <li><%= link_to "#{option} (#{count})", :params
> >>>> => {facet => option, :page => 1} %></li>
> >>>> <% end %>
> >>>> </ul>
> >>>> <% end %>
> >>>> </ul>
> >>>> <ul class="results">
> >>>> <% @results.each do |result| %>
> >>>> <li><%= render :partial =>
> >>>> partial_for_search_result(result), :locals => {:result => result}
> >>>> %></li>
> >>>> <% end %>
> >>>> </ul>
> >>>>
> >>>> And the result is:
> >>>> sphinx_internal_class
> >>>> Catalog (3)
> >>>> Page (3)
> >>>>
> >>>> class
> >>>> Catalog (3)
> >>>> Page (3)
> >>>>
> >>>> My TS version 3.1.0
> >>>>
> >>>> --
> >>>> You received this message because you are subscribed to the Google
> >>>> Groups "Thinking Sphinx" group.
> >>>> To unsubscribe from this group and stop receiving emails from it, send
> >>>> an email to [email protected].
> >>>> To post to this group, send email to [email protected].
> >>>> Visit this group at http://groups.google.com/group/thinking-sphinx.
> >>>> For more options, visit https://groups.google.com/d/optout.
> >>>
> >>>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups
> >>> "Thinking Sphinx" group.
> >>> To unsubscribe from this group and stop receiving emails from it, send an
> >>> email to [email protected].
> >>> To post to this group, send email to [email protected].
> >>> Visit this group at http://groups.google.com/group/thinking-sphinx.
> >>> For more options, visit https://groups.google.com/d/optout.
> >>
> >>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "Thinking Sphinx" group.
> >> To unsubscribe from this group and stop receiving emails from it, send an
> >> email to [email protected].
> >> To post to this group, send email to [email protected].
> >> Visit this group at http://groups.google.com/group/thinking-sphinx.
> >> For more options, visit https://groups.google.com/d/optout.
> >
> >
> > --
> > You received this message because you are subscribed to the Google Groups
> > "Thinking Sphinx" group.
> > To unsubscribe from this group and stop receiving emails from it, send an
> > email to [email protected].
> > To post to this group, send email to [email protected].
> > Visit this group at http://groups.google.com/group/thinking-sphinx.
> > For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/d/optout.