facets with v3

101 views
Skip to first unread message

pix_plm

unread,
Jun 13, 2013, 5:21:14 AM6/13/13
to thinkin...@googlegroups.com
Hi,
I am having problems with facets after updating to TS V3, for some reason facets don't return all parameters and I don't understand what are the criterias ?
I use facets to get number of images per provider (provider_id), calling Image.facets :with { :provider_id => provs_list }

facets.inspect => **** #<ThinkingSphinx::FacetSearch:0x00000006bc1ff0 @options={:with=>{:provider_id=>[99, 92, 150, 28, 116, 170, 45, 25, 74, 21, 3, 55, 12, 71, 93, 27, 79, 98, 52, 152, 65, 151, 38, 155, 115, 161, 53, 124, 106, 4, 133, 68, 156, 121, 134, 39, 117, 86, 26, 48, 67, 13, 167, 33, 162, 34, 22, 85, 15, 90, 47, 69, 18, 168, 163, 147, 153, 166, 59, 63, 131, 75, 154, 105, 41, 64, 119, 139, 84, 118, 94, 107, 96, 31, 113, 165, 40, 149, 35, 158, 8, 70, 112, 76, 97, 17, 109, 145, 137, 110, 11, 58, 7, 43, 16, 51, 1, 50, 10, 83, 36, 102, 169, 159, 111, 123, 19, 91, 66, 101, 160], :content_error=>0}, :classes=>[Image(id: integer, ...)]}, @query=nil, @hash={}>

results :
facets[:provider_id] => {4=>167153, 7=>185846, 10=>26215, 13=>88504, 17=>617844, 16=>53911, 18=>105185, 19=>12223, 21=>361506, 15=>59375, 26=>261693, 25=>27155, 27=>156428, 33=>553155, 31=>129199, 34=>719638, 22=>151379, 35=>3216, 36=>126032, 38=>19279}

I don't understand why I don't get all providers results ?
 
I am running rails 3.2.13, ts 3.0.3, sphinx 2.0.7

indices for Image Model

ThinkingSphinx::Index.define(:image, :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta) do
  indexes :title, :subject,  ...
  # attributes
  has :ratio, :reception_date ...
  has :provider_id, :facet => true
end

Any idea ?
Thanks
Patrick


Pat Allan

unread,
Jun 13, 2013, 10:33:18 AM6/13/13
to thinkin...@googlegroups.com
Hi Patrick

Can you try setting max_matches and limit in your search call to 1000?

Image.facets(
:with => {:provider_id => provs_list},
:max_matches => 1000,
:limit => 1000
)

--
Pat

> --
> 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 thinking-sphi...@googlegroups.com.
> To post to this group, send email to thinkin...@googlegroups.com.
> Visit this group at http://groups.google.com/group/thinking-sphinx?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



Patrick Lamotte

unread,
Jun 13, 2013, 10:53:15 AM6/13/13
to thinkin...@googlegroups.com
Hi Pat,
Thanks, it worked that way, but is it the good way to do it now ? it worked before with v2 ?
Thanks again,best regards

Patrick
> You received this message because you are subscribed to a topic in the Google Groups "Thinking Sphinx" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/thinking-sphinx/yiF1CHH9XAA/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to thinking-sphi...@googlegroups.com.

Pat Allan

unread,
Jun 13, 2013, 10:56:30 AM6/13/13
to thinkin...@googlegroups.com
Just looked at the v1/v2 source, I was setting max_matches/limit then, but I'm not with the v3 branch - I'll need to fix that! In the meantime, using those options will deal with the problem.

Sorry for the hassle.

--
Pat

Patrick Lamotte

unread,
Jun 13, 2013, 10:58:14 AM6/13/13
to thinkin...@googlegroups.com
ok, don't worry
Thanks for answering so quickly everytime
Best
Patrick

Pat Allan

unread,
Jun 13, 2013, 10:58:35 PM6/13/13
to thinkin...@googlegroups.com
Just pushed a fix, it'll be part of 3.0.4 when that gets released :)

Patrick Lamotte

unread,
Jul 15, 2013, 10:39:00 AM7/15/13
to thinkin...@googlegroups.com
Hi Pat,

I updated to 3.0.4, but I still got an error with facets
ThinkingSphinx::SphinxError (query 0 error: offset out of bounds (offset=20, max_matches=20); query 1 error: offset out of bounds (offset=20, max_matches=20)):

20 is results per page(if I choose 40 then error will offset=40, max_matches=40)
if I set max_matches and limit in the search, to 1000 for instance, then same error with offset=1000, max_matches=1000

No problem with text searches, any idea ?

Thanks, regards

Patrick
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/thinking-sphinx/yiF1CHH9XAA/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to thinking-sphi...@googlegroups.com.
> To post to this group, send email to thinkin...@googlegroups.com.
> Visit this group at http://groups.google.com/group/thinking-sphinx.

Pat Allan

unread,
Jul 15, 2013, 7:42:17 PM7/15/13
to thinkin...@googlegroups.com
Hi Patrick

Are you passing in a :page or :offset option to your search? It looks like it's trying to request the second page of results, but there's only one, due to max_matches being set to the largest possible page size.

