Question - is it possible to order index by word occurrences (hits)
See original GitHub issueI’m trying to do a simple blog search that sorts search results by keyword occurrences. The default FlexSearch behavior seems to try to retain the original order of the content as it was added to the Index… which makes sense for a book. Is this possible with flexsearch@0.6.x or flexsearch@0.7.x?
Here is a simple example, where each page just a ‘id’ and the ‘body’. When I search for a keyword, ‘cat’, I want the posts with the most occurrences of ‘cat’ first.
import FlexSearch from "flexsearch"
type IndexableDocument = Record<string, unknown>
const index = FlexSearch.create<IndexableDocument>({})
const document = [
{ id: `threecat`, body: `cat meows. cat stretch. cat sleep.` },
{ id: `onecat`, body: `cat is still asleep` },
{ id: `catcatdogdog`, body: `dog barks at cat. cat runs from dog.` },
{ id: `onedog`, body: `dog sleeps` },
{ id: `threedog`, body: `dog woofs. dog chases tail. dog sleeps` },
]
document.forEach(({ id, body }) => {
index.add(id as number, body)
})
index.search("cat") // goal: [ 'threecat', 'catcatdogdog', 'onecat' ]
index.search("dog") // goal: [ 'threedog', 'catcatdogdog', 'onedog' ]
// actual flexsearch@0.6.x output, respects order of original content
// cat: ["threecat","onecat","catcatdogdog"]
// dog: ["catcatdogdog","onedog","threedog"]
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Get search word Hits ( number of occurences) per document ...
Lucene uses a field-based, rather than document-based, index. In order to get term counts per document: Iterate over documents using IndexReader.document() ...
Read more >sql server - Counting occurrence of words in table is slow
UPDATE dbo.words WITH (TABLOCK) SET hits = ( SELECT COUNT_BIG(*) FROM dbo. ... I'm asking these questions because I can get a similar...
Read more >Return Multiple Match Values in Excel - Xelplus - Leila Gharani
The VLOOKUP and INDEX & MATCH formulas are great for looking up a value in a large data table and returning a result...
Read more >The Anatomy of a Large-Scale Hypertextual Web Search Engine
The hits record the word, position in document, an approximation of font size, and capitalization. The indexer distributes these hits into a set...
Read more >Probability of an Event: Simple Steps in Plain English
The question asks about the probability of a cat owner having fewer than three cats. In order words, you want to find how...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Good news, it is now supported by the option “boost”: https://github.com/nextapps-de/flexsearch#index-options
Example:
term ,Appear other words!!!!…