Gboard sticker search doesn't return result
Asked Answered
C

2

7

Via app indexing I added sticker packs to GBoard, but GBoard search can't find my stickers by keyword.

new Indexable.Builder("Sticker")
   .setName("Bye")
   .setImage("http://www.snoopysticker.com?id=1234")
   .setUrl("http://sticker/canonical/image/bye")
   .setDescription("A sticker for Bye")
   .put("keywords", "bye", "snoopy", "see ya", "good bye")
   .put("isPartOf",
        new Indexable.Builder("StickerPack")
          .setName("Snoopy Pack")
          .build())
   .build())};
Consecrate answered 5/9, 2017 at 8:44 Comment(5)
I also have problems with my stickers not appearing in gboard. I had to get the recent beta of Gboard to get the sticker feature at first. My personal stickers from Allo appeared instantly. Then I testet the stickers feature with the NBAmoji App and it worked flawlessly. But I still don't see the stickers indexed by my app appearing there. I followed the sample code almost exactly and I don't get any errors. Everything seems to work fine and the update task completes successfully. Sample code: github.com/firebase/quickstart-android/tree/master/app-indexingMonniemono
To get to the stickers in Gboard, long press the emoji button (comma). The new sticker icon is located at the very bottom between the emoji icon and the gif icon. Press it and you should see some stickers if available or a hint to download a sitcker app from the play store. Beware, there are also some crappy ones... ;-)Monniemono
However, you should provide more code of your IndexingService and StickerProvider and a detailed description of your problem, if you want others to help you. What does the log say? Any errors? How does the update task behave?Monniemono
@ArthurThompson any ideas? do we have to use a JobService?Monniemono
I got it! I renamed the Indexable.Builders. They must be named "Sticker" and "StickerPack" respectively. -> Indexable.Builder("StickerPack") (like in this question - so this is not an answer). Though it's in the example code, it's not explicitly documented.Monniemono
C
1

The problem is in another part of the code because what you have posted above works great in the following example adapted from Google's sample project for stickers:

public static void clearStickers(FirebaseAppIndex firebaseAppIndex) {
    Task<Void> task = firebaseAppIndex.removeAll();
    task.addOnSuccessListener(__ -> Log.i(TAG, SUCCESS_IN_CLEARING_STICKERS));
    task.addOnFailureListener(e -> Log.i(TAG, FAILED_TO_CLEAR_STICKERS, e));
}

public static void setStickers(final Context context, FirebaseAppIndex firebaseAppIndex) {
    try {
        List<Indexable> stickers = getIndexableStickers(context);
        Indexable stickerPack = getIndexableStickerPack(context);

        List<Indexable> indexables = new ArrayList<>(stickers);
        indexables.add(stickerPack);

        Task<Void> task = firebaseAppIndex.update(
                indexables.toArray(new Indexable[indexables.size()]));
        task.addOnSuccessListener(__ -> Log.i(TAG, SUCCESS_IN_INSTALLING_STICKERS));
        task.addOnFailureListener(e -> Log.i(TAG, FAILED_TO_INSTALL_STICKERS, e));

    } catch (IOException | FirebaseAppIndexingInvalidArgumentException e) {
        Log.e(TAG, ERROR_IN_SETTING_STICKERS, e);
    }
}

private static Indexable getIndexableStickerPack(final Context context)
        throws IOException, FirebaseAppIndexingInvalidArgumentException {
    List<Indexable> indexables = StreamSupport
            .stream(getStickerBuilders(context))
            .map(IndexableBuilder::build)
            .collect(Collectors.toList());

    StickerPackBuilder stickerPackBuilder = Indexables.stickerPackBuilder()
            .setName(STICKER_PACK_NAME)
            // Use the first sticker as the hero for the pack
            .setUrl(String.format(STICKER_PACK_URL_PATTERN, 0))
            // Defaults to the first sticker in "hasSticker". Used to select between sticker
            // packs so should be representative of the sticker pack.
            .setImage(StickersDataFactory.getAllStickerReference().get(0).getURL())
            .put("hasSticker", indexables.toArray(new Indexable[indexables.size()]))
            .setDescription(STICKER_PACK_NAME);
    return stickerPackBuilder.build();
}

private static List<Indexable> getIndexableStickers(final Context context)
        throws IOException, FirebaseAppIndexingInvalidArgumentException {
    List<Indexable> indexableStickers = new ArrayList<>();
    List<Indexable.Builder> stickerBuilders = getStickerBuilders(context);

    for (Indexable.Builder stickerBuilder : stickerBuilders) {
        stickerBuilder.put("keywords", getKeywordsForSticker(context, null))
                .put("isPartOf", new Indexable.Builder("StickerPack").setName(STICKER_PACK_NAME) .build());

        indexableStickers.add(stickerBuilder.build());
    }

    return indexableStickers;
}

private static List<Indexable.Builder> getStickerBuilders(final Context context)
        throws IOException, FirebaseAppIndexingInvalidArgumentException {
    List<Indexable.Builder> stickerBuilders = new ArrayList<>();

    // Start from 1 because the first sticker will be used as hero for the pack
    for (int i = 1; i < StickersDataFactory.getAllStickerReference().size(); i++) {
            stickerBuilders.add(new Indexable.Builder("Sticker")
                    .setName(StickersDataFactory.getAllStickerReference().get(i).getName())
                    .setUrl(String.format(STICKER_URL_PATTERN, i))
                    .setImage(StickersDataFactory.getAllStickerReference().get(i).getURL())
                    .setDescription("Random description")
                    .put("keywords", getKeywordsForSticker(context, StickersDataFactory.getAllStickerReference().get(i)))
                    .put("isPartOf", new Indexable.Builder("StickerPack").setName(STICKER_PACK_NAME) .build()));
    }

    return stickerBuilders;
}
Cestode answered 19/11, 2017 at 12:48 Comment(0)
V
0

Instead of new Indexable.Builder("Sticker") it should be Indexables.stickerBuilder(). I took this from this official Google example.

Velocipede answered 24/3, 2018 at 4:0 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.