Code Monkey home page Code Monkey logo

alternator's Introduction

Alternate UDF

Alternate is user defined function for sphinx. The function initializes the map (associative array) in form (attribute => counter) before query. Then during the query sphinx performs this function for each document and increments the internal counter if such attribute already existed. As result, this counter is appeared for each docid. This is essentially the position of the document in scope of attribute.

Examples:

SELECT alternate(company_id) AS alt_pos, sorted_name, company_id FROM product WHERE company_id IN (13497, 12229) ORDER BY company_id ASC, alt_pos ASC;

+---------+------------------------------------------------------------------------------------------------------------------------------------------+------------+
| alt_pos | sorted_name                                                                                                                              | company_id |
+---------+------------------------------------------------------------------------------------------------------------------------------------------+------------+
|       1 | ремонтная смесь мбр400 машинного нанесения, 25кг                                                                                         |      12229 |
|       2 | ремонтный состав для бетона мбр-500 гора хрустальная, 25 кг                                                                              |      12229 |
|       3 | смесь ремонтная для бетона гора хрустальная мбр 300 литьевой тип 25кг                                                                    |      12229 |
|       1 | стул для кафе герцог №2                                                                                                                  |      13497 |
|       2 | стул для столовой №1ш                                                                                                                    |      13497 |
|       3 | вешало напольное № 3ш гардеробное                                                                                                        |      13497 |

SELECT alternate(company_id) AS alt_pos, sorted_name, company_id FROM product WHERE company_id IN (13497, 12229) ORDER BY alt_pos ASC LIMIT 100;
+---------+------------------------------------------------------------------------------------------------------------------------------------------+------------+
| alt_pos | sorted_name                                                                                                                              | company_id |
+---------+------------------------------------------------------------------------------------------------------------------------------------------+------------+
|       1 | стул для кафе герцог №2                                                                                                                  |      13497 |
|       1 | ремонтная смесь мбр400 машинного нанесения, 25кг                                                                                         |      12229 |
|       2 | стул для столовой №1ш                                                                                                                    |      13497 |
|       2 | ремонтный состав для бетона мбр-500 гора хрустальная, 25 кг                                                                              |      12229 |
|       3 | вешало напольное № 3ш гардеробное                                                                                                        |      13497 |
|       3 | смесь ремонтная для бетона гора хрустальная мбр 300 литьевой тип 25кг                                                                    |      12229 |
|       4 | табурет м квадратный (корич-антик)                                                                                                       |      13497 |
|       4 | смесь ремонтная для бетона гора хрустальная мбр 700 25кг литьевой тип                                                                    |      12229 |
|       5 | стул для офиса аскона                                                                                                                    |      13497 |
|       5 | смесь ремонтная для бетона мбр-600 литьевой тип                                                                                          |      12229 |
|       6 | стул офисный серена                                                                                                                      |      13497 |
|       6 | столешницы из кварцевого агломерата для столиков кафе, ресторанов                                                                        |      12229 |

alternator's People

Contributors

ashalaev avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.