Comments (8)
Hi @jimbung ,
MiniSearch by default does not support searching in the middle of a word. It only supports searching at the beginning of the word, using prefix
search, and/or for slightly misspelled words using fuzzy
search.
That said, it is possible to implement search in the middle of the world, at the cost of a larger index, by following the instructions in this other discussion (and in particular in this comment).
from minisearch.
Hi @lucaong , thank u very much for quick response on the issue.
i tried as the following as the processTerm you mentioned above, but unfortunately some text cannot be searched out (before using processTerm function, they can be searched out).
below is the code, please have a look if i am wrong with somewhere.
const suffixes = (term, minLength) => {
if (term == null) { return []; }
const tokens = [];
for (let i = 0; i <= term.length - minLength; i++) {
tokens.push(term.slice(i));
}
return tokens;
}
const idfield = "order_id";
const miniSearch = new MiniSearch({
idField: idfield,
fields: ["suscep", "action.comment", "action.game.comment"],
extractField: (document, fieldName) => {
const arrFields = fieldName.split(".");
if (arrFields.length === 2) {
return (document[arrFields[0]] || [])
.map((arrField: any) => arrField[arrFields[1]] || "")
.join(" ");
} else if (arrFields.length === 3) {
const tmparr = (document[arrFields[0]] || []).flatMap(
(arrField: any) => arrField[arrFields[1]] || []
);
return tmparr.map((s: any) => s[arrFields[2]] || "").join(" ");
}
// Access fields in simple path (such as a.b.c)
return fieldName
.split(".")
.reduce((doc, key) => doc && doc[key], document);
},
processTerm: (term) => suffixes(term, 3),
searchOptions: {
processTerm: MiniSearch.getDefault('processTerm'),
prefix: true,
},
});
Thanks!
from minisearch.
Hi @jimbung ,
I did a quick test, only including the processTerm
logic and excluding the extractTerm
part, and it seems to work correctly:
const suffixes = (term, minLength) => {
if (term == null) { return []; }
const tokens = [];
for (let i = 0; i <= term.length - minLength; i++) {
tokens.push(term.slice(i));
}
return tokens;
}
const miniSearch = new MiniSearch({
fields: ["text"],
processTerm: (term) => suffixes(term, 3),
searchOptions: {
processTerm: MiniSearch.getDefault('processTerm'),
prefix: true,
},
});
const docs = [{id: 1, text: "something"}, {id: 2, text: 'something else'}]
miniSearch.addAll(docs)
miniSearch.search('thi')
/* >
[
{
id: 1,
score: 0.10047016592300792,
terms: [ 'thing' ],
match: { thing: [Array] }
},
{
id: 2,
score: 0.084675550210326,
terms: [ 'thing' ],
match: { thing: [Array] }
}
]
*/
Later today or tomorrow I will probably be able to test your code more in details. In the meanwhile, a few suggestions:
- make sure you use the latest
MiniSearch
version if you do not already use it. - try to find if the problem is with the
extractField
part or theprocessTerm
part - if possible, provide an example with data to reproduce the issue (ideally, a complete example where some result that you expect to be found is not found). This will help to spot the issue.
Good luck!
from minisearch.
Hi @lucaong ,
Thanks for quick reply.
I am using "minisearch": "^6.2.0" currently. is it the latest?
I'll check your suggestions later.
Thank you very much!
from minisearch.
Yes, its the latest 👍
from minisearch.
@jimbung did you manage to resolve your problem? If not, you can post more details here, ideally some code to reproduce the problem, and I will try to help you.
from minisearch.
hi @lucaong , thanks a lot for reminding me. Sorry i didnot post timely. The problem has been solved according to your suggestion. Thank u again for all the great helps :-)
from minisearch.
Thank you @jimbung , happy to know your issue is solved! I will then mark the issue as closed.
from minisearch.
Related Issues (20)
- Barebones, framework agnostic example HOT 8
- Is it possible to make autoSuggest suggest the entire title of my blogs instead of just one word? HOT 2
- case-sensitive dynamic selection during search HOT 2
- `fuzzy` predicate function? HOT 2
- how to index nested field with its value is an array HOT 6
- Minimum should match HOT 4
- Any way to search across multiple vitepress sites? HOT 4
- How to have a search at least as good as `includes` HOT 3
- How to prevent treating terms separately? HOT 2
- Can `loadJSON` be added as an instance method which merges indices? HOT 3
- Any notification on status of data loading? HOT 1
- Search terms are broken when immediately following unicode whitespace HOT 9
- Get Mini Search version? HOT 2
- Re-index to new documents with unknown changes HOT 4
- Generating (caching) an index during build-time rather than runtime HOT 2
- Typescript with module resolution "NodeNext" + type: "commonjs" fails to import the commonJS module HOT 13
- When there are a lot of markup documents (about 2000). The minisearch search search box is very sluggish, what is the solution? HOT 4
- bm25 and cross-language searching HOT 3
- [Suggestion] Async version of .LoadJSON()? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from minisearch.