olivernn / lunr.js

A bit like Solr, but much smaller and not as bright
http://lunrjs.com
MIT License
8.87k stars 546 forks source link

Confused on index building #514

Open gbradburn opened 2 years ago

gbradburn commented 2 years ago

Greetings,

I'm trying to replace our search implementation using lunr (previously using fuse.js). Using this in angular I have an array of objects. To build the index I iterate through the array per the example: ` private initializeLunr(simplifiedFlatCourtList: ISimplifiedCourtList[]) { this.lunrIndex = lunr(function () { this.ref('pGuid') // this.field('abbreviation') // this.field('strippedAbbreviation') this.field('pathName') // this.field('courtKey')

        simplifiedFlatCourtList.forEach(function(court){
            this.add(court)
        }, this)
    })
}`

Here is an example of the data I'm trying to index: [ { "pGuid": "urn:krm:pvi-460B269BFD3B4457A1C1D9EC2F5F7E47", "name": "United States", "pathName": "United States", "abbreviation": "U.S. Fed", "strippedAbbreviation": "US Fed", "displayName": "United States (All)" }, { "pGuid": "urn:entity:jb-100000366", "courtKey": "US_MDL_MDL", "pathName": "United States / Jud. Panel Multidistrict Litigation", "abbreviation": "J.P.M.L", "strippedAbbreviation": "JPML", "displayName": "United States / Jud. Panel Multidistrict Litigation" }]

We want to index by four fields but when I couldn't get that working I commented out 3 of them and just used the pathName field. I have verified that pathName is populated for each of the entries in the array but when I search I get no results even when using a value that should be an exact match (e.g. 'United States'). Furthermore, when I examine the lunrIndex in the debugger it doesn't seem like it is including the pathName values anywhere.

I am also confused by the terminology. In the example it refers to "documents" but seems to use them in a context I would expect to be "records" or "rows". In other words, what they call a collection of "documents" seems to me to be a single document with several "rows" or "records".

Any idea what I'm doing wrong?