question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

plurals and words ending in double-el

See original GitHub issue

When I search for a term that’s indexed by its plural, i.e. “carols”, I get no hits. Searching for “carol” or “carol*” works perfectly, but “carols”, “carols*” or “carols” comes up empty. Another example would be “Schwitters”. A search for “schwitter” gets a hit, but “schwitters” doesn’t.

I have a similar problem where searching for “powell” yields no results, but “powel” works as expected.

I did some basic testing and it seems to only apply to words ending in two els. If I change “powell” to “powerr” searches succeed.

This happens with v2.0.4 and also v2.1 Any idea what’s going on here?

This is how I build the index

            let index = lunr(function() {

                this.field("title", {boost: 10});
                this.field("section");
                this.field("content");
                this.field("worknumber");
                this.field("meta");
                this.field("description");
                this.field("firstname");
                this.field("lastname");
                this.field("tags");
                this.ref("ref");

                pages.forEach(page => {
                    this.add(page);
                })

            });

and the search (I fiddled with usePipeline but it seems to have no effect)

let results = index.query(function(q) {
                q.term(term, { 
                    fields: fields,
                    usePipeline: false,
                })
            });

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:1
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
olivernncommented, Jun 13, 2017

First off, that fiddle works for me on Safari 10.1.

So, it looks like you are trying to implement a typeahead style search. By manually appending the wildcard to the term, lets say “carols*”, you are searching for everything that begins with “carols” and then has some other characters after it. In addition you are not disabling the pipeline, so lunr is trying to trim and stem “carols*” with the wildcard, which probably isn’t doing anything.

I think the right way to approach this kind of search is to think of it in two parts:

  1. If there is an exact match for what I’ve typed, rank that highly.
  2. In addition, look for everything that begins with what I’ve typed and rank that lower.

So, in your case if you switch to the following:

  index.query(function(q) {
    q.term(term, { fields: fields, usePipeline: true, boost: 10 })
    q.term(term, { fields: fields, usePipeline: false, wildcard: lunr.Query.wildcard.TRAILING })
  });

You should get better results as well as getting results for “carols”, in your example. I’ve updated the fiddle with this change. Now, depending on what you want to do you can take it further by also doing a fuzzy search, this time with an even smaller boost:

  index.query(function(q) {
    q.term(term, { fields: fields, usePipeline: true, boost: 100 })
    q.term(term, { fields: fields, usePipeline: false, boost: 10, wildcard: lunr.Query.wildcard.TRAILING })
    q.term(term, { fields: fields, usePipeline: false, boost: 1, editDistance: 1 })
  });

You’ll have to experiment to see what works best for your application, but hopefully this is enough to get you on the right track.

0reactions
npearson72commented, Dec 18, 2020

@olivernn I know this is an old thread, but I’ve had similar confusions for getting matches on singular and plural terms. I’ve noticed the fiddle you updated only produces results when searching for single words. Ex: ‘carol’

But if I search any more, ex: ‘carol notes’ I get no matches.

Is there a way to use your settings but also to include matches for multiple terms?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Definitions and examples of double plurals in English
A double plural is the plural form of a noun with an additional plural ending (usually -s) attached; for example, candelabras (singular, ...
Read more >
Spelling Rules: Drop the 'f' and add 'ves' to make plurals
Spelling Rules: Plural Rule #4 If the noun ends with ‑f or ‑fe, the f is often changed to ‑ve before adding the...
Read more >
Spelling Rule Rap: Add 'ies' to make plurals with ... - YouTube
A song about making plurals of words that end in 'y'If a word ends consonant 'y' don't stressChange the 'y' to an 'i'...
Read more >
Developers - plurals and words ending in double-el - - Bountysource
When I search for a term that's indexed by its plural, i.e. "carols", I get no hits. Searching for "carol" or "carol" works...
Read more >
Spelling - Grammar - Cambridge Dictionary
When we add a suffix to a word with more than one syllable, we double the consonant only when the word ends in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found