Adam Tauno Williams
2011-12-24 02:32:28 UTC
I'm stumped how to build the following query in SQLalchemy:
SELECT title, ts_rank_cd(textsearch, query) AS rank
FROM apod, to_tsquery('neutrino|(dark & matter)') query
WHERE query @@ textsearch
ORDER BY rank DESC LIMIT 10;
I can do tsearch operations; but I can't figure out the syntax for this
non-join FROM clause.
If I setup using ...
class TextSearchVector(types.UserDefinedType):
def get_col_spec(self):
return 'tsvector'
class SearchVector(ORMEntity):
__tablename__ = 'vista_vectors'
object_id = Column('object_id', Integer, primary_key=True)
entity = Column('entity', String)
version = Column('version', Integer)
event_date = Column('version', UTCDateTime)
keywords = Column('keywords', ARRAY(String))
vector = Column('vector', TextSearchVector,
nullable=False)
... then I can query with the following -
tsq = func.to_tsquery('english', 'adam')
z = db.query(SearchVector.object_id).filter(SearchVector.vector.op('@@'
)(tsq)).all()
But -
z = db.query(SearchVector.object_id,
func.ts_rank_cd(SearchVector.vector, tsq)).\
filter(SearchVector.vector.op('@@' )(tsq)).all()
- doesn't produce a query with ranking [ the FROM clause only mentions
the table ].
And -
z = db.query(SearchVector.object_id,
func.ts_rank_cd(SearchVector.vector, tsq)).\
join(tsq),
filter(SearchVector.vector.op('@@' )(tsq)).all()
- fails (rather expectedly) with a no-relationship between a & b error.
How does one insert a function call into the FROM???
SELECT title, ts_rank_cd(textsearch, query) AS rank
FROM apod, to_tsquery('neutrino|(dark & matter)') query
WHERE query @@ textsearch
ORDER BY rank DESC LIMIT 10;
I can do tsearch operations; but I can't figure out the syntax for this
non-join FROM clause.
If I setup using ...
class TextSearchVector(types.UserDefinedType):
def get_col_spec(self):
return 'tsvector'
class SearchVector(ORMEntity):
__tablename__ = 'vista_vectors'
object_id = Column('object_id', Integer, primary_key=True)
entity = Column('entity', String)
version = Column('version', Integer)
event_date = Column('version', UTCDateTime)
keywords = Column('keywords', ARRAY(String))
vector = Column('vector', TextSearchVector,
nullable=False)
... then I can query with the following -
tsq = func.to_tsquery('english', 'adam')
z = db.query(SearchVector.object_id).filter(SearchVector.vector.op('@@'
)(tsq)).all()
But -
z = db.query(SearchVector.object_id,
func.ts_rank_cd(SearchVector.vector, tsq)).\
filter(SearchVector.vector.op('@@' )(tsq)).all()
- doesn't produce a query with ranking [ the FROM clause only mentions
the table ].
And -
z = db.query(SearchVector.object_id,
func.ts_rank_cd(SearchVector.vector, tsq)).\
join(tsq),
filter(SearchVector.vector.op('@@' )(tsq)).all()
- fails (rather expectedly) with a no-relationship between a & b error.
How does one insert a function call into the FROM???
--
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
You received this message because you are subscribed to the Google Groups "sqlalchemy" group.
To post to this group, send email to ***@googlegroups.com.
To unsubscribe from this group, send email to sqlalchemy+***@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.