mapreduce - Morphia/MongoDB: ordering search results from advanced queries -
i'm new morphia, mongodb, , document-oriented databases in general. i'm looking general guidance on how approach following problem.
we have db around 500k book
documents.
{ "isbn" : "0-691-01305-5", "title" : "for whom bell tolls", "titlefts" : [ "bell", "toll" ], "author" : "hemingway, ernest", "ratingscount" : 138, "rating" : "3.5", "sales" : 10245 "price" : "12.95", "category" : "fiction", "description" : "the story of young american in international brigades attached republican guerilla unit during spanish civil war.", "descriptionfts" : [ "story", "young", "americ", "internat", "brigade", "attach", "republic", "guerilla", "unit", "spanish", "civil", "war"] }
we need perform full-text searches on title , description fields. end, have created titlefts
, descriptionfts
arrays contains words title
, description
fields respectively, filtered of stop words, , stemmed.
when searching, users enter keywords, , return books match of entered terms, e.g.:
db.book.find({ titlefts : { $all: ['spanish', 'civil', 'war']}}) db.book.find({ descriptionfts : { $all: ['spanish', 'civil', 'war']}})
this works fine, but come tough part: we'd order results above queries based on multiple criteria. 1 such proposed ordering following:
- books matching search terms in both
titlefts
,descriptionfts
fields - books matching in
titlefts
field - books matching in
descriptionfts
field - books greatest # of
sales
- books highest
rating
- books highest
ratingscount
our app written in java , uses morphiadb api. can envision how write java comparator sort of thing pretty easily, i'd ordering @ db level.
which brings me question: can done using morphia api? or need delve writing javascript db.command()? require map/reduce? if so, hint how implement map/reduce problem lot.
i recommend external fulltext engine solr or elasticsearch. capabilities of mongodb related fulltext search truely not suitable real fulltext solution. approach pre-stemming etc. dirty workaround. long mongodb not provide suitable fulltext integration, go external solution if interested in serious , working solution.
Comments
Post a Comment