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

search: allow advanced filters #1995

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft

search: allow advanced filters #1995

wants to merge 9 commits into from

Conversation

pierre
Copy link
Member

@pierre pierre commented Mar 28, 2024

The search key is opaque to the system. Interpret the prefix marker _q=1 as the beginning of an advanced query, allowing to filter on specific fields, e.g.:

_q=1&[email protected]&currency=USD

It is the responsibility of the user to add relevant indexes.

The search key is opaque to the system. Interpret the
prefix marker _q=1 as the beginning of an advanced query,
allowing to filter on specific fields, e.g.:

  _q=1&[email protected]&currency=USD

It is the responsability of the user to add relevant indexes.

Signed-off-by: Pierre-Alexandre Meyer <[email protected]>
Simple solution to work around lack of implicit casting
on PostgreSQL. Good enough for now?

Signed-off-by: Pierre-Alexandre Meyer <[email protected]>
This allows us to find all open and paid invoices for instance.

Signed-off-by: Pierre-Alexandre Meyer <[email protected]>
Copy link
Member

@sbrossie sbrossie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👏

searchQuery = new SearchQuery(SqlOperator.OR);
searchQuery.addSearchClause("currency", SqlOperator.EQ, searchKey);
} else if (searchKey.startsWith(SEARCH_QUERY_MARKER)) {
final Matcher matcher = BALANCE_QUERY_PATTERN.matcher(searchKey);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the use case that we have to show (return) invoices matching specific balance criteria for the given tenant - and not for a specific account?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the use-case is to filter invoices for that tenant and balance criteria, e.g., show me all unpaid invoices.

There is a branch in the code because it doesn't support additional filtering capabilities: it's either balance filter or any other filter. Cannot do: show me all unpaid invoices in the last month unfortunately. We might be able to do it, it's just a bit hard with the balance specific query...

>>

searchByCurrency(ordering) ::= <<
searchInvoicesByBalance(ordering, comparisonOperator) ::= <<
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The result(s) we return will match the criteria, but since we just return the columns (fileds), the exact balance will not be returned, is this correct - i.e. balance computation is just used for search criteria and not to populate the objects being returned?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

balance computation is just used for search criteria and not to populate the objects being returned

Correct.

since we just return the columns (fileds)

That's a good point, I need to check if the objects are re-hydrated at higher levels of the stack or if I should select more columns here.

Copy link
Member

@sbrossie sbrossie May 31, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am just wondering if we could use the amount computed from the underlying invoiceBalanceQuery() so we don't have to rehydrate the invoices as it is very expensive. However, not returning the balance is an issue as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could:

  • Modify InvoiceModelDao to have a balance field. This is set only in this new codepath, when computing the balance in SQL (the balance column from the SQL query should automatically populate it if the getter and setter for balance are added in InvoiceModelDao.
  • Modify DefaultInvoice to have a private balance field. If set during construction of the object (pulled from InvoiceModelDao), getBalance() returns it, otherwise, it goes through the computation like today.

@reshmabidikar Could you give this a try? When doing searches, the invoices will still be shallow, but when searchInvoicesByBalance is called, the balance should be returned. If this work, we could also look at updating the other search queries to do the same?

@pierre
Copy link
Member Author

pierre commented Mar 30, 2024

Note to self: unresolved comments must be addressed before merging.

, x.tenant_record_id
, SUM(x.amount) as balance
FROM (
SELECT
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need that first query - is it because we want to return also that DRAFT or VOID invoices?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could:

  • Modify InvoiceModelDao to have a balance field. This is set only in this new codepath, when computing the balance in SQL (the balance column from the SQL query should automatically populate it if the getter and setter for balance are added in InvoiceModelDao.
  • Modify DefaultInvoice to have a private balance field. If set during construction of the object (pulled from InvoiceModelDao), getBalance() returns it, otherwise, it goes through the computation like today.

@reshmabidikar Could you give this a try? When doing searches, the invoices will still be shallow, but when searchInvoicesByBalance is called, the balance should be returned. If this work, we could also look at updating the other search queries to do the same?

JOIN invoices inv ON ii.invoice_id = inv.id
LEFT OUTER JOIN tags tg ON ii.invoice_id = tg.object_id
WHERE
ii.type in ('TAX', 'EXTERNAL_CHARGE', 'FIXED', 'USAGE', 'RECURRING', 'ITEM_ADJ', 'REPAIR_ADJ', 'PARENT_SUMMARY', 'CBA_ADJ', 'CREDIT_ADJ')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like all the InvoiceItemType are present here, so is this needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants