>
> search_count_query = select([func.count(reviews.c.id)],
> "MATCH%s AGAINST (:q)" % search_fields)
> search_query = select([reviews,
>
> (func.sum(review_ratings.c.rating)/func.count(review_ratings.c.id).label("avg")),
> "MATCH%s AGAINST (:q) AS score" %
> search_fields ],
> "MATCH%s AGAINST (:q)" % search_fields,
> from_obj=[reviews.outerjoin(review_ratings,
>
> reviews.c.id==review_ratings.c.review_id)],
> order_by=[desc("avg"), desc("score")],
> group_by=[reviews.c.id])
>
> search_hits = search_count_query.scalar(q=q)
> results = search_query.execute(q=q)
>
> return session.query(Review).instances(results), search_hits
>
> As you can see, the queries can be as complex as you like, but I've
> retrieved every column from the review table. You may need to play
> around with what data is required to be retrieved to be able to use
> .instances().
>
> Hope this helps.
>
> Lee
Hi,
I've been using your resolution, and I've got a question. My code is:
q = "some text"
search_fields = "(keywords.description)"
search_query = select([company_t,"MATCH %s AGAINST (:q) AS score" %
search_fields ],
and_("MATCH %s AGAINST (:q)" %
search_fields,company_t.c.id == keywords_t.c.some_id,
keywords_t.c.dict_id == 1))
results = search_query.execute(q=q)
res = c.DBsession.query(Company_m).instances(results)
And, I'd like to have an access to a score column in my results
and.... how can I get it.
When I tried:
results.fetchall()
then I have a tuples, but then empty cursor is given to an instances
method :(
The best solution would be if in Company_m mapper a dynamic column was
created for score result, but how can i achieve it.
Best regards,
Loucash
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---