1

Am using lunr (elastic lunr0.9.5) as search engine in web browser. It is simple and very fast as well. but it is not listing exactly matched object in first position when it have more.

My lunr Configuration in Typescript

this.lunrIndex = lunr(function () {
                this.field('itemId');
                this.field('name');
                this.ref('itemId');
                this.pipeline.remove(lunr.stemmer)
            })

When i search pan d ca text it is returning,

[{
    "ref": "PANCOR DSR CAPSULE 10''S",
    "score": 0.01674628244112235
  },
  {
    "ref": "PANLID DSR CAPSULE 10''S",
    "score": 0.01674628244112235
  },
  {
    "ref": "PANSIO DSR CAPSULE 10''S",
    "score": 0.01590146213665648
  },
  {
    "ref": "PANLIFE DSR CAPSULE 10''S",
    "score": 0.015507241586286287
  },
  {
    "ref": "PANSEC DSR CAPSULE 10''S",
    "score": 0.014526355502926632
  },
  {
    "ref": "PAN D CAPSULE 10''S",
    "score": 0.011554433713104873
  }
  ]

Lunr trimming may be one of reason for above result, so i removed lunr.trimmer from its pipeline execution and still it giving the same result.

The above result shows, exact matching string(PAN D C) gets lower score(0.011554433713104873). am i missed any configuration here ?

I need the exact matching string should get highest score than others, How can i achieve that ?

Nat4j
  • 453
  • 2
  • 7
  • 19

1 Answers1

0

Lunr (versions 0.x and 1.x) automatically append a wildcard to each search term, so when you search for "pan d ca" you are actually getting results for "pan* d* ca*" which is why you are getting extra results. There is some logic that attempts to boost exact matches, but, especially with multi word searches it doesn't always boost the matches enough to get the expected results. This is not configurable.

If you can, I would suggest upgrading to Lunr 2.x which offers much greater control over searching.

Oliver Nightingale
  • 1,805
  • 1
  • 17
  • 22
  • Good Suggestion, But, The largest difference between 0.x/1.x and 2.x is that Lunr indexes are now immutable. Once they have been built, it is not possible to add, update or remove any documents in the index. In my application i need to add/update documents in index in middle. Re-building the whole index instead add/updating few documents is very costly. that is the reason am stabled in 0.x – Nat4j Sep 21 '17 at 07:16