Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask search query giving another index results. #117

Open
cnvsuresh opened this issue Apr 1, 2021 · 1 comment
Open

Flask search query giving another index results. #117

cnvsuresh opened this issue Apr 1, 2021 · 1 comment

Comments

@cnvsuresh
Copy link

Hi,

I'm trying to use this library. When i was searching for a key in the stored docs it's giving correctly. After that, I've tried to create another index from the same code. Without trying to store any docs in the new index if I'm trying to run, it's giving the previously created index results with this new index name surprisingly. Can I get help on that to solve this issue?

First index details
`from flask import request
from flask_restful import Resource
from redisearch import Client, IndexDefinition, Query, TextField, TagField

index_name = 'myIndexQuery!'
host = 'redis-xxxxxxxx.redislabs.com'
port = 12906
password = 'xxxxxx'

class RedisClass(Resource):

@staticmethod
def put():
    client = Client(index_name, host=host, port=port, password=password)
    # Creating a client with a given index name
    # IndexDefinition is available for RediSearch 2.0+
    definition = IndexDefinition()

    # Creating the index definition and schema
    client.create_index((TextField("title", weight=5.0), TextField("body"), TagField("services")),
                        definition=definition)
    # client.alter_schema_add([TagField("description")])
    return True

@staticmethod
def post():
    client = Client(index_name, host=host, port=port, password=password)

    # Indexing a document for RediSearch 2.0+
    payload = request.get_json()
    doc_id = payload['doc_id']
    return client.redis.hset(doc_id, mapping=payload)

@staticmethod
def get():
    client = Client(index_name, host=host, port=port, password=password)
    print("Connected to %s" % client.__dict__)
    # add_document(title="meh, lol", tags="python,C")
    # Query("@title:meh @tags:{java}")
    query = request.args.get('query') if not ('type' in request.args) else "@description:{%s}" % request.args.get(
        'query')
    q = Query(query).with_scores().paging(0, 5)
    # .no_content()
    # .verbatim()
    res = client.search(q)
    # print("%s %s" % (query, json.dumps(res)))
    print("%s %s" % (query, res))
    # print(res.docs[0].id)
    for doc in res.docs:
        print("Ids %s" % doc.id)
    return True`

Second index details:

`from flask import request
from flask_restful import Resource
from redisearch import Client, IndexDefinition, Query, TextField, TagField

index_name = 'Gupta_myIndexQuery'
host = 'redis-xxxxxx.redislabs.com'
port = 12906
password = 'xxxxx'

class RedisSearchClass(Resource):

@staticmethod
def put():
    client = Client(index_name, host=host, port=port, password=password)
    # Creating a client with a given index name
    # IndexDefinition is available for RediSearch 2.0+
    definition = IndexDefinition()

    # Creating the index definition and schema
    client.create_index((TextField("title", weight=5.0), TextField("body"), TagField("services")),
                        definition=definition)
    # client.alter_schema_add([TagField("description")])
    return True

@staticmethod
def post():
    client = Client(index_name, host=host, port=port, password=password)

    # Indexing a document for RediSearch 2.0+
    payload = request.get_json()
    doc_id = payload['doc_id']
    return client.redis.hset(doc_id, mapping=payload)

@staticmethod
def get():
    client = Client(index_name, host=host, port=port, password=password)
    print("Connected to %s" % client.__dict__)
    # add_document(title="meh, lol", tags="python,C")
    # Query("@title:meh @tags:{java}")
    query = request.args.get('query') if not ('type' in request.args) else "@description:{%s}" % request.args.get(
        'query')
    q = Query(query).with_scores().verbatim().paging(0, 5)
    # .no_content()
    # .verbatim()
    res = client.search(q)
    # print("%s %s" % (query, json.dumps(res)))
    print("%s %s" % (query, res))
    # print(res.docs[0].id)
    for doc in res.docs:
        print("Ids %s" % doc.id)
    return True

`

@cnvsuresh
Copy link
Author

cnvsuresh commented Apr 1, 2021

I've found the Redis insight library. Installed and checked what are all the values exist.
Surprisingly, I've seen all the docs without index-based. It's storing all the keys plainly in DB.

Is there any index name concept? If yes what I've done wrongly in this. As per the insight, the library looks like not exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant