Py-instant-search-redis - Source code example for how to build an instant search with redis in python

Overview

Build Status License Python version

py-instant-search-redis

Source code example for how to build an instant search (or real-time search) function with Redis in python.

This short source code will helps you understand about Redis Search feature and how to implement it into your project ideas (eg: use real-time search function for any ecommerce website like Book/Movie/Product/etc..) helps the user can search a product by tite/name/price/origin/category/... very quickly. Especially, this function can combine multiple search condition together which helps the system return the result with high accuracy.

Technical stack:

  1. Programming language: Python
  2. Backend server: Flask
  3. Redis (use redis cli and Redis server + Redisearch lib):
  4. Data source: you can access data source from MongoDB, MySQL, Postgres, etc and then index it into redis memory (I don't demo it here with this version)

Deploy/Running environment

  1. OS: Linux (Ubuntu or CentOS or other)
  2. If you want to use/try it on Windows, you can use Docker (with a linux image)

Prerequisite

  1. Install python environment
  2. Install Flask (https://flask.palletsprojects.com/en/2.0.x/installation/)
  3. Install Docker Engine on your development host if you want to run code or redis server by Docker container
  • Withow Docker engine desktop (on MacOS):
# Install hyperkit and minikube
brew install hyperkit
brew install minikube

# Install Docker CLI
brew install docker
brew install docker-compose

# Start minikube
minikube start

# Tell Docker CLI to talk to minikube's VM
eval $(minikube docker-env)

# Save IP to a hostname
echo "`minikube ip` docker.local" | sudo tee -a /etc/hosts > /dev/null

# Test
docker run hello-world
  1. Install Redis client and Redis server:
  • Redis Server (includes RedisSearch library)

You can run Redis server in a Docker container instead of run in on your host (this method help you install Redis quickly) Redis server docker here (includes redis search library): docker run -p 6379:6379 redislabs/redisearch:latest

Example code after installed Redis Client library

More about redisearch API here More about redis command/synctax here

from redisearch import Client, TextField, NumericField, Query

# Creating a client with a given index name
client = Client('myIndex')  #you can set any index name you want

# Creating the index definition and schema
client.create_index([TextField('title', weight=5.0), TextField('body')])

# Indexing a document
client.add_document('doc1', title = 'RediSearch', body = 'Redisearch implements a search engine on top of redis')

# Simple search
res = client.search("search engine")

# the result has the total number of results, and a list of documents
print res.total # "1"
print res.docs[0].title

# Searching with snippets
res = client.search("search engine", snippet_sizes = {'body': 50})

# Searching with complex parameters:
q = Query("search engine").verbatim().no_content().paging(0,5)
res = client.search(q)

My development environment:

  1. Laptop/PC: MacOS BigSur
  2. Python version: python3.8
  3. Install Redis Cli for Mac
  • Redis cli helps we can connect and interact with Redis server from command-line

We can use FT._LIST to list all existing indexs on the Redis server (or create, delete, view an index information) Check more about redis search command here (https://oss.redis.com/redisearch/Commands/)

  • Install steps on MacOS's terminal
brew update
brew install redis

//To check
redis-cli ping
//if you are getting PONG Then you are good to go

Now is time to start to code

  • Getting started >>

Now is time to start the server

#Server running functions =================================================================>
if __name__ == "__main__":
    app.run(host='0.0.0.0', port=5000, debug=True, threaded=True)

Run server on your host:

python3 main.py
Owner
Giap Le
Full-stack dev, Solution Architect in SaaS, PaaS, ML, DS, Mobile App, IoT, Autonomous
Giap Le
Simple XML-RPC and JSON-RPC server for modern Django

django-modern-rpc Build an XML-RPC and/or JSON-RPC server as part of your Django project. Major Django and Python versions are supported Main features

Antoine Lorence 82 Dec 04, 2022
An URL Shortener with Basic Features.

Simple Url Shortener What is that? Yet another url shortener built with Django framework. Preview HOW TO RUN? 1. Virtual Environment First create a vi

Ethem Turgut 6 Jan 25, 2022
open source online judge based on Vue, Django and Docker

An onlinejudge system based on Python and Vue

Qingdao University(青岛大学) 5.2k Jan 09, 2023
Django + Next.js integration

Django Next.js Django + Next.js integration From a comment on StackOverflow: Run 2 ports on the same server. One for django (public facing) and one fo

Quera 162 Jan 03, 2023
🏭 An easy-to-use implementation of Creation Methods for Django, backed by Faker.

Django-fakery An easy-to-use implementation of Creation Methods (aka Object Factory) for Django, backed by Faker. django_fakery will try to guess the

Flavio Curella 93 Oct 12, 2022
Declarative model lifecycle hooks, an alternative to Signals.

Django Lifecycle Hooks This project provides a @hook decorator as well as a base model and mixin to add lifecycle hooks to your Django models. Django'

Robert Singer 1k Dec 31, 2022
🗂️ 🔍 Geospatial Data Management and Search API - Django Apps

Geospatial Data API in Django Resonant GeoData (RGD) is a series of Django applications well suited for cataloging and searching annotated geospatial

Resonant GeoData 53 Nov 01, 2022
Displaying objects on maps in the Django views and administration site.

DjangoAdminGeomap library The free, open-source DjangoAdminGeomap library is designed to display objects on the map in the Django views and admin site

Vitaly Bogomolov 31 Dec 28, 2022
Auth module for Django and GarpixCMS

Garpix Auth Auth module for Django/DRF projects. Part of GarpixCMS. Used packages: django rest framework social-auth-app-django django-rest-framework-

GARPIX CMS 18 Mar 14, 2022
A Django based shop system

django-SHOP Django-SHOP aims to be a the easy, fun and fast e-commerce counterpart to django-CMS. Here you can find the full documentation for django-

Awesto 2.9k Dec 30, 2022
Django Girls Tutorial Workshop

Django Girls Tutorial Workshop A log of activities during the workshop. this is an H2 git remote add origin https://github.com/ahuimanu/django_girls_t

Jeffry Babb 1 Oct 27, 2021
Running in outer Django project folder (cd django_project)

Django Running in outer Django project folder (cd django_project) Make Migrations python manage.py makemigrations Migrate to Database python manage.py

1 Feb 07, 2022
Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project

Django URL Shortener Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project Install this package to your Dja

Rishav Sinha 4 Nov 18, 2021
Automatic class scheduler for Texas A&M written with Python+Django and React+Typescript

Rev Registration Description Rev Registration is an automatic class scheduler for Texas A&M, aimed at easing the process of course registration by gen

Aggie Coding Club 21 Nov 15, 2022
A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for quickly creating new images from the one assigned to the field.

django-versatileimagefield A drop-in replacement for django's ImageField that provides a flexible, intuitive and easily-extensible interface for creat

Jonathan Ellenberger 490 Dec 13, 2022
ProjectManagementWebsite - Project management website for CMSC495 built using the Django stack

ProjectManagementWebsite A minimal project management website for CMSC495 built

Justin 1 May 23, 2022
Getdp-project - A Django-built web app that generates a personalized banner of events to come

getdp-project https://get-my-dp.herokuapp.com/ A Django-built web app that gener

CODE 4 Aug 01, 2022
Django project starter on steroids: quickly create a Django app AND generate source code for data models + REST/GraphQL APIs (the generated code is auto-linted and has 100% test coverage).

Create Django App 💛 We're a Django project starter on steroids! One-line command to create a Django app with all the dependencies auto-installed AND

imagine.ai 68 Oct 19, 2022
Django based webapp pulling in crypto news and price data via api

Deploy Django in Production FTA project implementing containerization of Django Web Framework into Docker to be placed into Azure Container Services a

0 Sep 21, 2022
Auto-detecting the n+1 queries problem in Python

nplusone nplusone is a library for detecting the n+1 queries problem in Python ORMs, including SQLAlchemy, Peewee, and the Django ORM. The Problem Man

Joshua Carp 837 Dec 29, 2022