You've already forked pigallery2
mirror of
https://github.com/bpatrik/pigallery2.git
synced 2025-07-15 01:24:25 +02:00
implementing search
This commit is contained in:
@ -2,6 +2,7 @@ import {AutoCompleteItem, AutoCompeleteTypes} from "../../../common/entities/Aut
|
||||
import {ISearchManager} from "../ISearchManager";
|
||||
import {DirectoryModel} from "./entities/DirectoryModel";
|
||||
import {PhotoModel} from "./entities/PhotoModel";
|
||||
import {SearchResult} from "../../../common/entities/SearchResult";
|
||||
|
||||
export class MongoSearchManager implements ISearchManager {
|
||||
|
||||
@ -35,6 +36,70 @@ export class MongoSearchManager implements ISearchManager {
|
||||
});
|
||||
}
|
||||
|
||||
search(text, cb:(error:any, result:SearchResult) => void) {
|
||||
console.log("instantSearch: " + text);
|
||||
let result:SearchResult = new SearchResult();
|
||||
result.searchText = text;
|
||||
PhotoModel.find({
|
||||
name: {
|
||||
$regex: text,
|
||||
$options: "i"
|
||||
}
|
||||
}).populate('directory', 'name path').exec((err, res:Array<any>) => {
|
||||
if (err || !res) {
|
||||
return cb(err, null);
|
||||
}
|
||||
result.photos = res;
|
||||
|
||||
DirectoryModel.find({
|
||||
name: {
|
||||
$regex: text,
|
||||
$options: "i"
|
||||
}
|
||||
}).select('name').exec((err, res:Array<any>) => {
|
||||
if (err || !res) {
|
||||
return cb(err, null);
|
||||
}
|
||||
result.directories = res;
|
||||
return cb(null, result);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
instantSearch(text, cb:(error:any, result:SearchResult) => void) {
|
||||
console.log("instantSearch: " + text);
|
||||
let result:SearchResult = new SearchResult();
|
||||
result.searchText = text;
|
||||
PhotoModel.find({
|
||||
name: {
|
||||
$regex: text,
|
||||
$options: "i"
|
||||
}
|
||||
}).limit(10).populate('directory', 'name path').exec((err, res:Array<any>) => {
|
||||
if (err || !res) {
|
||||
return cb(err, null);
|
||||
}
|
||||
result.photos = res;
|
||||
|
||||
DirectoryModel.find({
|
||||
name: {
|
||||
$regex: text,
|
||||
$options: "i"
|
||||
}
|
||||
}).limit(10).exec((err, res:Array<any>) => {
|
||||
if (err || !res) {
|
||||
return cb(err, null);
|
||||
}
|
||||
result.directories = res;
|
||||
return cb(null, result);
|
||||
});
|
||||
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private encapsulateAutoComplete(values:Array<string>, type:AutoCompeleteTypes) {
|
||||
let res = [];
|
||||
values.forEach((value)=> {
|
||||
|
Reference in New Issue
Block a user