GitHub - netgen/query-translator: Query Translator is a search query translator...
source link: https://github.com/netgen/query-translator
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
README.md
Query Translator
Query Translator takes a search string as user input and converts it into something a search backend can understand. Technically, it's a search query translator with abstract syntax tree representation. From the produced syntax tree, translation target can be anything you need. Usually it's a search backend, like Solr and Elasticsearch, or a database abstraction layer.
A set of interfaces for implementing a language processor is provided, with a single implemented language named Galach. Galach implements a syntax that is based on what seems to be the unofficial standard for search query as user input. Quick cheat sheet:
word
"phrase"
(group)
+mandatory
-prohibited
AND
&&
OR
||
NOT
!
#tag
@user
domain:term
Error handling
User input means you have to expect errors and handle them gracefully. Because of that, the parser is completely resistant to errors. Syntax tree will contain detailed information about corrections applied to make sense of the user input. This can be useful to clean up the input or implement rich input interface, with features like suggestions, syntax highlighting and error feedback.
Customization
The implementation was made with customization in mind. You can change the special characters which will be used as part of the syntax, pick out elements of the language you want to use, implement your own term clauses, or change how the syntax tree is converted to the target output.
Some use cases
- User-level query language on top of your search backend
- Common query language on top of different search backends
- Control over options of the query language that is already provided by the search backend
- Better error handling than provided by the search backend
- Analysis and manipulation of the query before sending to the backend
- Customized query language (while remaining within the base syntax)
- Implementing rich input interface (with suggestions, syntax highlighting, error feedback)
Note: This implementation is intended as a library, meaning it doesn't try to solve specific use cases for query translation. Instead, it's meant to be a base that you can use in implementing such a use case.
How to use
First add the library to your project:
composer require netgen/query-translator:^1.0
After that, make use of the features provided out of the box. If those are not enough, use extension points to customize various parts of the translator to fit your needs. See Galach documentation to find out more.
Run the demo
Demo is available as a separate repository at netgen/query-translator-demo.
Steps for running the demo:
- Create the demo project using composer
composer create-project netgen/query-translator-demo
- Position into the demo project directory
cd query-translator-demo
- Start the web server with
src
as the document rootphp -S localhost:8005 -t src
- Open http://localhost:8005 in your browser
Recommend
-
96
你应该了解的5个 Logstash Filter 插件 原文:5 Logstash Filter Plugins You Need to Know About 译者:
-
166
deepl-translator-cli This command line tool delivers text translation capabilities to your console, powered by DeepL (https://www.deepl.com/translator). Insta...
-
117
Page not found · GitHub · GitHub The 'madneal/articles-translator' repository doesn't contain the '出去就餐并且理解Express.js的基本知识.md' path in 'master'.
-
105
xterm-color - ANSI & xterm-256 color text property translator for Emacs
-
45
README.md GTRS - Google Translator Reverse Shell This tools uses Google Translator as a proxy to send arbitr...
-
9
Files Permalink Latest commit message Commit time
-
10
fanyi.el fanyi.el is a simple yet powerful multi-dictionaries interface for Emacs, includes: fanyi.el has integrations with: imenu, M-x imenu to jump to dictionary section di...
-
2
Netgen首页、文档和下载 - 二/三维四面体网格生成器 - OSCHINA - 中文开源技术交流社区 ...
-
18
TypeScript Error Translator Confused by TypeScript errors? Translate them into human-readable language right in your IDE. ...
-
8
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK