Skip to content

Commit

Permalink
Merge pull request #934 from Chia-Network/develop
Browse files Browse the repository at this point in the history
release 1.6.14 - improve assetid search
  • Loading branch information
TheLastCicada authored Oct 5, 2023
2 parents 7a94dde + 7afb8a4 commit 90e046b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cadt",
"version": "1.6.13",
"version": "1.6.14",
"_comment": "DONT CHANGE MAJOR UNLESS DATAMODEL CHANGES: The major version corresponds to the datamodel version your using, so 2.0.0 means it'll use datamodel v2",
"private": true,
"bin": "build/server.js",
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export const editHomeOrg = async (req, res) => {

return res.json({
message: 'Home org currently being updated, will be completed soon.',
success: true
success: true,
});
} catch (error) {
console.trace(error);
Expand Down Expand Up @@ -346,7 +346,7 @@ export const addMetadata = async (req, res) => {

return res.json({
message: 'Home org currently being updated, will be completed soon.',
success: true
success: true,
});
} catch (error) {
console.trace(error);
Expand Down
1 change: 0 additions & 1 deletion src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ app.get('/health', (req, res) => {
});
});


app.use('/v1', V1Router);

app.use((err, req, res, next) => {
Expand Down
35 changes: 25 additions & 10 deletions src/models/units/units.model.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ class Unit extends Model {
}

static async findAllSqliteFts(
searchStr,
userSearchInput,
orgUid,
pagination,
columns = [],
Expand All @@ -213,30 +213,39 @@ class Unit extends Model {
fields = columns.join(', ');
}

searchStr = sanitizeSqliteFtsQuery(searchStr);
userSearchInput = sanitizeSqliteFtsQuery(userSearchInput);

if (searchStr === '*') {
if (userSearchInput === '*') {
// * isn't a valid matcher on its own. return empty set
return {
count: 0,
rows: [],
};
}

if (searchStr.startsWith('+')) {
searchStr = searchStr.replace('+', ''); // If query starts with +, replace it
if (userSearchInput.startsWith('+')) {
userSearchInput = userSearchInput.replace('+', ''); // If query starts with +, replace it
}

let sql = `
SELECT ${fields}
FROM units_fts
WHERE units_fts MATCH :search`;
FROM units_fts
WHERE units_fts MATCH :search
UNION
SELECT ${fields}
FROM units_fts
WHERE units_fts MATCH :search2
`;

if (includeProjectInfo) {
sql = `SELECT units_fts.*
FROM units_fts
WHERE units_fts MATCH :search1
UNION
SELECT units_fts.*
FROM units_fts
WHERE units_fts MATCH :search3
UNION
SELECT units_fts.*
FROM units_fts
INNER JOIN issuances on units_fts.issuanceId = issuances.id
Expand All @@ -249,11 +258,17 @@ class Unit extends Model {
sql = `${sql} AND units_fts.orgUid = :orgUid`;
}

let replacements = { search: searchStr, orgUid };
// doing a union search with an 0x is a hack to allow us to search against assetIds easier
let replacements = {
search: userSearchInput,
search2: `0x${userSearchInput}`,
orgUid,
};
if (includeProjectInfo) {
replacements = {
search1: searchStr,
search2: searchStr,
search1: userSearchInput,
search2: userSearchInput,
search3: `0x${userSearchInput}`,
orgUid,
};
}
Expand Down

0 comments on commit 90e046b

Please sign in to comment.