Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

238
Visualizações
How to perform "like" query with full text search in mongodb?

I know that mongo does not support $regex or like operation with full text search at the moment.It only matches the text or the phrase.But I need to perform like query search on indexed fields.So, I need help regarding the choice of multiple search frameworks or any other work around to solve this issue.

I have nested document structure. For eg:

{
"name": "John",
"phones": [{
    "phone_number": "1234",
    "is_primary": true
}, {
    "phone_number": "5678",
    "is_primary": false
}]
}

I have tried using Apache Solr but I found that it does not provide good support for nested documents. It flattens the structure and indexes the fields but when I tried to perform like query as I have discussed above, it did not work.

I am using scala, play and mongodb.It is not feasilbe for me to change the nested document structure now. What are the suitable search platforms that I could integrate with mongodb to develop a powerful search framework ? How can I go about handling this issue ? What would be the best approach in this scenario ?

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

To perform like full text search you can create text index and use then. more about text index

Syntax to create text index

db.colectionName.createIndex( { fieldName: "text" } );

Here shown for single field you can also create with multiple fields. but remember that

A collection can have at most one text index.

then you can search using $text and $search

var searchText= 'some text to search';
db.collectionName.find({ $text: { $search: searchText} });

But to sequence matching or pattern matching no need to create text index can use $regex.

var searchName ='som';
db.collectionName.find({"name":{ $regex: searchName, $options: 'i' }})

for above query with $regex that will match partially . for example in your db name:'some text to search' so can return data if searchName value like some,som,ome, rex ...

for better performance can create normal index for name field

over 4 years ago · Santiago Trujillo Relatório

0

You could do this in SOLR but you need to define in advance the kinds of queries you will want to do and flatten the index in a creative ways so you can query and retrieve what you need. You can use multi-valued fields to store more than one value. You can store a JSON version of the entire object in a text field if your client needs to instantiate it.

For example you could store primaries and secondaries separately:

phone_number_primary: 1234,...
phone_number_secondary: 5678,...
my_json_blob: {OBJECT HERE}

then you can retrieve and query each separately. If you want to search for both you can either query both

 ( phone_number_primary:1234 OR phone_number_secondary:1234) 

or you can define an extra field that stores both numbers in your schema:

 <copyField source="phone_number_*" dest="phone_number_all" />

and then search this field.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda