{"id":22473123,"url":"https://github.com/bas080/lucene-query-string-builder","last_synced_at":"2025-08-02T10:30:59.172Z","repository":{"id":8179463,"uuid":"57116824","full_name":"bas080/lucene-query-string-builder","owner":"bas080","description":"Build complex lucene query strings with basic functions","archived":false,"fork":false,"pushed_at":"2022-04-02T19:54:35.000Z","size":305,"stargazers_count":11,"open_issues_count":3,"forks_count":5,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-11-13T03:44:16.111Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/bas080.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-04-26T09:46:47.000Z","updated_at":"2023-03-26T04:39:07.000Z","dependencies_parsed_at":"2022-08-06T21:00:17.705Z","dependency_job_id":null,"html_url":"https://github.com/bas080/lucene-query-string-builder","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bas080%2Flucene-query-string-builder","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bas080%2Flucene-query-string-builder/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bas080%2Flucene-query-string-builder/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bas080%2Flucene-query-string-builder/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bas080","download_url":"https://codeload.github.com/bas080/lucene-query-string-builder/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228461622,"owners_count":17923830,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-06T12:19:12.146Z","updated_at":"2024-12-06T12:19:14.538Z","avatar_url":"https://github.com/bas080.png","language":"JavaScript","readme":"# Lucene Query String Builder\n\n[![NPM](https://img.shields.io/npm/v/lucene-query-string-builder?color=blue\u0026style=flat-square)](https://www.npmjs.com/package/lucene-query-string-builder)\n[![NPM Downloads](https://img.shields.io/npm/dm/lucene-query-string-builder?style=flat-square)](https://www.npmjs.com/package/lucene-query-string-builder)\n[![Dependency Status](https://img.shields.io/librariesio/release/npm/lucene-query-string-builder?style=flat-square)](https://libraries.io/npm/lucene-query-string-builder)\n[![Standard Code Style](https://img.shields.io/badge/code_style-standard-brightgreen.svg?style=flat-square)](https://standardjs.com)\n\n## Notice\n\n*Lucene Query String Builder* is looking for a developer to help with the API.\nI'll continue performing the maintenance tasks.\n\nEasily build your lucene string queries using small and pure functions.\n\nImagine having an API that leverages lucene for performing queries on the\n(indexed) database. In that case you might want to generate lucene query strings on\nthe client/front end.\n\nThe usage section shows how you can leverage this lib for your purposes.\n\n## Setup\n\n```bash\nnpm install lucene-query-string-builder --save\n```\n\n## Features\n\n- escapes lucene special chars when creating a term string\n- contains all the operators lucene uses\n- simple lucene.builder function for defining a lucene query builder\n\n## Usage\n\nLet's see how you can use lucene query string builder to define lucene query\nstrings with simple JavaScript functions.\n\nAssuming that the lucene global variable contains the lucene functions. This\nwould be the default when loaded into a browser.\n\n```JavaScript\n\nvar findUserLuceneQueryString = lucene.builder(function(data){\n\n  // just to make the example more readable;\n  var _ = lucene;\n\n  return _.group(_.and(\n    _.field('eye-color', _.term(data.eye.color)),\n    _.field('age', _.range(data.age.min, data.age.max))\n  ));\n\n});\n\nvar luceneQueryString = findUserLuceneQueryString({\n  eye: { color: 'brown'},\n  age: {\n    min: 10,\n    max: 20\n  }\n});\n\nluceneQueryString === '( eye-color: \"brown\" AND age:{ 10 TO 20 } )' // =\u003e true\n\n```\nThe functions are based on the lucene specifications found here:\nhttps://lucene.apache.org/core/2_9_4/queryparsersyntax.html#Terms\n\n```JavaScript\n\n  var _ = lucene;\n\n  /***\n   * terms or term\n   */\n\n  _.term('hello'); // =\u003e '\"hello\"'\n\n  _.terms('hello world'); // =\u003e '\"hello world\"'\n\n\n  /***\n   * field\n   */\n\n  _.field('hello', _.term('world')); // =\u003e 'hello: \"world\"'\n\n\n  /***\n   * or/and/not\n   *\n   * These functions are variadic and all work the same way. This example only\n     shows the or but it works similar with and and not\n   */\n\n  _.or(_.term('hello'), _.term('world')); // =\u003e '\"hello\" OR \"world\"'\n\n  _.or(_.term('hello'), _.term('you'), _.term('world')); // =\u003e '\"hello\" OR \"you\" OR \"world\"'\n\n\n  /***\n   * group\n   *\n   * Is a variadic function too\n   */\n\n  _.group(_.term('hello'), _.term('you'), _.term('world')); // =\u003e '( \"hello\" \"you\" \"world\" )'\n\n\n  /***\n   * range\n   *\n   * Takes two strings and 2 booleans.\n   */\n\n  /* combined with the field function to query for ages between 10 and 20 */\n  _.field('age', _.range(10, 20)); // =\u003e 'age: { 10 TO 20 }'\n\n\n  /***\n   * fuzzy\n   */\n\n  _.fuzzy(_.term('hello'), 0.2); // =\u003e '\"hello\"~0.2'\n\n\n  /***\n   * proximity\n   */\n\n  _.proximity(\"a\", \"c\", 2); // =\u003e '\"a b\"'~2\n\n\n  /***\n   * required\n   */\n\n  _.required(_.term('required')); // =\u003e '+\"required\"'\n\n```\n\n## Tests\n\n```bash bash\nset -eo pipefail\n\n{\n  npm i\n  npm prune\n} \u003e /dev/null\n\nnpx standard --fix\nnpx nyc npm t\n```\n```\n\n\u003e lucene-query-string-builder@1.0.7 test\n\u003e tape ./test/index.js\n\nTAP version 13\n# builder\nok 1 should be strictly equal\n# range\nok 2 should be strictly equal\nok 3 should be strictly equal\nok 4 should be strictly equal\nok 5 should be strictly equal\n# group\nok 6 should be strictly equal\n# term\nok 7 should be strictly equal\nok 8 should be strictly equal\n# fuzzy\nok 9 should throw\nok 10 should be strictly equal\nok 11 should be strictly equal\nok 12 should be strictly equal\nok 13 should be strictly equal\nok 14 should be strictly equal\nok 15 should be strictly equal\n# proximity\nok 16 should be strictly equal\nok 17 should throw\nok 18 should throw\nok 19 should throw\nok 20 should throw\nok 21 should throw\n# or/and/not\nok 22 should be strictly equal\nok 23 should be strictly equal\nok 24 should be strictly equal\nok 25 should be strictly equal\nok 26 should be strictly equal\nok 27 should be strictly equal\n\n1..27\n# tests 27\n# pass  27\n\n# ok\n\n----------|---------|----------|---------|---------|-------------------\nFile      | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s \n----------|---------|----------|---------|---------|-------------------\nAll files |   90.32 |    94.44 |   88.24 |   90.91 |                   \n index.js |   90.32 |    94.44 |   88.24 |   90.91 | 69-72,165-167     \n----------|---------|----------|---------|---------|-------------------\n```\n\n## Contributing\n\nI have not gotten the chance to use this lib in my own projects. Please share\nyour thoughts, issues and improvements.\n\n- Make sure your dependencies are installed by running: `npm run-script setup`\n- Then start editing the index.js\n- You should add and/or edit the tests in test/index.js\n- Run your tests and see what happens\n\nWhen performing pull request make sure to not add the **dist** files. This is left\nto the maintainers(s) of the library. They are responsible to version and avoid\ncode breakages.\n\nYou can perform your own build with `npm run-script` build to make a *lucine.js* and\na *lucine.min.js*\n\n**notice**\n\nI am currently not using this repository in any of my projects. Therefore I am looking\nfor people that are able to make LQSB more useful for them and others.\n\n## Road map\n\n- split all functions into separate files\n- tasks for running tests on dist/lucene.js and dist/lucene.min.js\n\n## License\n\nThe MIT License (MIT)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbas080%2Flucene-query-string-builder","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbas080%2Flucene-query-string-builder","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbas080%2Flucene-query-string-builder/lists"}