Closed Travis42 closed 4 years ago
Hi @Travis42 , if I understand correctly, you want to be able to search within sections of a single large document, but also between several of those documents. Is that correct?
If so, you could use the storeFields
option to store, for each section, the ID (or title) of the larger document that the section is part of. This way, the search results (each result being a section) will include the ID of the document they are part of.
Example:
const sections = [
{ id: 1, title: 'Section One, doc One', text: '...', documentId: 1, ... },
{ id: 2, title: 'Section Two, doc One', text: '...', documentId: 1, ... },
{ id: 3, title: 'Section One, doc Two', text: '...', documentId: 2, ... }
]
const miniSearch = new MiniSearch({
fields: ['title', 'text'],
storeFields: ['documentId']
})
miniSearch.search('two')
//=> [{ id: 2, documentId: 1, ... }, { id: 3, documentId: 2, ... }]
Closing this issue as I assume the question is answered, but feel free to comment on it if I misunderstood your question, and I will reopen it.
You did, thanks. Its taken me longer to get back to this part of the code than I anticipated. :)
In all of the examples I've encountered, minisearch does its thing against an object that contains different books, song titles, etc.
What I have been doing is using minisearch to find sections within a large document. That works. Format is: [ { id: 1, name: "Section Title", link_name: "an id tag to search in the HTML doc", description: "full text of that section to search against" }, ... ]
What I want to do next is search over multiple documents, ideally each composed of their own separate object. This would be a lot nicer than combining all my document objects into one giant object.
Is that possible? Thanks in advance.