Unique keys for Sphinx along three vectors instead of two
Posted
by Brendon Muir
on Stack Overflow
See other posts from Stack Overflow
or by Brendon Muir
Published on 2009-12-18T03:05:55Z
Indexed on
2010/04/14
4:43 UTC
Read the original article
Hit count: 297
I'm trying to implement thinking-sphinx across multiple 'sites' hosted under a single rails application. I'm working with the developer of thinking-sphinx to sort through the finer details and am making good progress, but I need help with a maths problem:
Usually the formula for making a unique ID in a thinking-sphinx search index is to take the id, multiply it by the total number of models that are searchable, and add the number of the currently indexed model:
id * total_models + current_model
This works well, but now I also through an entity_id into the mix, so there are three vextors for making this ID unique. Could someone help me figure out the equation to gaurantee that the id's will never collide using these three variables:
id, total_models, total_entities
The entity ID is an integer.
I thought of:
id * (total_models + total_entities) + (current_model + current_entity)
but that results in collisions.
Any help would be greatly appreciated :)
© Stack Overflow or respective owner