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

Revert "remove word_similarity temporary" #1501

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 45 additions & 44 deletions src/resolvers/projectResolver.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import {
fetchFeaturedProjectUpdate,
fetchLatestProjectUpdates,
fetchLikedProjectsQuery,
fetchMultiFilterAllProjectsQuery,
fetchNewProjectsPerDate,
fetchProjectBySlugQuery,
fetchProjectUpdatesQuery,
Expand Down Expand Up @@ -159,7 +160,7 @@ describe(
similarProjectsBySlugTestCases,
);

// describe('projectSearch test cases --->', projectSearchTestCases);
describe('projectSearch test cases --->', projectSearchTestCases);

describe('projectUpdates query test cases --->', projectUpdatesTestCases);

Expand Down Expand Up @@ -4203,49 +4204,49 @@ function projectUpdatesTestCases() {
});
}

// function projectSearchTestCases() {
// it('should return projects with a typo in the end of searchTerm', async () => {
// const limit = 1;
// const USER_DATA = SEED_DATA.FIRST_USER;
// const result = await axios.post(graphqlUrl, {
// query: fetchMultiFilterAllProjectsQuery,
// variables: {
// limit,
// // Typo in the title
// searchTerm: SEED_DATA.SECOND_PROJECT.title.slice(0, -1) + 'a',
// connectedWalletUserId: USER_DATA.id,
// },
// });

// const projects = result.data.data.allProjects.projects;
// assert.equal(projects.length, limit);
// assert.equal(projects[0].title, SEED_DATA.SECOND_PROJECT.title);
// assert.equal(projects[0].slug, SEED_DATA.SECOND_PROJECT.slug);
// assert.equal(projects[0].id, SEED_DATA.SECOND_PROJECT.id);
// });

// it('should return projects with the project title inverted in the searchTerm', async () => {
// const limit = 1;
// const USER_DATA = SEED_DATA.FIRST_USER;
// const result = await axios.post(graphqlUrl, {
// query: fetchMultiFilterAllProjectsQuery,
// variables: {
// limit,
// searchTerm: SEED_DATA.SECOND_PROJECT.title
// .split(' ')
// .reverse()
// .join(' '),
// connectedWalletUserId: USER_DATA.id,
// },
// });

// const projects = result.data.data.allProjects.projects;
// assert.equal(projects.length, limit);
// assert.equal(projects[0].title, SEED_DATA.SECOND_PROJECT.title);
// assert.equal(projects[0].slug, SEED_DATA.SECOND_PROJECT.slug);
// assert.equal(projects[0].id, SEED_DATA.SECOND_PROJECT.id);
// });
// }
function projectSearchTestCases() {
it('should return projects with a typo in the end of searchTerm', async () => {
const limit = 1;
const USER_DATA = SEED_DATA.FIRST_USER;
const result = await axios.post(graphqlUrl, {
query: fetchMultiFilterAllProjectsQuery,
variables: {
limit,
// Typo in the title
searchTerm: SEED_DATA.SECOND_PROJECT.title.slice(0, -1) + 'a',
connectedWalletUserId: USER_DATA.id,
},
});

const projects = result.data.data.allProjects.projects;
assert.equal(projects.length, limit);
assert.equal(projects[0].title, SEED_DATA.SECOND_PROJECT.title);
assert.equal(projects[0].slug, SEED_DATA.SECOND_PROJECT.slug);
assert.equal(projects[0].id, SEED_DATA.SECOND_PROJECT.id);
});

it('should return projects with the project title inverted in the searchTerm', async () => {
const limit = 1;
const USER_DATA = SEED_DATA.FIRST_USER;
const result = await axios.post(graphqlUrl, {
query: fetchMultiFilterAllProjectsQuery,
variables: {
limit,
searchTerm: SEED_DATA.SECOND_PROJECT.title
.split(' ')
.reverse()
.join(' '),
connectedWalletUserId: USER_DATA.id,
},
});

const projects = result.data.data.allProjects.projects;
assert.equal(projects.length, limit);
assert.equal(projects[0].title, SEED_DATA.SECOND_PROJECT.title);
assert.equal(projects[0].slug, SEED_DATA.SECOND_PROJECT.slug);
assert.equal(projects[0].id, SEED_DATA.SECOND_PROJECT.id);
});
}

function getProjectUpdatesTestCases() {
it('should return project updates with current take', async () => {
Expand Down
41 changes: 30 additions & 11 deletions src/resolvers/projectResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import { Donation } from '../entities/donation';
import { ProjectImage } from '../entities/projectImage';
import { ApolloContext } from '../types/ApolloContext';
import { publicSelectionFields, User } from '../entities/user';
import config from '../config';
import { Context } from '../context';
import SentryLogger from '../sentryLogger';
import {
Expand Down Expand Up @@ -318,21 +319,39 @@ export class ProjectResolver {
searchTerm?: string,
) {
if (!searchTerm) return query;
const similarityThreshold =
Number(config.get('PROJECT_SEARCH_SIMILARITY_THRESHOLD')) || 0.4;

return query.andWhere(
new Brackets(qb => {
qb.where('project.title ILIKE :searchTerm', {
searchTerm: `%${searchTerm}%`,
})
.orWhere('project.description ILIKE :searchTerm', {
searchTerm: `%${searchTerm}%`,
})
.orWhere('project.impactLocation ILIKE :searchTerm', {
searchTerm: `%${searchTerm}%`,
})
.orWhere('user.name ILIKE :searchTerm', {
qb.where(
'WORD_SIMILARITY(project.title, :searchTerm) > :similarityThreshold',
{
searchTerm: `%${searchTerm}%`,
});
similarityThreshold,
},
)
.orWhere(
'WORD_SIMILARITY(project.description, :searchTerm) > :similarityThreshold',
{
searchTerm: `%${searchTerm}%`,
similarityThreshold,
},
)
.orWhere(
'WORD_SIMILARITY(project.impactLocation, :searchTerm) > :similarityThreshold',
{
searchTerm: `%${searchTerm}%`,
similarityThreshold,
},
)
.orWhere(
'WORD_SIMILARITY(user.name, :searchTerm) > :similarityThreshold',
{
searchTerm: `%${searchTerm}%`,
similarityThreshold,
},
);
}),
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/server/adminJs/adminJsPermissions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,9 +275,7 @@ describe.skip('canAccessUserAction test cases', () => {
roles.forEach(role => {
Object.keys(actionsPerRole[role]).forEach(page => {
actions.forEach(action => {
it(`should return ${actionsPerRole[role][page].includes(
action,
)} for ${role} --> ${action} on ${page}`, function () {
it(`should return ${actionsPerRole[role][page].includes(action)} for ${role} --> ${action} on ${page}`, function () {
assert.strictEqual(
canAccessAction(role, page, action),
actionsPerRole[role][page].includes(action),
Expand Down
4 changes: 1 addition & 3 deletions src/services/recurringDonationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,7 @@ export const createRelatedDonationsToStream = async (

const toAddress = projectRelatedAddress?.address?.toLowerCase();
const fromAddress = donorUser.walletAddress?.toLowerCase();
const transactionTx = `${streamData.id?.toLowerCase()}-${
streamPeriod.endTime
}`;
const transactionTx = `${streamData.id?.toLowerCase()}-${streamPeriod.endTime}`;
const donation = Donation.create({
amount: normalizeNegativeAmount(
streamPeriod.amount,
Expand Down
Loading