Reputation: 141
I am making an android app that uses algolia to search through an index that I made on the algolia dashboard like so:
Now when I query this in my android app with this code:
index = client.getIndex("games");
query = new Query();
query.setAttributesToRetrieve("Name", "FilePathName");
query.setAttributesToHighlight("Name", "FilePathName");
index.searchAsync(query, new CompletionHandler() {
@Override
public void requestCompleted(JSONObject content, AlgoliaException error) {
System.out.print(content);
}
});
the return json statement includes every element in the algolia index. The search is working because in the json return statement it shows that some do match the query string, but they are mixed in with all the games that do not match the query string. How can I get the json return statement to include only results that match a provided query string? Here is what the return statement looks like now:
{
"hits": [
{
"Starcraft II": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "starcraft2",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Starcraft II",
"matchLevel": "none",
"matchedWords": []
}
},
"Left 4 Dead": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "left4dead",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Left 4 Dead",
"matchLevel": "none",
"matchedWords": []
}
}, (A lot more games in here, deleted text to minimize space)
"objectID": "886515680",
"_highlightResult": {
"Borderlands 2": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "borderlands2",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Borderlands 2",
"matchLevel": "none",
"matchedWords": []
}
},
"Portal 2": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "portal2",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Portal 2",
"matchLevel": "none",
"matchedWords": []
}
},
"Starcraft II": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "starcraft2",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Starcraft II",
"matchLevel": "none",
"matchedWords": []
}
},
"Left 4 Dead": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "left4dead",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Left 4 Dead",
"matchLevel": "none",
"matchedWords": []
}
},
"Dark Souls": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "darksouls",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Dark Souls",
"matchLevel": "none",
"matchedWords": []
}
},
"Tom Clancy's The Division": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "thedivision",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Tom Clancy's The Division",
"matchLevel": "none",
"matchedWords": []
}
},
"name": {
"Consoles": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "None",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "",
"matchLevel": "none",
"matchedWords": []
}
},
"Destiny 2": {
"Consoles": [
{
"value": "Xbox 1",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "PC",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "destiny2",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "Shooter",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Adventure",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Destiny 2",
"matchLevel": "none",
"matchedWords": []
}
},
"Call of Duty: Black Ops 3": {
"Consoles": [
{
"value": "PC",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Xbox 1",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Xbox 360",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "PS3",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "PS4",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "bo3",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "FPS",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "<em>Call</em> <em>of</em> <em>Duty</em>: Black Ops 3",
"matchLevel": "full",
"fullyHighlighted": false,
"matchedWords": [
"call",
"of",
"duty"
]
}
},
"Forza 6": {
"Consoles": [
{
"value": "PC",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Xbox 1",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Xbox 360",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "forza6",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "Racing",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Forza 6",
"matchLevel": "none",
"matchedWords": []
}
},
"Minecraft": {
"Consoles": [
{
"value": "PC",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Xbox 1",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Xbox 360",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "minecraft",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "Adventure",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Creation",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Open World",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Minecraft",
"matchLevel": "none",
"matchedWords": []
}
},
"Overwatch": {
"Consoles": [
{
"value": "Xbox 1",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Xbox 360",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "PS3",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "PS4",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "PC",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "overwatch",
"matchLevel": "none",
"matchedWords": []
},
"Genre": [
{
"value": "competitive",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "moba",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "shooter",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Overwatch",
"matchLevel": "none",
"matchedWords": []
}
},
"Planetary Annihilation": {
"Consoles": [
{
"value": "PC",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "Steam",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "planetaryannihilation",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "Strategy",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Planetary Annihilation",
"matchLevel": "none",
"matchedWords": []
}
},
"Rust": {
"Consoles": [
{
"value": "Steam",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "rust",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "Survival",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Rust",
"matchLevel": "none",
"matchedWords": []
}
},
"Sea of Thieves": {
"Consoles": [
{
"value": "Xbox 1",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "PC",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "seaofthieves",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "Adventure",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "Sea <em>of</em> Thieves",
"matchLevel": "partial",
"fullyHighlighted": false,
"matchedWords": [
"of"
]
}
},
"The Last of Us": {
"Consoles": [
{
"value": "PS4",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "PS3",
"matchLevel": "none",
"matchedWords": []
}
],
"FilePathName": {
"value": "thelastofus",
"matchLevel": "none",
"matchedWords": []
},
"Genres": [
{
"value": "adventure",
"matchLevel": "none",
"matchedWords": []
},
{
"value": "survival",
"matchLevel": "none",
"matchedWords": []
}
],
"Name": {
"value": "The Last <em>of</em> Us",
"matchLevel": "partial",
"fullyHighlighted": false,
"matchedWords": [
"of"
]
}
}
},
"_rankingInfo": {
"nbTypos": 0,
"firstMatchedWord": 294,
"proximityDistance": 2,
"userScore": 0,
"geoDistance": 0,
"geoPrecision": 1,
"nbExactWords": 3,
"words": 3,
"filters": 0
}
}
],
"nbHits": 1,
"page": 0,
"nbPages": 1,
"hitsPerPage": 10,
"processingTimeMS": 1,
"exhaustiveNbHits": true,
"query": "call of duty",
"params": "query=call%20of%20duty&hitsPerPage=10&page=0&analytics=false&attributesToRetrieve=*&highlightPreTag=%3Cais-highlight-0000000000%3E&highlightPostTag=%3C%2Fais-highlight-0000000000%3E&getRankingInfo=1&facets=%5B%5D&tagFilters=",
"index": "games",
"serverUsed": "c5-use-3.algolia.net",
"parsedQuery": "call of duty",
"timeoutCounts": false,
"timeoutHits": false
}
Upvotes: 0
Views: 271
Reputation: 2447
Your index is not built the right way you should have one record for each game. Make sure you send one object per game when building your index.
Upvotes: 1