Fix tag and album results on tag and album searches.

master
Sander Vocke 6 years ago
parent 70308af91e
commit 5ccc4a72ab
  1. 4
      src/main.js
  2. 46
      src/queries.js
  3. 2
      src/resultsview.js

@ -150,14 +150,14 @@ export function MainPage() {
return ( return (
<ThemeProvider theme={theme}> <ThemeProvider theme={theme}>
<ProvideDB <ProvideDB
db_url="https://sandervocke-nas.duckdns.org/digikam-fatclient-data/digikam4.db" db_url="https://192.168.1.101/digikam-fatclient-data/digikam4.db"
> >
{({ db_error, db }) => ( {({ db_error, db }) => (
<> <>
{(db == null && !db_error) && <LoadingPage file={"digikam4.db"} />} {(db == null && !db_error) && <LoadingPage file={"digikam4.db"} />}
{db_error && <InternalErrorPage message={db_error.message} />} {db_error && <InternalErrorPage message={db_error.message} />}
{db != null && <LoadedMainPage database={db} photos_dir="https://sandervocke-nas.duckdns.org/digikam-fatclient-data/photos" thumbs_dir="https://sandervocke-nas.duckdns.org/digikam-fatclient-data/thumbs" />} {db != null && <LoadedMainPage database={db} photos_dir="https://192.168.1.101/digikam-fatclient-data/photos" thumbs_dir="https://192.168.1.101/digikam-fatclient-data/thumbs" />}
</> </>
)} )}
</ProvideDB> </ProvideDB>

@ -166,21 +166,21 @@ export class MatchingFilter extends ResultFilter {
if (this.match_type == MatchTypeEnum.MATCH_IMAGE_NAME_EQUALS) { if (this.match_type == MatchTypeEnum.MATCH_IMAGE_NAME_EQUALS) {
return '(Images.name="' + this.match_from + '")'; return '(Images.name="' + this.match_from + '")';
} else if (this.match_type == MatchTypeEnum.MATCH_IMAGE_NAME_NATURAL) { } else if (this.match_type == MatchTypeEnum.MATCH_IMAGE_NAME_NATURAL) {
return 'REGEXP(LOWER(Images.name), LOWER(".*' return '(Images.name NOT NULL AND REGEXP(LOWER(Images.name), LOWER(".*'
+ escape_regex(this.match_from) + escape_regex(this.match_from)
+ '.*"))'; + '.*")))';
} else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_EQUALS) { } else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_EQUALS) {
return '(Albums.relativePath="' + this.match_from + '")'; return '(Albums.relativePath="' + this.match_from + '")';
} else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD) { } else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD) {
return 'REGEXP(Albums.relativePath, "' return '(Albums.relativePath NOT NULL AND REGEXP(Albums.relativePath, "'
+ escape_regex(this.match_from) + escape_regex(this.match_from)
+ '(\/[^\/]+)*")'; + '(\/[^\/]+)*"))';
} else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_NATURAL) { } else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_NATURAL) {
throw new Error("Natural matching on album names is not yet supported."); throw new Error("Natural matching on album names is not yet supported.");
} else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_NAME_EQUALS) { } else if (this.match_type == MatchTypeEnum.MATCH_ALBUM_NAME_EQUALS) {
return 'REGEXP(Albums.relativePath, "\/(.*\/)*' return '(Albums.relativePath NOT NULL AND REGEXP(Albums.relativePath, "\/(.*\/)*'
+ escape_regex(this.match_from) + escape_regex(this.match_from)
+ '(\/[^\/]+)*")'; + '(\/[^\/]+)*"))';
} else if (this.match_type == MatchTypeEnum.MATCH_TAG_EQUALS) { } else if (this.match_type == MatchTypeEnum.MATCH_TAG_EQUALS) {
return '(Tags.fullname="' + this.match_from + '")'; return '(Tags.fullname="' + this.match_from + '")';
} else if (this.match_type == MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD) { } else if (this.match_type == MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD) {
@ -190,9 +190,9 @@ export class MatchingFilter extends ResultFilter {
} else if (this.match_type == MatchTypeEnum.MATCH_TAG_NATURAL) { } else if (this.match_type == MatchTypeEnum.MATCH_TAG_NATURAL) {
throw new Error("Natural matching on tag names is not yet supported."); throw new Error("Natural matching on tag names is not yet supported.");
} else if (this.match_type == MatchTypeEnum.MATCH_TAG_NAME_EQUALS) { } else if (this.match_type == MatchTypeEnum.MATCH_TAG_NAME_EQUALS) {
return 'REGEXP(Tags.fullname, "\/(.*\/)*' return '(Tags.fullname NOT NULL AND REGEXP(Tags.fullname, "\/(.*\/)*'
+ escape_regex(this.match_from) + escape_regex(this.match_from)
+ '(\/[^\/]+)*")'; + '(\/[^\/]+)*"))';
} }
console.log(this); console.log(this);
@ -269,17 +269,39 @@ export function image_query_with_where(maybe_where) {
// This query will return database entries with the fields "id" and "relativePath" for each matching album. // This query will return database entries with the fields "id" and "relativePath" for each matching album.
export function album_query_with_where(maybe_where) { export function album_query_with_where(maybe_where) {
return "SELECT Albums.id, Albums.relativePath FROM Albums " + (maybe_where ? maybe_where : "") + ";"; var query = "SELECT Albums.id, Albums.relativePath FROM Albums";
// If there is tags/images stuff in the where clause, we need to do a join on those tables.
if(maybe_where && (maybe_where.includes("Tags.") || maybe_where.includes("Images."))) {
query = query + " LEFT JOIN Images ON Images.album=Albums.id "
+ " LEFT JOIN ImageTags ON ImageTags.imageid=Images.id "
+ " LEFT JOIN Tags ON Tags.id=ImageTags.tagid";
}
query = query + " " + (maybe_where ? maybe_where : "") + " GROUP BY Albums.id;";
return query;
} }
// This query will return database entries with the fields "id" and "name" for each matching tag. // This query will return database entries with the fields "id" and "name" for each matching tag.
export function tag_query_with_where(maybe_where) { export function tag_query_with_where(maybe_where) {
var query = "SELECT Tags.id, Tags.name, Tags.fullname FROM Tags LEFT JOIN TagProperties ON Tags.id=TagProperties.tagid";
// Add a clause to the WHERE to hide internal tags. // Add a clause to the WHERE to hide internal tags.
var exclude_internal = ' (Tags.name="People" OR TagProperties.property IS NULL OR TagProperties.property<>"internalTag")'; var exclude_internal = ' (Tags.name="People" OR TagProperties.property IS NULL OR TagProperties.property<>"internalTag")';
var where = maybe_where ? var where = maybe_where ?
maybe_where + ' AND' + exclude_internal : maybe_where + ' AND' + exclude_internal :
"WHERE " + exclude_internal; "WHERE " + exclude_internal;
return "SELECT Tags.id, Tags.name, Tags.fullname FROM Tags LEFT JOIN TagProperties ON Tags.id=TagProperties.tagid " + where + " GROUP BY Tags.fullname;";
// If there is albums/images stuff in the where clause, we need to do a join on those tables.
if(where.includes("Albums.") || where.includes("Images.")) {
query = query + " LEFT JOIN ImageTags ON ImageTags.tagid=Tags.id "
+ " LEFT JOIN Images ON Images.id=ImageTags.imageid "
+ " LEFT JOIN Albums ON Albums.id=Images.album";
}
query = query + " " + where + " GROUP BY Tags.id;";
return query;
} }
export function maybe_image_query(user_query, database) { export function maybe_image_query(user_query, database) {
@ -393,7 +415,6 @@ export function user_query_from_browsed_album(album_path) {
album_path, album_path,
MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD, MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD,
false).simplify(); false).simplify();
/*
r.album_filter = r.album_filter =
new MatchingFilter( new MatchingFilter(
ResultTypeEnum.ALBUM, ResultTypeEnum.ALBUM,
@ -406,7 +427,6 @@ export function user_query_from_browsed_album(album_path) {
album_path, album_path,
MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD, MatchTypeEnum.MATCH_ALBUM_EQUALS_OR_CHILD,
false).simplify(); false).simplify();
*/
return r; return r;
} }
@ -418,7 +438,6 @@ export function user_query_from_browsed_tag(tag_path) {
tag_path, tag_path,
MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD, MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD,
false).simplify(); false).simplify();
/*
r.album_filter = r.album_filter =
new MatchingFilter( new MatchingFilter(
ResultTypeEnum.ALBUM, ResultTypeEnum.ALBUM,
@ -431,7 +450,6 @@ export function user_query_from_browsed_tag(tag_path) {
tag_path, tag_path,
MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD, MatchTypeEnum.MATCH_TAG_EQUALS_OR_CHILD,
false).simplify(); false).simplify();
*/
return r; return r;
} }

@ -66,7 +66,7 @@ export function TagItemView(props) {
<Button <Button
variant="outlined" variant="outlined"
startIcon={<LabelIcon />}> startIcon={<LabelIcon />}>
{tag.state.name} {tag.state.fullname}
</Button> </Button>
) )
} }

Loading…
Cancel
Save