Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't Merge just for referencing, integrated levi without testing #116

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@


## IMPORTANT

We started collaborating with the [WebMemex project](https://github.com/WebMemex/memextension) and are in the mode of porting all the features of WorldBrain there. The WebMemex will power our software in the future and will lend its name to the WorldBrain tool as well. Therefore be not surprised, if you see no action in this repo.
Expand Down
1 change: 1 addition & 0 deletions WorldBrain-Memex-Extension-
Submodule WorldBrain-Memex-Extension- added at ba52a8
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
"npm-run-all": "^4.0.0"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^6.4.1",
"cpx": "^1.5.0",
"watchify": "^3.8.0"
},
Expand Down
74 changes: 71 additions & 3 deletions src/js/background.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

var MILLIS_BEFORE_CLEAR = 1000 * 60; // 60 seconds
var CLEAR_DELAY = 20000;
var MAX_URL_LEN_SHOWN = 50;
Expand All @@ -8,6 +9,12 @@ var LT_OBJ = function(a,b) {
}

var db
//import levi from 'levi' something like that
var levidb = levi.levi('db')
.use(levi.tokenizer())
.use(levi.stemmer())
.use(levi.stopword())


function ValidURL(text) {
var valid = /((https?):\/\/)?(([w|W]{3}\.)+)?[a-zA-Z0-9\-\.]{3,}\.[a-zA-Z]{2,}(\.[a-zA-Z]{2,})?/
Expand Down Expand Up @@ -46,7 +53,8 @@ function acceptInput(text, disposition) {
}

function init() {


//levi = new indexedDB('levi')
db = new PouchDB('main')
// db.plugin()
var remoteCouch = false;
Expand Down Expand Up @@ -89,15 +97,15 @@ function transferToPouch() {
keys[i] != "blacklist" &&
keys[i] != "preferences" &&
keys[i] != "shouldOpenTab")
count += store_url(results[keys[i]]);
count += store_url(results[keys[i]]);
}
);
console.log('Successfully stored ' + count.toString() + ' / ' + (keys.length - 4).toString() + ' items to PDB');
}

function handleMessage(data, sender, sendRespones) {
// data is from message
if (data.msg === 'pageContent' && shouldArchive(data)) {
if (data.msg === 'pageContent' && shouldArchive(data) ) {
delete data.msg;
data.text = processPageText(data.text);
//console.log("TEST"+ data.text)
Expand Down Expand Up @@ -154,15 +162,75 @@ function store_url(data) {
return 0;
}
});
levidb.put('indexing_key',item )
console.log('#############Build')
}

function search_pouch(query, text, cb, suggestCb) {
//levi search implementation
levidb.searchStream(query, {
fields: { 'title': 10, 'url': 5, 'text':1 } // title field boost. then url then text as mentioned by Oliver.
}).toArray(function (res) { console.log(res)
/*levi search returns the search results into an Array. We parse that array along with the conditions
applied in the below original search of Research Engine checking for date time compatiblities and
negative query length .
*/
var results = [];
for(var i = 0; i < res.length ; i++) {
var doc = res[i];
if (query.before != false) {
if (doc.doc.LastVisitTime <= query.before.getTime() && doc.doc.LastVisitTime >= query.after.getTime())
results.push(doc);
}
else if (doc.doc.LastVisitTime >= query.after.getTime())
results.push(doc);
}

// If Minuswords are entered in the query
var final_results = [];
if(query.negative.length > 0) {

//calculating the precision, if more than 1 minus word is entered: https://github.com/nolanlawson/pouchdb-quick-search#minimum-should-match-mm
var full_percent = 100
divisor = query.negative.length
var mm = 100 / divisor + "%"

// searching for two minus words
query.negative= query.negative.join(" ")
db.search({
query: query.negative,
fields: ['title','url','text'],
mm: mm,
include_docs: true,
build: false
}).then(function (res_negative) {
for(var i = 0 ; i < res.length ; i++) {
var flag = 0;
for(var j = 0 ; j < res_negative.rows.length ; j++) {
if(res[i].id === res_negative.rows[j].id)
flag = 1;
}
if(flag === 0)
final_results.push(res[i]);
}
return suggestionsComplete(final_results, query.shouldDate, suggestCb);
});
} else {
final_results = results;
}
if(final_results.length > 0)
return suggestionsComplete(final_results, query.shouldDate, suggestCb);
})




for(var i = 0 ; i < query.keywords.length ; i++)
if(query.keywords[i].length == 0)
query.keywords.splice(i, 1)
// Regular search through PouchDB


db.search({
query: query.text,
fields: ['title','url','text'],
Expand Down