Exemplo n.º 1
0
      .then(bics => {

        console.log('Generating bic index');

        //elasticlunr.Configuration({fields: {}});

        var idx = elasticlunr(function() {
          this.setRef('code');

          this.addField('code');
          this.addField('desc');

          this.addField('industryName');
          this.addField('divisionName');
          this.addField('className');
          this.addField('cu');
          this.addField('anzsic');

          this.addField('keywordsFlattened');
          this.addField('definitionPlainText');

          this.saveDocument(false);
        });

        idx.pipeline.add(
          elasticlunr.trimmer,
          elasticlunr.stopWordFilter,
          elasticlunr.stemmer
        );

        //TODO promise this as to not halt event que?

        bicStore = {};

        return delay(1000).then(()=> {
          return Promise.all(_.map(bics, (bic, index) => {
            return delay(index).then(() => {
              bic.keywordsFlattened = bic.keywords && bic.keywords.join(' ') || '';
              idx.addDoc(bic);
              bicStore[bic.code.toString()] = bic;
            });
          }));
        })
        .then(bics => {
            return bicIndex = idx; //jshint ignore:line
          });

      });
Exemplo n.º 2
0
                return self.read('./db/terms/' + term.code + '.json').then(function(courses) {
                    self.index[term.code] = elasticlunr();

                    self.index[term.code].addField('c');
                    self.index[term.code].addField('n');
                    self.index[term.code].addField('f');
                    self.index[term.code].addField('la');
                    self.index[term.code].addField('d');
                    self.index[term.code].setRef('b');
                    self.index[term.code].saveDocument(false);

                    return Promise.map(Object.keys(courses), function(subject) {
                        return Promise.map(courses[subject], function(course) {
                            if (course.num) {
                                course.c = subject + ' ' + course.c;
                                //course.lo = course.loc;
                                course.c = course.c.split(/(\d+)/).map(function(el) { return el.replace(/\s+/g, ''); }).join(' ')
                                course.n = course.n;
                                course.f = course.ins.f;
                                course.la = course.ins.l;
                                course.d = course.ins.d[0];
                                course.b = course.num;
                                self.index[term.code].addDoc(course);
                            }else{
                                console.log('No course number found, skipping...')
                            }
                        }, { concurrency: 50 })
                    }, { concurrency: 2 }).then(function() {
                        self.indexTimestamp[term.code] = Math.round(+new Date()/1000)
                        console.log('Saving term index', term.name)
                        return self.write('./db/index/' + term.code + '.json', self.index[term.code].toJSON())
                        .then(function() {
                            return self.write('./db/timestamp/index/' + term.code + '.json', self.indexTimestamp[term.code]).then(function() {
                                delete self.index[term.code];
                            })
                        })
                    })
                })
Exemplo n.º 3
0
'use strict';

import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import el from 'elasticlunr';

const POSTS = require('../../../_site/posts.json');

// Add the search command and handling function
var index = el(function() {
  this.addField('title', { boost: 10 });
  this.addField('content', { boost: 5 });
  this.addField('category');
});

POSTS.forEach(post => index.addDoc(Object.values(post)[0]));

class Posts extends Component {
  constructor(props) {
    super(props);

    this.state = {
      posts: []
    };

    const mainContainer = document.querySelector('.container--main');
    const openCtrl = document.getElementById('button-search');
    const closeCtrl = document.getElementById('button-search-close');
    const searchContainer = document.querySelector('.search');
  
    function openSearch() {
Exemplo n.º 4
0
Arquivo: jibu.js Projeto: mugendi/jibu
/**
 * Function to load index
 * @param  {string} channel channel name
 * @param  {object} jibu      inherited jibu object
 * @return {null}        returns null
 */
function loadIndex(channel,jibu){

  JIBU = jibu || this;

  //must have channel
  if(!channel){return null;}

  channel = channel.toLowerCase();

  if(( index = cache.get(channel) )){

    if(JIBU.options.log){ console.log('Returned Existing Index...');  }
    JIBU.index = index;
    JIBU.index_numerals = index.index_numerals;

  }
  else{

    var db_name = channel || 'jibu';

    var index = path.join( JIBU.options.db_path, db_name+'.json' );
    var numerals = path.join( JIBU.options.db_path, db_name+'-numerals.json' );

    var data = null;

    try{
      data =  require(index);
      data.numerals = require(numerals);
    }
    catch(e){}


    if(data){
      if(JIBU.options.log){ console.log('Loaded Existing Index...');  }
      //load index
      JIBU.index = elasticlunr.Index.load(data);
      JIBU.index_numerals = data.numerals;

    }
    else{
      if(JIBU.options.log){ console.log('Created New Index...'); }
      //create index
      JIBU.index = elasticlunr(function () {
          this.addField('search');
          this.addField('command');
          this.setRef('id');
      });
    }

    var loadedIndexes = {};

    loadedIndexes[channel] = JIBU.index;
    loadedIndexes[channel].index_numerals = JIBU.index_numerals;

    //set data
    cache.set(channel, loadedIndexes[channel]);

  }

  return null;
}
Exemplo n.º 5
0
import elasticlunr from "elasticlunr";

let index = elasticlunr();
index.addField('title');
index.addField('description');
index.setRef('id');
index.saveDocument(false);
elasticlunr.clearStopWords();

export default class Indexer {
    static indexDocuments(todoItems) {
        for (let todo of todoItems) {
            this.indexDocument(todo);
        }
    }

    static indexDocument(todo) {
        index.updateDoc({
            id: todo.key,
            title: todo.title,
            description: todo.description
        });
    }

    static search(searchText) {
        return index.search(searchText, {
            fields: {
                title: {
                    boost: 2
                },
                description: {
Exemplo n.º 6
0
'use strict';

const elasticlunr = require('elasticlunr');
const lunr = require('lunr');
const Benchmark = require('benchmark');
const factory = require('AutoFixture');
require('./fixtures/fixture')(factory);

let elasticlunrIndex = elasticlunr(function() {
  this.addField('id');
  this.addField('title');
  this.addField('body');
  this.setRef('_ref');
  this.saveDocument(false);
});

let elasticlunrIndexWithDocumentCopy = elasticlunr(function() {
  this.addField('id');
  this.addField('title');
  this.addField('body');
  this.setRef('_ref');
  this.saveDocument(true);
});

let lunrIndex = lunr(function() {
  this.field('id');
  this.field('title');
  this.field('body');
  this.ref('_ref');
});
Exemplo n.º 7
0
var elasticlunr = require('elasticlunr');
    fs = require('fs'),
    cloud = require('../leancloud');

var data = {};

var index = elasticlunr(function () {
    this.addField('title');
    this.addField('url');
    this.setRef('id');
});

cloud.getAllData(function(list){
    console.log("加载完所有数据");
    list.forEach(function(v,i){
        index.addDoc({
            "id" : v.objectId,
            "title" : v.name,
            "url" : v.url
        });


        data[v.objectId] = {
            "name" : v.name,
            "url" : v.url,
            "createdAt" : v.createdAt,
            "updatedAt" : v.updatedAt,
            "objectId" : v.objectId
        };
    });