@@ -1607,7 +1607,17 @@ routes:
16071607
16081608 get " /search.json" :
16091609 cond " q" in request.params
1610- let q = @ " q"
1610+ var query = @ " q"
1611+
1612+ var depth = 0
1613+ for ch in query:
1614+ if ch == '(' : depth.inc
1615+ elif ch == ')' : depth.dec
1616+ if depth == 0 : discard
1617+ elif depth > 0 : query.add ')' .repeat (depth)
1618+ elif depth < 0 : query = '(' .repeat (abs (depth)) & query
1619+
1620+ let q = query
16111621 cond q.len > 0
16121622
16131623 var results: seq [SearchResult ] = @ []
@@ -1618,20 +1628,23 @@ routes:
16181628 q, q, $ count, $ 0 , q,
16191629 q, $ count, $ 0 , q
16201630 ]
1621- for rowFT in fastRows (db, queryFT, data):
1622- var content = rowFT[3 ]
1623- try : content = content.rstToHtml () except EParseError : discard
1624- results.add (
1625- SearchResult (
1626- kind: SearchResultKind (rowFT[^ 1 ].parseInt ()),
1627- threadId: rowFT[0 ].parseInt (),
1628- threadTitle: rowFT[1 ],
1629- postId: rowFT[2 ].parseInt (),
1630- postContent: content,
1631- creation: rowFT[4 ].parseInt (),
1632- author: selectUser (rowFT[5 .. 11 ]),
1631+ try :
1632+ for rowFT in fastRows (db, queryFT, data):
1633+ var content = rowFT[3 ]
1634+ try : content = content.rstToHtml () except EParseError : discard
1635+ results.add (
1636+ SearchResult (
1637+ kind: SearchResultKind (rowFT[^ 1 ].parseInt ()),
1638+ threadId: rowFT[0 ].parseInt (),
1639+ threadTitle: rowFT[1 ],
1640+ postId: rowFT[2 ].parseInt (),
1641+ postContent: content,
1642+ creation: rowFT[4 ].parseInt (),
1643+ author: selectUser (rowFT[5 .. 11 ]),
1644+ )
16331645 )
1634- )
1646+ except DbError :
1647+ discard
16351648
16361649 resp Http200 , $ (% results), " application/json"
16371650
0 commit comments