Skip to content

Commit

Permalink
Refine search logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zzzzwen committed Mar 15, 2017
1 parent a62b31f commit 5d4a9fc
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions backend/proxy/movie.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,25 +33,25 @@ function getSearchString(searchString, priority) {
}

exports.getMovieByTitleCount = function (searchString) {
var rawString = searchString;
var rawString = searchString.trim();
return Movie.count({
where: sequelize.literal('"movies"."title" ILIKE \'' + getSearchString(rawString, 1) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 2) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 3) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 4) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 5) + '\'')
where: {
title: {
$ilike: '%' + rawString + '%'
}
}
})
};

exports.getMovieByTitle = function (userId, searchString, offset, limit) {

var rawString = searchString;
var rawString = searchString.trim();
return Movie.findAll({
where: sequelize.literal('"movies"."title" ILIKE \'' + getSearchString(rawString, 1) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 2) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 3) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 4) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 5) + '\''),
where: {
title: {
$ilike: '%' + rawString + '%'
}
},
limit: limit,
offset: offset,
include: [
Expand Down Expand Up @@ -89,13 +89,13 @@ exports.getMovieByTitle = function (userId, searchString, offset, limit) {

exports.getShowingMovieByTitle = function (userId, searchString) {

var rawString = searchString;
var rawString = searchString.trim();
return Movie.findAll({
where: sequelize.literal('"movies"."title" ILIKE \'' + getSearchString(rawString, 1) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 2) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 3) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 4) + '\' OR ' +
'"movies"."title" ILIKE \'' + getSearchString(rawString, 5) + '\''),
where: {
title: {
$ilike: '%' + rawString + '%'
}
},
include: [
{
model: PublicRate,
Expand Down

0 comments on commit 5d4a9fc

Please sign in to comment.