Skip to content

Commit

Permalink
Issue #18: add queryParser module
Browse files Browse the repository at this point in the history
  • Loading branch information
idrissneumann committed Nov 28, 2023
1 parent abd7860 commit 8451e7b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
24 changes: 24 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@testing-library/user-event": "^14.4.3",
"@types/jest": "^29.5.0",
"@types/lodash": "^4.14.194",
"@types/lucene": "^2.1.7",
"@types/node": "^18.15.11",
"@types/react": "17.0.42",
"@types/react-dom": "17.0.14",
Expand Down Expand Up @@ -66,6 +67,7 @@
"@grafana/runtime": "9.5.14",
"@grafana/ui": "9.5.14",
"@reduxjs/toolkit": "^1.9.5",
"lucene": "^2.1.1",
"react": "17.0.2",
"react-dom": "17.0.2",
"tslib": "2.5.3"
Expand Down
15 changes: 15 additions & 0 deletions src/queryParser.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import lucene from 'lucene';

function normalizeQuery(query: string) {
return query.replace(/(\w+)\s(:)/gi, '$1$2');
}

function parseQuery(query: string) {
try {
return lucene.parse(normalizeQuery(query));
} catch (e) {
return null;
}
}

export default parseQuery;

0 comments on commit 8451e7b

Please sign in to comment.