Skip to content
jsonW Paper GitHub

Search and ranking

Scoring by request: weights, cosine, sparse or grid, in one line

A one-line request scores every record in the file and returns the best ones, with the same result in the tool, the ABI and the 10 SDKs.

· jsonW 1.3.11

The problem

Ranking products, candidates or documents by a business rule usually becomes a long database query or a loop in application code that reads every column.

How jsonW solves it

avaliar takes a request: a weighted sum over numeric columns, the cosine with a vector, the sparse product or the grid. It reads only the columns it names, in parallel, and returns score, position and row. The same request exists in JSON, identical in the tool and in the ABI.

$ wjsw avaliar prod.jsw pesos "preco=-1,nota=10" 3
37.1	1	{id:2,produto:"Pão de queijo",categoria:"padaria",preco:8.90d,nota:4.6,…}
35.5	0	{id:1,produto:"Café especial",categoria:"bebida",preco:12.50d,nota:4.8,…}
31.1	2	{id:3,produto:"Chá verde",categoria:"bebida",preco:9.90d,nota:4.1,…}
$ wjsw avaliar prod.jsw '{"pesos":{"preco":-1}}' 2 --json
{"linha":1,"nota":-8.9,"valor":{"id":2,"produto":"Pão de queijo",…}}
{"linha":2,"nota":-9.9,"valor":{"id":3,"produto":"Chá verde",…}}

Real output. Price weighs against (−1) and rating in favor (10); in the JSON request, only price.

Where it is

wjsw avaliar, the ABI function and the SDKs for C, C++, Python, Node, Go, Rust, Java, Kotlin, Swift and PHP. The test suite checks that all of them return the same result, byte for byte.

Read the full section in the paper →