So, if you are using :page or :offset, remove that option, see if that helps.

Cheers

--
Pat

Patrick Lamotte

unread,
Jul 16, 2013, 5:02:25 AM7/16/13
to thinkin...@googlegroups.com
Hi Pat,

Yes it happens only when one tries to show page 2, so there is a :page option in the search.
max_matches is set up in the config file, but not in the search, I tried to pass max_matches in the search, it's ok for the first page but same error offset out of bounds with max_matches number set up in the search, instead of per_page option.
It works fine with TS 3.0.3 and it's only when facets are requested, text searches work fine.
Thanks, regards

Patrick

Pat Allan

unread,
Jul 16, 2013, 6:27:20 AM7/16/13
to thinkin...@googlegroups.com
Can you share with us the full facet search call?

Patrick Lamotte

unread,
Jul 16, 2013, 6:37:55 AM7/16/13
to thinkin...@googlegroups.com
cearch[:per_page] = val_def_ppage #user default
cearch[:per_page] = @current_params["per_page"].to_i if @current_params["per_page"] #unless it was changed in the search
cearch[:page] = params["page"].to_i if params["page"]

keywords = @current_params["key_words"] ? Pixways::SearchesHelper.filter_keywords(@current_params["key_words"]) : ''
cearch[:match_mode] = :extended
@medias = Image.search(keywords, cearch)

@medias.context[:panes] << ThinkingSphinx::Panes::ExcerptsPane
@nb_images = {}
facets = Image.facets(keywords, cearch)
@nb_images = facets[:provider_id]

the error is in the last line @nb_images = facets[:provider_id]

indices => image_index.rb
ThinkingSphinx::Index.define(:image, :with => :active_record, :delta => ThinkingSphinx::Deltas::DelayedDelta) do
indexes :title, :subject ...
# attributes
has :ratio, :reception_date ...
has :provider_id, :facet => true



Pat Allan

unread,
Jul 16, 2013, 7:29:55 AM7/16/13
to thinkin...@googlegroups.com
There's not much point passing :per_page into the facet call - it's going to grab all the results in one hit anyway (hence why it's picking up on the max_matches value).

So, instead of "facets = Image.facets(keywords, cearch)", try "facets = Image.facets(keywords, cearch.except(:per_page))".

Patrick Lamotte

unread,
Jul 16, 2013, 8:13:54 AM7/16/13
to thinkin...@googlegroups.com
yes you're right, but I tried with except and recreating cearch without the per_page option and i've got the same error with offset and max_matches equal to the config file
ThinkingSphinx::SphinxError (query 0 error: offset out of bounds (offset=10000, max_matches=10000); query 1 error: offset out of bounds (offset=10000, max_matches=10000)):

Pat Allan

unread,
Jul 16, 2013, 8:18:33 AM7/16/13
to thinkin...@googlegroups.com
Ah, sorry, remove :page as well:

facets = Image.facets(keywords, cearch.except(:page, :per_page))

Patrick Lamotte

unread,
Jul 16, 2013, 8:35:38 AM7/16/13
to thinkin...@googlegroups.com
ok it works, so I'll remove the per_page and :page every time I use facets, it is logical actually
Many thanks, and nice summer (it's winter in australia isn't it ?
Patrick

Pat Allan

unread,
Jul 16, 2013, 2:12:17 PM7/16/13
to thinkin...@googlegroups.com
It is winter here - some warmer weather would be nice :)

Great to know it's working now!

Patrick Lamotte

unread,
Aug 8, 2013, 4:17:31 AM8/8/13
to thinkin...@googlegroups.com
Hi Pat,

Sorry to disturb you again but I have another problem using Thinking Sphinx with delta

I set up my index with delta => true : : ThinkingSphinx::Index.define(:image, :with => :active_record, :delta => true) do
I have a rails app which read ftp folders and update the mysql database to feed images with delta to true.
I have a cron which launch sphinx indexer rotate delta every 10'
but now every time an image is saved with active-record (Model.save) from the ftp app, rotate delta is launched and the next image will be got only when rotate is finished (about 3'), any idea why ?

What I could do is using delayed_delta, it works, but I prefer not using delayed_job

TS 3.0.4
rails 3.2.13
Sphinx 2.0.8

Thanks, regards
Patrick

Pat Allan

unread,
Aug 8, 2013, 7:06:12 AM8/8/13
to thinkin...@googlegroups.com
Hi Patrick

The default delta approach will invoke the deltas immediately, so I presume that's what prompted the delay. If you don't want deltas firing, perhaps suspend deltas in an initialiser:

ThinkingSphinx::Deltas.suspend!

This will keep the delta values in your models set to true, but won't fire off the actual indexing/rotation.

There's also options of Sidekiq and Resque if you don't want to use Delayed Job but do have either of those other queues being used.

Cheers

--
Pat

Patrick Lamotte

unread,
Aug 8, 2013, 9:24:21 AM8/8/13
to thinkin...@googlegroups.com
thanks, it was the solution
all the best
Patrick
Reply all
Reply to author
Forward
0 new messages