we have a database with names of wines and beer(s). We're using MongoDB and our document structure for each wine or beer company looks like this:
{
name: String //this is the company name
products: [
{
name: String //this is the product's name
...
}
],
...
}
I have created a text index on both the company name and product name, the text search is working fine but it's not working as expected. For example we'd like our app to be able to return results when someone searches for a product named Bellissima and the text they send is Belisima OR Bellisima or any variations of that word.
Is that even possible with MongoDB's text search? How can I make it smarter? I'm not a MongoDB expert but I know it has something to do with word stemming or something so is there a way I can modify that?? Or any other workaround to give the user most appropriate results? Because searching for Belisima doesn't return any results because that's not the exact word saved in database.
Related
So basically:
const screamDocument = db.doc(`/screams/${req.params.screamId}`)
This line of code works because req.params.screamId is document ID. I just want to know how to write this line but getting document path with FIELD VALUE and not document ID. For example I want a document that inside collection scream but exactly one document which has field value "age" equal to 120. I know how I wqould do that the long way, with querysnapshot and doc.data bla bla but how to write it short and in one line like above but with field value?
like something like this:
const postDocument2 = db.collection("posts").where("id", "==", id);
but this lacks .doc and doesnt return to me what i want how to add .doc to that line?
Ok so I solved it myself, the solution is this: document path ONLY works if you include document ID and not a field called id, so for example this like
const screamDocument = db.doc(`/screams/${req.params.screamId}`)
is a document path because screamId is document ID of one of documents inside collection screams. If I want to have this document path with some field value, I must store document ID in a sepparate variable and then add it like this:
const screamDocument = db.doc(`/screams/${documentId}`)
now how to get documentId i mean id of a document thats easy to find snapshot.foreach(doc)
and u can get doc.id its in documentation.
I'm writing a UI that presents the results of a MongoDB full text search query, visually highlighting the matched search terms in each result; this works well enough for full word or phrase matches, but not for partial/fuzzy matches.
For example, if I search for "delete" a will get a search result that contains "deletion", which does not contain the full word "delete" and therefore won't be highlighted if I merely highlight the full search term matches. I do want the partial matches, though.
Is there any way to project the set of matched words/substrings when I execute the query?
I've so far been unable to find anything in the docs that hints at this being possible, but I thought it worth asking around. Any help would be greatly appreciated.
You can use the Mongo DB Atlas feature where you can search your text based on different Analyzers that MongoDB provides. And you can then do a search like this: Without the fuzzy object, it would do a full-text-match search.
$search:{
{
index: 'analyzer_name_created_from_atlas_search',
text: {
query: 'Text to do a full match or fuzzy match with',
path: 'sentence',
fuzzy:{
maxEdits: 2 #max 2 is allowed
}
}
}
}
Does anyone have experience with Algolia & transliteration? For example indexes contain Cyrillic text but user is typing in latin letters.
Unfortunately, most search engines don't support transliteration natively; same for Algolia.
The best way to handle such a use-case is to enrich your objects with the transliterated attributes before sending them to the search engine.
Maybe you can try gausby/translitit-cyrillic-russian-to-latin?
Just to add one little clarification. Let's say we have one field like name and many name translations
you can form object like
{
name: 'whatever',
translations: {
ru: 'без разницы',
he: 'οτιδήποτε',
de: 'was auch immer'
}
}
Then you put in your searchable attributes name, translations.ru, translations.he, translations.de so search will return 'whatever' when user type in 'без ра' for example.
How to find partial search?
Now Im trying to find
db.content.find({$text: {$search: "Customer london"}})
It finds all records matching customer, and all records matching london.
If I am searching for a part of a word for example lond or custom
db.content.find({$text: {$search: "lond"}})
It returns an empty result. How can I modify the query to get the same result like when I am searching for london?
You can use regex to get around with it (https://docs.mongodb.com/manual/reference/operator/query/regex/). However, it will work for following :
if you have word Cooking, following queries may give you result
cooking(exact matching)
coo(part of the word)
cooked(The word containing the english root of the document word, where cook is the root word from which cooking or cooked are derived)
If you would like to go one step further and get a result document containing cooking when you type vooking (missplled V instead of C), go for elasticsearch.
Elasticsearch is easy to setup, has extremely powerful edge-ngram analyzer which converts each words into smaller weightage words. Hence when you misspell, you will still get a document based on score elasticsearch gives to that document.
You can read about it here : https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-edgengram-tokenizer.html
it will always return the empty array for partial words like when you are searching for lond to get this type of text london..
Because it take full words and search same as that they are ..
Not achive same results like :-
LO LON LOND LONDO LONDON
Here you may get help from ELASTIC-SEARCH . It is quite good for full text search when implement with mongoDB.
Refrence : ElasticSearch
Thanks
The find all is to an Array
clientDB.collection('details').find({}).toArray().then((docs) =>
I now used the str.StartWith in a for loop to pick out my record.
if (docs[i].name.startsWith('U', 0)) {
return console.log(docs[i].name);
} else {
console.log('Record not found!!!')
};
This may not be efficient, but it works for now
I am am in need of a solution quickly for the following:
Assuming that I have n numbere of documents in collection XYZ similar to below:
XYZ{
NAME: Test
AGE: 33
ADDRESS: ASDF
EDUCATION: BSC
}
If I want to search for a string say: "BSC"
I want the api to search for the string "BSC", and after successful search, it has to return me only the column name( or field name) of the document XYZ: "EDUCATION"
Any quick help for the solution of the above problem would be very helpful.
Thanks.
MongoDB does not allow you full text search, Sorry, I am not able to comment this one, Don't have appropriate points.