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

Uncaught TypeError: Cannot read property 'tf' of undefined #16

Open
janthonyeconomist opened this issue Jul 12, 2017 · 1 comment
Open

Comments

@janthonyeconomist
Copy link

janthonyeconomist commented Jul 12, 2017

I'm not sure if this is a bug for you, or for Lunr, but seeing as it has to do with the index, and this is what I'm using to build the index, I thought I would start here.

So I'm getting the error Uncaught TypeError: Cannot read property 'tf' of undefined. It seems to have to do with parsing vector similarities. The code seems to be looking for tf on a document in the tokenStore.
https://cl.ly/1B3f1m0B391b

My lunr configs look like:

      metalsmithLunr({
        ref: 'id',
        indexPath: 'api/search-index.json',
        fields: {
          headline: 5,
          subheadline: 3,
          category: 5,
          tags: 3,
          contents: 1,
        },
        preprocess: function(content) {
          const tr = (str) => {
            const map = {"а":"a","б":"b",/*  truncated for issue  */"І":"I","і":"i"};
            let new_str = "", char, substitute, n = str.length;
            for(let i = 0; i < n; i++) {
                char = str[i];
                substitute = map[char];
                new_str += substitute ? substitute : char;
            }
            return new_str;
          };
          return tr(
            content.replace(/<[^>]+>/g, ' ') // Strip HTML
          ) // Transliterate foreign characters
            .replace(/[^\w]/g, ' ') // Strip Punctuation
          ;
        },
      }),

And the client side code looks like:

    let ip = new Promise((resolve, reject) => {
      $.getJSON('/api/search-index.json', data => {
        console.log('SEARCH DATA', data);
        resolve(lunr.Index.load(data));
      });
    });

and then later:

      if (keywords) {
        SearchService.results = SearchService.index.search(keywords);
      }

I can provide the index data or the serialized index object if you would like.

@janthonyeconomist
Copy link
Author

Do give you more information, I seem to only get the error when I have a field in the fields object that is optional. In the example above, I think the subheadline is present, but always has an empty value.

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

1 participant