Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sdk-client): Lucene Query Builder Architecture #28539

Merged
merged 25 commits into from
May 20, 2024

Conversation

zJaaal
Copy link
Contributor

@zJaaal zJaaal commented May 13, 2024

Proposed changes

  • Add composite/builder class QueryBuilder to handle the simple cases of building a Lucene Query
  • Add tests to be sure that the class works as expected

Lucene Syntax

Note

I used this docs as reference for this Query Builder

Field

Lucene supports fielded data. When performing a search you can either specify a field, or use the default field. The field names and default field is implementation specific.

You can search any field by typing the field name followed by a colon ":" and then the term you are looking for.

Example: +myField:

Term

A query is broken up into terms and operators. There are two types of terms: Single Terms and Phrases.

A Single Term is a single word such as "test" or "hello".

A Phrase is a group of words surrounded by double quotes such as "hello dolly".

Operand

Boolean operators allow terms to be combined through logic operators. Lucene supports AND, "+", OR, NOT and "-" as Boolean operators(Note: Boolean operators must be ALL CAPS).

By the time, we only support OR, AND & NOT

Architecture Diagram

I used a combination of composite and builder pattern to create a cycle that allows the developer to always write a lucene query with a correct syntax and avoid early building of queries.

Screenshot 2024-05-14 at 10 45 05 AM

Look how we can only end the cycle by getting to a term and calling the build method, this is to prevent the building of invalid Queries.

We can say that a Lucene Query should always end in a Term to be valid and complete.

Update: Term naming was changed to Equals in the code.

@zJaaal zJaaal marked this pull request as ready for review May 14, 2024 13:35
@fmontes fmontes enabled auto-merge May 20, 2024 14:26
@fmontes fmontes added this pull request to the merge queue May 20, 2024
Merged via the queue into master with commit fd4cb0f May 20, 2024
15 checks passed
@fmontes fmontes deleted the 28537-sdk-simple-lucene-query-builder-for-content-api branch May 20, 2024 16:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

SDK: Simple Lucene Query Builder for Content API
6 participants