Commit 87a03dc3 authored by Nacim Goura's avatar Nacim Goura

optimize form search

parent cf7ddef6
...@@ -7,7 +7,7 @@ const hooksFormApiCrawl = { ...@@ -7,7 +7,7 @@ const hooksFormApiCrawl = {
displayNotif({ displayNotif({
type: 'success', type: 'success',
title: 'Indexation : ', title: 'Indexation : ',
message: `Indexation fini avec succès avec ${result.index.items.length} urls indexées!`, message: `Indexation de ${result.api.idPage} pour l\'api ${result.api.type} fini avec succès avec ${result.index.items.length} urls indexées!`,
save: true, save: true,
}); });
}, },
......
...@@ -29,9 +29,6 @@ export default new SimpleSchema({ ...@@ -29,9 +29,6 @@ export default new SimpleSchema({
{ {
label: 'Twitter', value: 'twitter', label: 'Twitter', value: 'twitter',
}, },
{
label: 'Instagram', value: 'instagram',
},
]; ];
}, },
}, },
......
...@@ -34,6 +34,7 @@ export default class CrawlFacebook { ...@@ -34,6 +34,7 @@ export default class CrawlFacebook {
_.forEach(this.content.data, (item, index) => { _.forEach(this.content.data, (item, index) => {
const dataForIndex = { const dataForIndex = {
tag: 'social', tag: 'social',
apiName: 'facebook',
domain: this.config.idPage, domain: this.config.idPage,
url: `https://www.facebook.com/${item.id}`, url: `https://www.facebook.com/${item.id}`,
description: '', description: '',
......
...@@ -43,6 +43,7 @@ export default class CrawlTwitter { ...@@ -43,6 +43,7 @@ export default class CrawlTwitter {
_.forEach(tweets, (item, index) => { _.forEach(tweets, (item, index) => {
const dataForIndex = { const dataForIndex = {
tag: 'social', tag: 'social',
apiName: 'twitter',
domain: this.config.idPage, domain: this.config.idPage,
url: `https://twitter.com/${this.config.idPage}/status/${item.id_str}`, url: `https://twitter.com/${this.config.idPage}/status/${item.id_str}`,
}; };
......
import { check } from 'meteor/check'; import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import _ from 'lodash';
import formApiCrawlSchema from '/imports/api/crawl/api/formApiCrawlSchema'; import formApiCrawlSchema from '/imports/api/crawl/api/formApiCrawlSchema';
import IndexGeneric from '/imports/api/indexation/server/indexGeneric'; import IndexGeneric from '/imports/api/indexation/server/indexGeneric';
import IndexWebsite from '/imports/api/indexation/server/indexWebsite'; import IndexWebsite from '/imports/api/indexation/server/indexWebsite';
...@@ -31,28 +30,4 @@ Meteor.methods({ ...@@ -31,28 +30,4 @@ Meteor.methods({
const index = new IndexApi(); const index = new IndexApi();
return index.indexationApi(data); return index.indexationApi(data);
}, },
searchByTerm(term) {
check(term, String);
const index = new IndexGeneric();
return index.search(term)
.then(result => ({
total: result.hits.total,
list: _.map(result.hits.hits, '_source'),
}))
.catch((error) => {
console.log(error);
throw new Meteor.Error('recherche', 'Une erreur s\'est produite lors de la recherche', error);
});
},
autoCompletion(term) {
check(term, String);
const index = new IndexGeneric();
return index.autoComplete(term)
.then((result) => {
if (result.suggest) {
return _.take(_.map(result.suggest[0].options, 'text'), 5);
}
return [];
});
},
}); });
...@@ -89,6 +89,9 @@ exports.mapping = { ...@@ -89,6 +89,9 @@ exports.mapping = {
domain: { domain: {
type: 'keyword', type: 'keyword',
}, },
apiName: {
type: 'keyword',
},
title: { title: {
type: 'text', type: 'text',
analyzer: 'french_light', analyzer: 'french_light',
......
...@@ -4,6 +4,11 @@ import IndexGeneric from './indexGeneric'; ...@@ -4,6 +4,11 @@ import IndexGeneric from './indexGeneric';
export default class IndexApi extends IndexGeneric { export default class IndexApi extends IndexGeneric {
/**
* realize indexation
* @param data
* @returns Promise
*/
async indexationApi(data) { async indexationApi(data) {
return new CrawlApi(data) return new CrawlApi(data)
.then(dataToIndex => new Promise(async resolve => resolve({ .then(dataToIndex => new Promise(async resolve => resolve({
......
...@@ -3,7 +3,7 @@ import { AutoForm } from 'meteor/aldeed:autoform'; ...@@ -3,7 +3,7 @@ import { AutoForm } from 'meteor/aldeed:autoform';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import { FlowRouter } from 'meteor/kadira:flow-router'; import { FlowRouter } from 'meteor/kadira:flow-router';
import displayNotif from '../notif/notif.js'; import displayNotif from '/imports/api/notif/notif.js';
const hooksFormLogin = { const hooksFormLogin = {
onSubmit: (insertDoc, updateDoc, currentDoc) => { onSubmit: (insertDoc, updateDoc, currentDoc) => {
......
import { AutoForm } from 'meteor/aldeed:autoform';
import { Meteor } from 'meteor/meteor';
import { Session } from 'meteor/session';
const hooksFormSearch = {
onSuccess(formType, result) {
},
};
AutoForm.hooks({
formSearch: hooksFormSearch,
});
import SimpleSchema from 'simpl-schema';
SimpleSchema.extendOptions(['autoform']);
export default new SimpleSchema({
_id: {
type: String,
required: false,
},
term: {
type: String,
},
afterDate: {
type: Date,
},
}, { tracker: Tracker });
import { check } from 'meteor/check';
import { Meteor } from 'meteor/meteor';
import _ from 'lodash';
import IndexGeneric from '/imports/api/indexation/server/indexGeneric';
Meteor.methods({
searchByTerm(term) {
check(term, String);
const index = new IndexGeneric();
return index.search(term)
.then(result => ({
total: result.hits.total,
list: _.map(result.hits.hits, '_source'),
}))
.catch((error) => {
console.log(error);
throw new Meteor.Error('recherche', 'Une erreur s\'est produite lors de la recherche', error);
});
},
autoCompletion(term) {
check(term, String);
const index = new IndexGeneric();
return index.autoComplete(term)
.then((result) => {
if (result.suggest) {
return _.take(_.map(result.suggest[0].options, 'text'), 5);
}
return [];
});
},
});
// analyser
exports.analyser = {
settings: {
analysis: {
filter: {
// suppression de ces mots pour diminuer le bruit
french_elision: {
type: 'elision',
articles_case: true,
articles: [
'l',
'm',
't',
'qu',
'n',
's',
'j',
'd',
'c',
'jusqu',
'quoiqu',
'lorsqu',
'puisqu',
],
},
// synonyme
french_synonym: {
type: 'synonym',
ignore_case: true,
expand: true,
synonyms: [
'gosse, enfant',
'pmi, protection maternelle et infantile',
],
},
// radical des mots
french_stemmer: {
type: 'stemmer',
language: 'light_french',
},
},
analyzer: {
// français elevé
french_heavy: {
tokenizer: 'icu_tokenizer',
filter: [
'french_elision',
'icu_folding',
'french_synonym',
'french_stemmer',
'lowercase',
'asciifolding',
],
},
// français léger
french_light: {
tokenizer: 'icu_tokenizer',
char_filter: [
'html_strip',
],
filter: [
'french_elision',
'icu_folding',
'lowercase',
'asciifolding',
],
},
// analyzer for url
url_analyzer: {
tokenizer: 'uax_url_email',
filter: [
'french_elision',
'icu_folding',
'lowercase',
],
},
},
},
},
};
// mapping
exports.mapping = {
properties: {
tag: {
type: 'keyword',
},
domain: {
type: 'keyword',
},
apiName: {
type: 'keyword',
},
title: {
type: 'text',
analyzer: 'french_light',
fields: {
stemmed: {
type: 'text',
analyzer: 'french_heavy',
},
},
},
title_suggest: {
type: 'completion',
analyzer: 'french_light',
max_input_length: 100,
},
description: {
type: 'text',
analyzer: 'french_light',
fields: {
stemmed: {
type: 'text',
analyzer: 'french_heavy',
},
},
},
body: {
type: 'text',
analyzer: 'french_light',
fields: {
stemmed: {
type: 'text',
analyzer: 'french_heavy',
},
},
},
html: {
type: 'text',
analyzer: 'french_light',
},
url: {
type: 'text',
analyzer: 'url_analyzer',
},
urlText: {
type: 'text',
analyzer: 'french_light',
fields: {
stemmed: {
type: 'text',
analyzer: 'french_heavy',
},
},
},
h1: {
type: 'text',
analyzer: 'french_light',
},
h2: {
type: 'text',
analyzer: 'french_light',
},
breadcrumb: {
type: 'text',
analyzer: 'french_light',
},
listPdf: {
type: 'text',
analyzer: 'url_analyzer',
},
createdAt: {
type: 'date',
},
},
};
...@@ -2,21 +2,22 @@ ...@@ -2,21 +2,22 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { FlowRouter } from 'meteor/kadira:flow-router'; import { FlowRouter } from 'meteor/kadira:flow-router';
import { BlazeLayout } from 'meteor/kadira:blaze-layout'; import { BlazeLayout } from 'meteor/kadira:blaze-layout';
import displayNotif from '../../api/notif/notif'; import displayNotif from '/imports/api/notif/notif';
// Import layout templates // Import layout templates
import '../../ui/layouts/main/main'; import '/imports/ui/layouts/main/main';
import '../../ui/layouts/navbar/navbar'; import '/imports/ui/layouts/navbar/navbar';
import '../../ui/layouts/sidebar/sidebar'; import '/imports/ui/layouts/sidebar/sidebar';
// Import page templates // Import page templates
import '../../ui/pages/home/home'; import '/imports/ui/pages/home/home';
import '../../ui/pages/login/login'; import '/imports/ui/pages/demo/demo';
import '../../ui/pages/not-found/not-found'; import '/imports/ui/pages/login/login';
import '../../ui/pages/admin/indexation/indexation'; import '/imports/ui/pages/not-found/not-found';
import '../../ui/pages/admin/account/account'; import '/imports/ui/pages/admin/indexation/indexation';
import '../../ui/pages/admin/statistique/statistique'; import '/imports/ui/pages/admin/account/account';
import '../../ui/pages/admin/notif/notif'; import '/imports/ui/pages/admin/statistique/statistique';
import '/imports/ui/pages/admin/notif/notif';
// Set up all routes in the app // Set up all routes in the app
import './adminRoutes'; import './adminRoutes';
...@@ -32,6 +33,15 @@ FlowRouter.route('/', { ...@@ -32,6 +33,15 @@ FlowRouter.route('/', {
}, },
}); });
FlowRouter.route('/demo', {
name: 'home',
action() {
BlazeLayout.render('mainLayoutTpl', {
main: 'demoTpl',
});
},
});
FlowRouter.route('/login', { FlowRouter.route('/login', {
name: 'login', name: 'login',
action() { action() {
......
...@@ -5,6 +5,7 @@ import '/imports/api/account/methods'; ...@@ -5,6 +5,7 @@ import '/imports/api/account/methods';
import '/imports/api/config/methods'; import '/imports/api/config/methods';
import '/imports/api/notif/methods'; import '/imports/api/notif/methods';
import '/imports/api/testSearch/methods'; import '/imports/api/testSearch/methods';
import '/imports/api/search/methods';
import '/imports/tabular/tabularUser'; import '/imports/tabular/tabularUser';
import '/imports/tabular/tabularTestSearch'; import '/imports/tabular/tabularTestSearch';
import '/imports/tabular/tabularNotif'; import '/imports/tabular/tabularNotif';
<template name="resultSearchTpl">
<!-- Template resultSearchTpl -->
<br>
{{#if listResults}}
<div class="row">
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading text-center">
<h3 class="panel-title">Résultat de site</h3>
</div>
<div class="panel-body">
{{#each result in listResults.list}}
<li>
<a href="{{result.url}}" target="_blank">{{result.title}}</a>
</li>
{{/each}}
</div>
</div>
</div>
<div class="col-md-6">
<div class="panel panel-default">
<div class="panel-heading text-center">
<h3 class="panel-title">Résultat de réseaux sociaux</h3>
</div>
<div class="panel-body">
</div>
</div>
</div>
</div>
{{/if}}
</template>
...@@ -2,10 +2,10 @@ ...@@ -2,10 +2,10 @@
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import './result.html'; import './resultSearch.html';
Template.resultSearchTpl.onCreated(() => { Template.resultSearchTpl.onCreated(() => {
Session.set('results', []); // Session.set('results', []);
}); });
Template.resultSearchTpl.helpers({ Template.resultSearchTpl.helpers({
......
<template name="resultSearchTpl">
<!-- Template resultSearchTpl -->
<br>
{{#if listResults}}
<div class="row">
<h4>
<b>{{ listResults.total }}</b> Résultats pour cette recherche :
</h4>
<div class="result_search">
<ul>
{{#each result in listResults.list}}
<li>
<a href="{{result.url}}" target="_blank">{{result.title}}</a>
</li>
{{/each}}
</ul>
</div>
</div>
{{/if}}
</template>
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
</button> </button>
</span> </span>
</div> </div>
<!--
{{#if listAutoCompleteResults}} {{#if listAutoCompleteResults}}
<div class="autocomplete-dropdown"> <div class="autocomplete-dropdown">
{{#each result in listAutoCompleteResults}} {{#each result in listAutoCompleteResults}}
...@@ -22,6 +23,7 @@ ...@@ -22,6 +23,7 @@
{{/each}} {{/each}}
</div> </div>
{{/if}} {{/if}}
-->
</form> </form>
</div> </div>
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import displayNotif from '../../../api/notif/notif'; import displayNotif from '/imports/api/notif/notif';
import './result/result'; import '/imports/ui/components/resultSearch/resultSearch';
import './search.html'; import './search.html';
...@@ -31,11 +31,11 @@ Template.searchTpl.events({ ...@@ -31,11 +31,11 @@ Template.searchTpl.events({
}); });
}, },
'input #searchResult': (event) => { 'input #searchResult': (event) => {
event.preventDefault(); /* event.preventDefault();
const term = event.target.value; const term = event.target.value;
/* Meteor.callPromise('autoCompletion', term) Meteor.callPromise('autoCompletion', term)
.then((results) => { .then((results) => {
Session.set('autoCompleteResults', results); Session.set('autoCompleteResults', results);
});*/ });*/
......
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import tabsCollection from '../../../api/tabs/tabsCollection'; import tabsCollection from '/imports/api/tabs/tabsCollection';
import './tabs.html'; import './tabs.html';
......
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import '/imports/tabular/configClient';
import './testSearch.html'; import './testSearch.html';
import '../../../tabular/configClient';
Template.testSearchTpl.events({ Template.testSearchTpl.events({
'submit form': (event) => { 'submit form': (event) => {
event.preventDefault(); event.preventDefault();
......
...@@ -2,9 +2,9 @@ ...@@ -2,9 +2,9 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { Session } from 'meteor/session'; import { Session } from 'meteor/session';
import TabsCollection from '../../../../api/tabs/tabsCollection'; import TabsCollection from '/imports/api/tabs/tabsCollection';
import '../../../components/tabs/tabs'; import '/imports/ui/components/tabs/tabs';
import './list/list'; import './list/list';
import './add/add'; import './add/add';
......
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import displayNotif from '../../../../../api/notif/notif'; import displayNotif from '/imports/api/notif/notif';
import './add.html'; import './add.html';
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import displayNotif from '../../../../../api/notif/notif'; import displayNotif from '/imports/api/notif/notif';
import '../../../../../tabular/configClient'; import '/imports/tabular/configClient';
import './list.html'; import './list.html';
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { Template } from 'meteor/templating'; import { Template } from 'meteor/templating';
import { Meteor } from 'meteor/meteor'; import { Meteor } from 'meteor/meteor';
import swal from 'sweetalert2'; import swal from 'sweetalert2';
import displayNotif from '../../../../../api/notif/notif.js'; import displayNotif from '/imports/api/notif/notif.js';
import './main.html'; import './main.html';
......
<template name="demoTpl">
<br>
<div class="row">
{{> searchTpl ""}}
</div>