Reads a single JSON request from the TCP connection, performs the search and sends results back over the TCP connection as they appear.
(in *sourcebackendpb.SearchRequest, stream sourcebackendpb.SourceBackend_SearchServer)
| 291 | flags := syntax.Perl |
| 292 | if in.GetLiteral() { |
| 293 | flags |= syntax.Literal |
| 294 | } |
| 295 | re, err := syntax.Parse(in.Query, flags) |
| 296 | if err != nil { |
| 297 | return err |
| 298 | } |
| 299 | |
| 300 | // Parse the (rewritten) URL to extract all ranking options/keywords. |
| 301 | rewritten, err := url.Parse(in.RewrittenUrl) |
| 302 | if err != nil { |
| 303 | return err |
| 304 | } |
| 305 | rankingopts := ranking.RankingOptsFromQuery(rewritten.Query()) |
| 306 | |
| 307 | // TODO: analyze the query to see if fast path can be taken |
| 308 | // maybe by using a different worker? |
| 309 | simplified := re.Simplify() |
| 310 | caseSensitive := simplified.Flags&syntax.FoldCase != 0 |
| 311 | queryPos := s.UsePositionalIndex && simplified.Op == syntax.OpLiteral && !caseSensitive |
| 312 | var files ranking.ResultPaths |
| 313 | if queryPos { |
| 314 | possible, err := s.queryPositional(string(simplified.Rune)) |
| 315 | if err != nil { |
| 316 | return err |
| 317 | } |
| 318 | files = make(ranking.ResultPaths, 0, len(possible)) |
| 319 | for _, entry := range possible { |
| 320 | result := ranking.ResultPath{ |
| 321 | Path: entry.fn, |
| 322 | Position: int(entry.pos), |
| 323 | } |
| 324 | result.Rank(s.RankingMap, &rankingopts) |
| 325 | if result.Ranking > -1 { |
| 326 | files = append(files, result) |
| 327 | } |
| 328 | } |
| 329 | } else { |
| 330 | possible, err := s.query(index.RegexpQuery(re)) |
| 331 | if err != nil { |
| 332 | return err |
| 333 | } |
| 334 | |
| 335 | // Rank all the paths. |
| 336 | files = make(ranking.ResultPaths, 0, len(possible)) |
| 337 | for _, filename := range possible { |
| 338 | result := ranking.ResultPath{Path: filename} |
| 339 | result.Rank(s.RankingMap, &rankingopts) |
| 340 | if result.Ranking > -1 { |
| 341 | files = append(files, result) |
| 342 | } |
| 343 | } |
| 344 | |
| 345 | } |
| 346 | |
| 347 | // Filter all files that should be excluded. |
| 348 | files = FilterByKeywords(rewritten, files) |
| 349 | |
| 350 | // While not strictly necessary, this will lead to better results being |
nothing calls this directly
no test coverage detected