<commit_before>// Tests for configured indexer (ElasticQuery)
/*jslint node: true */
/* global describe,it */
'use strict';

var expect = require("expect.js");
var indexer = require('../../lib/indexer.js'), annotations = require('../../lib/annotations.js'), testApp = require('../lib/test-app.js'), utils = require('../../lib/utils.js');
GLOBAL.config = require('../lib/test-config.js').config;

var uniq = utils.getUnique(), uniqMember = 'member'+uniq, uniqURI = 'http://test.com/' + uniq, uniqCategory = 'category' + uniq;

describe('Indexer', function(done) {
  it('should reset test app', function(done) {
    testApp.start(function(err, ok) {
      expect(err).to.be(undefined);
      done();
    });
  });

  it('should index a page', function(done) {
    var cItem = annotations.createContentItem({title: 'test title', uri: uniqURI, content: 'test content ' + uniq});
    cItem.visitors = { member: uniqMember};
    indexer._saveContentItem(cItem, function(err, res) {
      expect(err).to.be(undefined);
      done();
    });
  });

  it('should retrieve by URI', function(done) {
    indexer.retrieveByURI(uniqURI, function(err, r) {
      expect(err).to.be(undefined);
      expect(r.exists).to.be(true);
      done();
    });
  });

  it('should index an annotation', function(done) {
    var annoCategory = annotations.createAnnotation({hasTarget: uniqURI, annotatedBy: uniqMember, type: 'category', category: uniqCategory});
    indexer.saveAnnotations(uniqURI, annoCategory, function(err, res) {
      expect(err).to.be(undefined);
      done();
    });
  });

  it('should retrieve annotations', function(done) {
    indexer.retrieveAnnotations(uniqURI, function(err, res) {
      expect(err).to.be(undefined);
      expect(res.length).to.be(1);
      done();
    });
  });

  it('should wait a second for indexing', function(done) {
    setTimeout(function() {
      done();
    }, 1000);
  });

  it('should form search', function(done) {
// delay for ElasticSearch refresh delay
    indexer.formQuery({}, function(err, res) {
      expect(err).to.be(undefined);
      expect(res.hits.total).to.be(1);
      done();
    });
  });

  it('should form search by member', function(done) {
    var found = { member: uniqMember, annotationState: utils.states.content.visited };

    indexer.formQuery(found, function(err, res) {
      expect(err).to.be(undefined);
      expect(res.hits.total).to.be(1);
      done();
    });
  });

  it('should return no results for form search by non-member', function(done) {
    var notFound = { member: uniqMember + 'nonense', annotationState: utils.states.content.visited };
    indexer.formQuery(notFound, function(err, res) {
      expect(err).to.be(undefined);
      expect(res.hits.total).to.be(0);
      done();
    });
  });

  it('should form search by terms', function(done) {
    var found = { terms: uniq };

    indexer.formQuery(found, function(err, res) {
      expect(err).to.be(undefined);
      expect(res.hits.total).to.be(1);
      done();
    });
  });

/*
  it('should return no results for non-terms', function(done) {
    var notFound = { terms: uniq + 'nonsense' }
    indexer.formQuery(notFound, function(err, res) {
      expect(err).to.be.null;
      expect(res.hits.total).to.be(0);
      done();
    });
  });
  it('should form search by date range', function(done) {
    var e = { from: '2013-10-04T19:51:15.963Z', to: '2013-10-07T19:51:15.963Z' }

    indexer.formQuery(e, function(err, res) {
      expect(err).to.be.null;<commit_msg>fixing test<commit_after>// Tests for configured indexer (ElasticQuery)
/*jslint node: true */
/* global describe,it */
'use strict';

var expect = require("expect.js");
var indexer = require('../../lib/indexer.js'), annotations = require('../../lib/annotations.js'), testApp = require('../lib/test-app.js'), utils = require('../../lib/utils.js');
GLOBAL.config = require('../lib/test-config.js').config;

var uniq = utils.getUnique(), uniqMember = 'member'+uniq, uniqURI = 'http://test.com/' + uniq, uniqCategory = 'category' + uniq;

describe('Indexer', function(done) {
  it('should reset test app', function(done) {
    testApp.start(function(err, ok) {
      expect(err).to.be(undefined);
      done();
    });
  });

  it('should index a page', function(done) {
    var cItem = annotations.createContentItem({title: 'test title', uri: uniqURI, content: 'test content ' + uniq});
    cItem.visitors = { member: uniqMember};
    indexer._saveContentItem(cItem, function(err, res) {
      expect(err).to.be(null);
      done();
    });
  });

  it('should wait a second for indexing', function(done) {
    setTimeout(function() {
      done();
    }, 1000);
  });

  it('should retrieve by URI', function(done) {
    indexer.retrieveByURI(uniqURI, function(err, r) {
      expect(err).to.be(null);
      expect(r).to.not.be(undefined);
      done();
    });
  });

  it('should index an annotation', function(done) {
    var annoCategory = annotations.createAnnotation({hasTarget: uniqURI, annotatedBy: uniqMember, type: 'category', category: uniqCategory});
    indexer.saveAnnotations(uniqURI, annoCategory, function(err, res) {
      expect(err).to.be(null);
      done();
    });
  });

  it('should retrieve annotations', function(done) {
    indexer.retrieveAnnotations(uniqURI, function(err, res) {
      expect(err).to.be(null);
      expect(res.length).to.be(1);
      done();
    });
  });

  it('should wait a second for indexing', function(done) {
    setTimeout(function() {
      done();
    }, 1000);
  });

  it('should form search', function(done) {
// delay for ElasticSearch refresh delay
    indexer.formQuery({}, function(err, res) {
      expect(err).to.be(null);
      expect(res.hits.total).to.be(1);
      done();
    });
  });

  it('should form search by member', function(done) {
    var found = { member: uniqMember, annotationState: utils.states.content.visited };

    indexer.formQuery(found, function(err, res) {
      expect(err).to.be(null);
      expect(res.hits.total).to.be(1);
      done();
    });
  });

  it('should return no results for form search by non-member', function(done) {
    var notFound = { member: uniqMember + 'nonense', annotationState: utils.states.content.visited };
    indexer.formQuery(notFound, function(err, res) {
      expect(err).to.be(null);
      expect(res.hits.total).to.be(0);
      done();
    });
  });

  it('should form search by terms', function(done) {
    var found = { terms: uniq };

    indexer.formQuery(found, function(err, res) {
      expect(err).to.be(null);
      expect(res.hits.total).to.be(1);
      done();
    });
  });

/*
  it('should return no results for non-terms', function(done) {
    var notFound = { terms: uniq + 'nonsense' }
    indexer.formQuery(notFound, function(err, res) {
      expect(err).to.be.null;
      expect(res.hits.total).to.be(0);
      done();
    });
  });
  it('should form search by date range', function(done) {
    var e = { from: '2013-10-04T19:51:15.963Z', to: '2013-10-07T19:51:15.963Z' }

    indexer.formQuery(e, function(err, res) {
      expect(err).to.be.null;
{'fraction_non_alphanumeric': 0.18006747258926062, 'fraction_numerical': 0.012932246274950801, 'mean_word_length': 3.3042952208106473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '310170', 'n_tokens_mistral': 2442, 'n_tokens_neox': 2349, 'n_words': 474}