Home » Python » whoosh – Define a function with Python, indentation rules-Exceptionshub

whoosh – Define a function with Python, indentation rules-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment


I have this code:

import os, os.path
import codecs
from whoosh import index
from whoosh.index import create_in
from whoosh.fields import Schema, TEXT, KEYWORD, ID, STORED
from whoosh import analysis
from whoosh.analysis import RegexTokenizer
from whoosh.analysis import StopFilter
import sys
root = "C:\Users\vitop\OneDrive\Desktop\Final Project\Test\Splitted\Txt"

def createSearchableData():    

    schema = Schema(title=TEXT(stored=True),path=ID(stored=True), content=TEXT(analyzer = my_analyzer),textdata=TEXT(stored=True))
    my_analyzer = RegexTokenizer()| StopFilter(lang = "en")

    # Creating a index writer to add document as per schema
    ix = index.create_in("indexdir",schema)
    writer = ix.writer()

    filepaths = [os.path.join(root,i) for i in os.listdir(root)]
    for path in filepaths:
        fp = open(path,'r', econding ="utf-8")
        text = fp.read()
        writer.add_document(title=path.split("\"), path=path,\


This was working fine until yesterday morning, after adding some extra files the folder (3 megabytes of txt files) it simply does not create any index anymore. When run, it just skips the code without giving any feedback on what is wrong.
I have uninstalled and reinstalled Anaconda and all the packages needed, tried to run the code with Spyder, JupyterNotebook, JypyterLab.
Nothing to do.
Help is badly needed being this part of my course project.

How to&Answers: