Code Monkey home page Code Monkey logo

memsort's Introduction

Pre-order and cache sequences for sorting

This module allows you to create a pre-sorted sequence in memory to speed up sorting via "order by" in XQuery. Create an ordered sequence using memsort:create by mapping each element to a sort key (an arbitrary atomic value). Calling memsort:get for the same element at any later point will return an integer corresponding to the ordinal position of that element in the sorted sequence (or empty if no mapping is found).

Example for creating a sorted sequence:

declare namespace tei="http://www.tei-c.org/ns/1.0";

import module namespace memsort="http://exist-db.org/xquery/memsort" at "java:org.existdb.memsort.SortModule";

memsort:create(
    "record-date", 
    collection("/db/apps/my-data")//record,
    function($div) {
        $div/@date/xs:dateTime(.)
    }
)

Example for using the index in a query, assuming $hits are records returned by a lucene full text search:

for $hit in $hits
order by memsort:get("record-date", $hit) ascending empty greatest, ft:score($hit) descending
return
    $hit

This will first sort by date, then by full text match score. Records without date will appear at the end (due to "empty greatest").

Building

If you want to create an EXPath Package for the app, you can run:

$ mvn package

There will be a .xar file in the target/ sub-folder.

memsort's People

Contributors

wolfgangmm avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gawati

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.