npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

full-text-search-light

v0.0.18

Published

A pure in JS written full text search with an easy to use API.

Downloads

1,537

Readme

Full Text Search Light is a pure JS full text search engine with an ultrafast search and the following commands:

  • Add
  • Search
  • Remove
  • Save to file
  • Load from file

You can add every kind of data, also complex objects.

Install

From NPM

npm install full-text-search-light

From GitHub

npm install git+https://github.com/frankred/node-full-text-search-light.git

Documentation

Init

var fulltextsearchlight = require('full-text-search-light');
var search = new fulltextsearchlight();

You can also change some configuration values according to the full text search.

var fulltextsearchlight = require('full-text-search-light');
var search = new fulltextsearchlight({
  ignore_case: false,   // default = true, Ignore case during all search queries
  index_amount: 8;   // default = 12, The more indexes you have, the faster can be your search but the slower the 'add' method  gets
});

Add

// Add values
search.add('Peter');
search.add('Paul');
search.add('Maria');

You can also add objects or arrays to the search. Every child value will be added to the search, no matter if it's an array or object.

// Add objects
var obj = {
    name: 'Alexandra',
    age: 27,
    student: true,
    hobbies: ['Tennis', 'Football', 'Party'];
    car: {
        make: 'Volvo',
        year: 2012,
        topspeed: 280
    }
};

search.add(obj);

Add with filter

If you want to ignore fields you can pass a filter function. If you want to ignore a field or value just return false. If you return true or everything else the field is added to the index.

// Add filter, this function will be called on every single field
// If you don't want to add a field to the search just return false
var filter = function (key, val) {
    // Return false if you want to ignore field
    if (key == 'student' || key == 'topspeed') {
        return false;   // Ignore field
    }

    return true;    // Accept field
};

search.add(obj, filter);

Search

var results = search.search('p');
// results = ['Peter', 'Paul']

Remove

You can remove objects or values out of the search by saving the id which is returned from the add method.

// Add returns an id
var f = search.add("Frank");

// With that id you can remove the value from the search
search.remove(f);

// Returns an array with all result objects
var result = search.search('pau');
// result: ['Paul']

Save and Load

var fulltextsearchlight = require('full-text-search-light');
var search = new fulltextsearchlight();

// Add
search.add('Hello World');

// Save current db
search.save('search.json', function(error){

    // Load db
    fulltextsearchlight.load('search.json', function(error, search_loaded){
        var results = search_loaded.search('World');
    });
});

Save and Load (Sync)

var fulltextsearchlight = require('full-text-search-light');
var search = new fulltextsearchlight();

// Add
search.add('Hello World');

// Save current db
search.saveSync('search.json');

// Load db
var search_loaded = fulltextsearchlight.loadSync('search.json');
var results = search_loaded.search('World');

Functions

This are all functions that can be used.

add

  • search.add('Just a string value') - Add a string to the search, returns a unique id
  • search.add(obj) - Add a object to the search, returns a unique id

If you add numbers or booleans to the search they will be converted to strings.

  • search.add(false) - Add booelan to the search (ok this does not really make sense, but it works.), returns a unique id
  • search.add(42) - Add number to the search, returns a unique id

search

  • search.search('value') - Search for the string 'value'. Returns the results of the data as an array

remove

  • search.remove(1337) - Remove the data with the id 1337 from the search. This id was returned by adding a value or obj.

drop

  • search.drop() - Drops the search database and resets all data. The configuration is kept.

saveSync

  • search.saveSync('path/to/file.json') - Save current search db to a json file.

loadSync

  • fulltextsearchlight.loadSync('path/to/file.json') - Load a search from a file;

Run tests

You need mocha installed globally:

npm install -g mocha

Now you can run tests if you navigate to project root:

mocha test

##License MIT Free Software, Hell Yeah!