0

I am a complete newbie to to python as well as Whoosh.

I need to create a search engine that allows me to search inside an XML file. For that, I have downloaded Whoosh and from the command prompt

setup.py build 

setup.py install  

I then took a sample code from the http://pythonhosted.org/Whoosh/quickstart.html

from whoosh.index import create_in
from whoosh.fields import *
schema = Schema(title=TEXT(stored=True), path=ID(stored=True), content=TEXT)

ix = create_in("indexdir", schema)
writer = ix.writer()
writer.add_document(title=u"First document", path=u"/a", content=u"This is the first document we've added!")
writer.add_document(title=u"Second document", path=u"/b", content=u"The second one is even more interesting!")
writer.commit()

from whoosh.qparser import QueryParser
with ix.searcher() as searcher:
query = QueryParser("content", ix.schema).parse("first")
results = searcher.search(query)
results[0]

And I am getting an Unresolved import error:create_in and the same for QueryParser as well.

I am not sure if I have to add some path variables. There was not enough documentation on getting started with Whoosh, rather, there are more and more sample codes.

Thanks in advance!

viggie
  • 183
  • 1
  • 3
  • 11

1 Answers1

1

I strongly recommend using a module installer like easy_install or PIP instead of manual installation of modules as it will save you from a lot of problems and issues (like this one, after installing whoosh with pip the imports are working very well for me).

You can learn how to install pip on the official site http://www.pip-installer.org/en/latest/installing.html and after you've done it - getting whoosh is as simple as

pip install whoosh
Tymoteusz Paul
  • 2,732
  • 17
  • 20
  • I have installed it using easy_install Whoosh! I still get the same problem. – viggie Jun 20 '13 at 12:07
  • Well it's an issue with your python setup. Try using virtualenv to create a clean one and install it there with pip. – Tymoteusz Paul Jun 20 '13 at 12:34
  • Kindly elaborate on what is a virtualenv. – viggie Jun 20 '13 at 12:48
  • @viggie kindly: https://www.google.co.uk/search?q=virtualenv&oq=virtualenv&aqs=chrome.0.69i57j69i60j69i65l2j69i59j69i61.1600j0&sourceid=chrome&ie=UTF-8 :) – Tymoteusz Paul Jun 20 '13 at 12:50
  • thanks for the overdose of commonsense :) I did 'pip install Whoosh' and it just says that "Requirement already up-to-date: Whoosh in c:\..\site-packages\whoosh-2.4.1-py2.7.egg " And I am getting the same errors.. any idea on how to fix this ? – viggie Jun 20 '13 at 16:11
  • @viggie as i said before there is something wrong with your python install as on clear instance it works just fine. You can reinstal python, run it with virtual env, pick what you prefer but the issue is inside your python. – Tymoteusz Paul Jun 20 '13 at 18:27
  • It was all right with my python. I had to restart my computer twice after which Whoosh now works!! Damn.. I got no clue why two times.. But still it works, so i am happy. Thanks for ur help :) – viggie Jun 21 '13 at 09:45