Whoosh:Pure Python search engine library Part-1

Whoosh is a library of classes and functions for indexing text and then searching the index. It helps to develop custom search engines.

For example, if you were creating daily tasks software, you could use Whoosh to add a search function to allow users to search daily entries.

A very Basic Whoosh Example

1. Install Whoosh

pip install Whoosh

2. In terminal write following code

import os
from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(title=TEXT(stored=True),path=ID(stored=True),content=TEXT)
if not os.path.exists("indexdirectory"):
os.mkdir("indexdirectory")
ix = create_in("indexdirectory", schema)
writer = ix.writer()
writer.add_document(title=u"First day task", path=u"/xxx",content=u"current month is january and today's task is buy a gift for brother on his birthday!")
writer.add_document(title=u"Other task", path=u"/yyy",content=u"Today's task is to work on python!")
writer.commit()
from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse("birthday")
results = searcher.search(query)
results[0]

Output:
<Hit {'path': u'/xxx', 'title': u'First day task'}>

>>>> In next part we will be working in whoosh from a form in which text to search is to be given and the contents from which search to be made will be from database in django framework.

 

 



Integrating Whoosh in python

 

whoosh is a Pure python library used to create a search engine in personal website.

Right now Working on integrating whoosh in python project soon will be posting its code and details about how to do it.



Congratulations!

If you can read this post, it means that the registration process was successful and that you can start blogging.
Please replace this with your first real post as soon as possible.
Happy Python blogging!



Copyright(c) 2017 - PythonBlogs.com
By using this website, you signify your acceptance of Terms and Conditions and Privacy Policy
All rights reserved