Type-ahead site search

Ternwords

Ternary trie of words

by Read Write Tools
Abstract
The ternwords JavaScript library parses the contents of a SITEWORDS file into memory for use with the rwt-search DOM component.

Motivation

Websites using the rwt-search DOM component need to access a ternary-trie of words and the documents where those words are found. This library is used to populate that ternary-trie with the contents of a file retrieved via an AJAX call.

Installation

The ternwords library may be installed directly from github or via NPM.

Node.js

To add the library to a node.js project, use this command:

[user@host]# npm install ternwords

Node.js project usage:

import FileInterface  from '/node_modules/ternwords/esm/file-interface.class.js';
import TernWords from '/node_modules/ternwords/esm/tern-words.class.js';

var fileInterface = new FileInterface();
var ternWords = new TernWords();
fileInterface.readSiteWords('sitewords-data', ternWords);

Browser

To add the library to a browser project, use this command:

[user@host]# git clone https://github.com/readwritetools/ternwords.git

Browser project usage:

import TextInterface  from '/ternwords/esm/text-interface.class.js';
import TernWords from '/ternwords/esm/tern-words.class.js';

var textInterface = new TextInterface();
var ternWords = new TernWords();
var textBlob = localStorage.getItem('sitewords-data');
var textInterface.readSiteWords(textBlob, this.ternWords);

Metadata

Dependencies

This library depends on softlib and iolib, which should be installed side-by-side.

Module exports

ES modules true
Common JS false

Suitability

Browser API
node.js API

Availability

Read Write Hub logo Documentation Read Write Hub
git logo Source code github
npm logo Package installation npm

License

The ternwords library is not freeware. After evaluating it and before using it in a public-facing website, eBook, mobile app, or desktop application, you must obtain a license from Read Write Tools as part of the rwt-search DOM component.

Site Search Software License Agreement

Copyright © 2022 Read Write Tools.

  1. This Software License Agreement ("Agreement") is a legal contract between you and Read Write Tools ("RWT"). The "Materials" subject to this Agreement include the "Site Search" software and associated documentation.
  2. By using these Materials, you agree to abide by the terms and conditions of this Agreement.
  3. The Materials are protected by United States copyright law, and international treaties on intellectual property rights. The Materials are licensed, not sold to you, and can only be used in accordance with the terms of this Agreement. RWT is and remains the owner of all titles, rights and interests in the Materials, and RWT reserves all rights not specifically granted under this Agreement.
  4. Subject to the terms of this Agreement, RWT hereby grants to you a limited, non-exclusive license to use the Materials subject to the following conditions:
    • You may not distribute, publish, sub-license, sell, rent, or lease the Materials.
    • You may not decompile or reverse engineer any source code included in the software.
    • You may not modify or extend any source code included in the software.
    • Your license to use the software is limited to the purpose for which it was originally intended, and does not include permission to extract, link to, or use parts on a separate basis.
  5. Each paid license allows use of the Materials under one "Fair Use Setting". Separate usage requires the purchase of a separate license. Fair Use Settings include, but are not limited to: eBooks, mobile apps, desktop applications and websites. The determination of a Fair Use Setting is made at the sole discretion of RWT. For example, and not by way of limitation, a Fair Use Setting may be one of these:
    • An eBook published under a single title and author.
    • A mobile app for distribution under a single app name.
    • A desktop application published under a single application name.
    • A website published under a single domain name. For this purpose, and by way of example, the domain names "alpha.example.com" and "beta.example.com" are considered to be separate websites.
    • A load-balanced collection of web servers, used to provide access to a single website under a single domain name.
  6. THE MATERIALS ARE PROVIDED BY READ WRITE TOOLS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL READ WRITE TOOLS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  7. This license is effective for a one year period from the date of purchase or until terminated by you or Read Write Tools. Continued use, publication, or distribution of the Materials after the one year period, under any of this Agreement's Fair Use Settings, is subject to the renewal of this license.
  8. Products or services that you sell to third parties, during the valid license period of this Agreement and in compliance with the Fair Use Settings provision, may continue to be used by third parties after the effective period of your license.
  9. If you decide not to renew this license, you must remove the software from any eBook, mobile app, desktop application, web page or other product or service where it is being used.
  10. Without prejudice to any other rights, RWT may terminate your right to use the Materials if you fail to comply with the terms of this Agreement. In such event, you shall uninstall and delete all copies of the Materials.
  11. This Agreement is governed by and interpreted in accordance with the laws of the State of California. If for any reason a court of competent jurisdiction finds any provision of the Agreement to be unenforceable, that provision will be enforced to the maximum extent possible to effectuate the intent of the parties and the remainder of the Agreement shall continue in full force and effect.

Ternwords — Ternary trie of words

🔗 🔎