Inverted index: Difference between revisions

Content added Content deleted
(jq)
m (→‎{{header|jq}}: shorten lines)
Line 1,660: Line 1,660:
<lang jq>def prompt_search:
<lang jq>def prompt_search:
"Enter a string or an array of strings to search for, quoting each string, or 0 to exit:",
"Enter a string or an array of strings to search for, quoting each string, or 0 to exit:",
( (input | if type == "array" then . elif type == "string" then [.] else empty end) as $in
( (input | if type == "array" then . elif type == "string" then [.]
else empty
end) as $in
| search($in), prompt_search ) ;
| search($in), prompt_search ) ;


Line 1,666: Line 1,668:


'''Example''':
'''Example''':
<lang sh>$ jq -r -c -n --argfile in <(jq -R 'split(" ") | select(length>0) | [input_filename, unique]' T?.txt) -f Inverted_index.jq
<lang sh>
$ jq -r -c -n --argfile in <(jq -R 'split(" ") | select(length>0) | [input_filename, unique]' T?.txt) -f Inverted_index.jq
Enter a string or an array of strings to search for, quoting each string, or 0 to exit:
Enter a string or an array of strings to search for, quoting each string, or 0 to exit:
"is"
"is"