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

Getting an error of TypeError: Cannot call method 'getDocFreq' of undefined #2

Closed
Darkle opened this issue Sep 28, 2015 · 1 comment

Comments

@Darkle
Copy link
Contributor

Darkle commented Sep 28, 2015

Hi, I'm getting an odd error when I try to run the example from the elasticlunr documentation in node.js.
Running the following code in node:

var http = require('http');

var elasticlunr = require("elasticlunr");

var server = http.createServer();

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

var doc1 = {
    "id": 1,
    "title": "Oracle released its latest database Oracle 12g",
    "body": "Yestaday Oracle has released its new database Oracle 12g, this would make more money for this company and lead to a nice profit report of annual year."
}

var doc2 = {
    "id": 2,
    "title": "Oracle released its profit report of 2015",
    "body": "As expected, Oracle released its profit report of 2015, during the good sales of database and hardware, Oracle's profit of 2015 reached 12.5 Billion."
}

index.addDoc(doc1);
index.addDoc(doc2);

index.search("Oracle database profit", {
  fields: {
      title: {boost: 2},
      body: {boost: 1}
  }
});

server.listen(process.env.PORT || 3000, process.env.IP || "0.0.0.0", function(){
  var addr = server.address();
  console.log("Chat server listening at", addr.address + ":" + addr.port);
});

I get the following error message:

/home/ubuntu/workspace/node_modules/elasticlunr/elasticlunr.js:731                                                                         
  var df = this.index[field].getDocFreq(term);                                                                                             
                             ^                                                                                                             
TypeError: Cannot call method 'getDocFreq' of undefined                                                                                    
    at elasticlunr.Index.idf (/home/ubuntu/workspace/node_modules/elasticlunr/elasticlunr.js:731:30)                                       
    at elasticlunr.Index.computeSquaredWeight (/home/ubuntu/workspace/node_modules/elasticlunr/elasticlunr.js:898:22)                      
    at Array.forEach (native)                                                                                                              
    at elasticlunr.Index.computeSquaredWeight (/home/ubuntu/workspace/node_modules/elasticlunr/elasticlunr.js:894:15)                      
    at elasticlunr.Index.search (/home/ubuntu/workspace/node_modules/elasticlunr/elasticlunr.js:779:28)                                    
    at Object.<anonymous> (/home/ubuntu/workspace/server.js:29:7)                                                                          
    at Module._compile (module.js:456:26)                                                                                                  
    at Object.Module._extensions..js (module.js:474:10)                                                                                    
    at Module.load (module.js:356:32)                                                                                                      
    at Function.Module._load (module.js:312:12) 

Any help would be appreciated.

@weixsong
Copy link
Owner

Hi, @Darkle , thanks very for reporting this issue. I've fixed this issue by v0.7.2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants