Commit e54de3ad authored by Alexandre Delanoë's avatar Alexandre Delanoë

[SEARCH] Adding the authors for the demo site.

parent ec633d46
......@@ -63,16 +63,17 @@ instance ToSchema SearchQuery where
instance Arbitrary SearchQuery where
arbitrary = elements [SearchQuery ["query"] 1]
arbitrary = elements [SearchQuery ["electrodes"] 472764]
-----------------------------------------------------------------------
data SearchResult = SearchResult { sr_id :: Int
, sr_name :: Text
data SearchResult = SearchResult { sr_id :: Int
, sr_title :: Text
, sr_authors :: Text
} deriving (Generic)
$(deriveJSON (unPrefix "sr_") ''SearchResult)
instance Arbitrary SearchResult where
arbitrary = elements [SearchResult 1 "name"]
arbitrary = elements [SearchResult 1 "Title" "Authors"]
instance ToSchema SearchResult where
declareNamedSchema =
......@@ -101,7 +102,7 @@ type SearchAPI = Post '[JSON] SearchResults
search :: Connection -> SearchQuery -> Handler SearchResults
search c (SearchQuery q pId) =
liftIO $ SearchResults <$> map (\(i, y, t, s, _) -> SearchResult i (cs $ encode t))
liftIO $ SearchResults <$> map (\(i, y, t, s, a, _) -> SearchResult i (cs $ encode t) (cs $ encode a))
<$> textSearch c (toTSQuery q) pId 5 0 Desc
......@@ -69,6 +69,7 @@ textSearchQuery :: Query
textSearchQuery = "SELECT n.id, n.hyperdata->'publication_year' \
\ , n.hyperdata->'title' \
\ , n.hyperdata->'source' \
\ , n.hyperdata->'authors' \
\ , COALESCE(nn.score,null) \
\ FROM nodes n \
\ LEFT JOIN nodes_nodes nn ON nn.node2_id = n.id \
......@@ -82,7 +83,7 @@ textSearchQuery = "SELECT n.id, n.hyperdata->'publication_year' \
textSearch :: Connection
-> TSQuery -> ParentId
-> Limit -> Offset -> Order
-> IO [(Int,Value,Value,Value, Maybe Int)]
-> IO [(Int,Value,Value,Value, Value, Maybe Int)]
textSearch conn q p l o ord = query conn textSearchQuery (q,p,ord, o,l)
textSearchTest :: ParentId -> TSQuery -> IO ()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment