I want to search inside the payload of a value in Redis using Flask.
This is the code that I have written
# to fetch value:
localhost/suggestions?prefix=<name>
@app.route('/get')
def get():
try:
prefix = request.args.get('prefix')
n = prefix.strip()
result= ac.get_suggestions(n, fuzzy = True,with_payloads=True)
return(json.dumps([{'id': item.string, 'score': item.score,'payload':item.payload} for item in result]))
except Exception as e:
print(e)
I tried to search for a value present in the payload, but an empty list was returned.
I went through the following things:
EDIT:
imports:
import redis
import redisearch
import json
import string
from flask import Flask
import logging
#flask to expose api's to outside world
from flask import Flask,request,jsonify,render_template
from flask_restx import Resource
from redis import Redis, ConnectionPool
from redisearch.auto_complete import AutoCompleter,Suggestion
from _util import to_string
ac = AutoCompleter('ac')
app = Flask("autocomplete")
New value add:
# localhost/add?name=<name>
def add():
try:
name = request.args.get('name')
n = name.strip()
payload = {
"data": {
"value": "1",
}
}
ac.add_suggestions(Suggestion(n,1.0,json.dumps(payload )))
return "Added Successfully"
except Exception as e:
print(e)
return "Addition Failed"
I have even tried searching on the web but was unable to find a suitable solution.
Any help is appreciated.