r.sendecky
r.sendecky

Reputation: 10383

Haskell mongodb text search

What is the status of text search with haskell mongodb driver?

There is now 'LIKE' operator in mongo similar to SQL variants, so what is the best way to search a collection or the whole db for a particular text string?

I've read some people referencing external tools but I can also see that some text search was implemented in 2.4 mongo version which is done through command interface.

There should not be any problems doing it from console but how would I do it from haskell driver? I found 'runCommand' function in the driver APIs and it looks like it should be possible to send 'text' command to the server but the signature shows that it returns only one document - not a list of documents. So how is it done correctly?

How would I efficiently search for a word or a sentence in a collection or db so that it returns a list of documents containing the word? Is it possible to do without external tools using mongo 'text search' feature? SHould it be done in the application level?

Thanks.

Upvotes: 4

Views: 246

Answers (1)

ichistmeinname
ichistmeinname

Reputation: 1500

The result type already contains the list of documents (that contain the searched text). Unfortunately, I could not test the query on my running database, but I have used runCommand to run an aggregation (before it was implemented for the haskell driver). The result document you get for such an query looks something like this:

{ results: [ 
            { score : ...,
              obj   : { ... }
            }, 
            ... 
           ],
  ... ,
  ok : 1
}

The result document has a field results and its value is a document with fields score and obj. So in the end, you can find each of the matched document behind the obj-field in the list of results. For more details, you should take a look here.

Upvotes: 5

Related Questions