P
P
Partizanin2019-01-07 01:18:11
Java
Partizanin, 2019-01-07 01:18:11

How to do text search with spring mongodb sort?

Hello, tell me, can anyone work with Spring data mongoDB
how to do this with the mongo driver?

db.stores.find(
   { $text: { $search: "java coffee shop" } },
   { score: { $meta: "textScore" } }
).sort( { score: { $meta: "textScore" } } )

There is something similar, but it's not quite the same, it's a simple match and not a search
override fun getSearchedFiles(searchQuery: String, pageNumber: Long, pageSize: Long, direction: Sort.Direction, sortColumn: String): MutableList<SystemFile> {

        val matching = TextCriteria.forDefaultLanguage().matching(searchQuery)


        val match = MatchOperation(matching)
        val sort = SortOperation(Sort(direction, sortColumn))
        val skip = SkipOperation((pageNumber * pageSize))
        val limit = LimitOperation(pageSize)

        val aggregation = Aggregation
                .newAggregation(match, skip, limit)
                .withOptions(Aggregation.newAggregationOptions().allowDiskUse(true).build())

        val mappedResults = template.aggregate(aggregation, "files", SystemFile::class.java).mappedResults


        return mappedResults
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
Orkhan, 2019-05-29
Hasanly @azerphoenix

Why don't you use Hibernate Search or ElasticSearch? If I understood the task correctly...
There is sorting and filtering and much more...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question