Skip to content

Commit

Permalink
Make sure for image resource url enabled index image pixel size field…
Browse files Browse the repository at this point in the history
…s are filled

if at least one of the image size fields is enabled in index (images_height_val,
images_width_val, images_pixel_val). 
Previously all fields were required to be enabled (hint: default setting 
is height + width enabled)
  • Loading branch information
reger committed Apr 30, 2018
1 parent e67df10 commit a8234b7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 18 deletions.
38 changes: 21 additions & 17 deletions source/net/yacy/search/schema/CollectionConfiguration.java
Expand Up @@ -913,24 +913,28 @@ public SolrVector yacy2solr(

// handle image source meta data
if (document.getContentDomain() == ContentDomain.IMAGE) {
// add image pixel size if known
Iterator<ImageEntry> imgit = document.getImages().values().iterator();
List<Integer> heights = new ArrayList<>();
List<Integer> widths = new ArrayList<>();
List<Integer> pixels = new ArrayList<>();
while (imgit.hasNext()) {
ImageEntry img = imgit.next();
int imgpixels = (img.height() < 0 || img.width() < 0) ? -1 : img.height() * img.width();
if (imgpixels > 0 && (allAttr || (contains(CollectionSchema.images_height_val) && contains(CollectionSchema.images_width_val) && contains(CollectionSchema.images_pixel_val)))) {
heights.add(img.height());
widths.add(img.width());
pixels.add(imgpixels);
// add image pixel sizes if enabled in index
// get values if as least one of the size fields is enabled in index
if (allAttr || (contains(CollectionSchema.images_height_val) || contains(CollectionSchema.images_width_val)) || contains(CollectionSchema.images_pixel_val)) {
// add image pixel size if known
Iterator<ImageEntry> imgit = document.getImages().values().iterator();
List<Integer> heights = new ArrayList<>();
List<Integer> widths = new ArrayList<>();
List<Integer> pixels = new ArrayList<>();
while (imgit.hasNext()) {
ImageEntry img = imgit.next();
int imgpixels = (img.height() < 0 || img.width() < 0) ? -1 : img.height() * img.width();
if (imgpixels > 0) {
heights.add(img.height());
widths.add(img.width());
pixels.add(imgpixels);
}
}
if (heights.size() > 0) { // add to index document
add(doc, CollectionSchema.images_height_val, heights); // add() checks if field is enabled in index
add(doc, CollectionSchema.images_width_val, widths);
add(doc, CollectionSchema.images_pixel_val, pixels);
}
}
if (heights.size() > 0) {
add(doc, CollectionSchema.images_height_val, heights);
add(doc, CollectionSchema.images_width_val, widths);
add(doc, CollectionSchema.images_pixel_val, pixels);
}

if (allAttr || contains(CollectionSchema.images_text_t)) {
Expand Down
2 changes: 1 addition & 1 deletion source/net/yacy/search/schema/CollectionSchema.java
Expand Up @@ -161,7 +161,7 @@ public enum CollectionSchema implements SchemaDeclaration {
images_alt_sxt(SolrType.string, true, true, true, false, true, "all image link alt tag"), // no need to index this; don't turn it into a txt field; use images_text_t instead
images_height_val(SolrType.num_integer, true, true, true, false, false, "size of images:height"),
images_width_val(SolrType.num_integer, true, true, true, false, false, "size of images:width"),
images_pixel_val(SolrType.num_integer, true, true, true, false, false, "size of images as number of pixels (easier for a search restriction than with and height)"),
images_pixel_val(SolrType.num_integer, true, true, true, false, false, "size of images as number of pixels (easier for a search restriction than width and height)"),
images_withalt_i(SolrType.num_integer, true, true, false, false, false, "number of image links with alt tag"),
htags_i(SolrType.num_integer, true, true, false, false, false, "binary pattern for the existance of h1..h6 headlines"),
canonical_s(SolrType.string, true, true, false, false, false, "url inside the canonical link element"),
Expand Down

0 comments on commit a8234b7

Please sign in to comment.