2009-06-22 64 views
10

我需要使用Google App Engine進行全文搜索。我發現項目Whoosh,它運行得非常好,只要我使用App Engine開發環境......當我將應用程序上傳到App Engine時,我得到以下TraceBack。對於我的測試,我正在使用此項目中提供的示例應用程序。任何想法我做錯了什麼?帶引擎的App Engine上的全文搜索

<type 'exceptions.ImportError'>: cannot import name loads 
Traceback (most recent call last): 
    File "/base/data/home/apps/myapp/1.334374478538362709/hello.py", line 6, in <module> 
    from whoosh import store 
    File "/base/data/home/apps/myapp/1.334374478538362709/whoosh/__init__.py", line 17, in <module> 
    from whoosh.index import open_dir, create_in 
    File "/base/data/home/apps/myapp/1.334374478538362709/whoosh/index.py", line 31, in <module> 
    from whoosh import fields, store 
    File "/base/data/home/apps/myapp/1.334374478538362709/whoosh/store.py", line 27, in <module> 
    from whoosh import tables 
    File "/base/data/home/apps/myapp/1.334374478538362709/whoosh/tables.py", line 43, in <module> 
    from marshal import loads 

這是我在我的Python文件中的導入。

# Whoosh ---------------------------------------------------------------------- 
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', 'utils'))) 
from whoosh.fields import Schema, STORED, ID, KEYWORD, TEXT 
from whoosh.index import getdatastoreindex 
from whoosh.qparser import QueryParser, MultifieldParser 

預先感謝您的幫助!

回答

3

應用程序引擎不支持編組模塊。它在那裏,但它是空的。元帥正在開發中正常工作。環境已經registered as an issue

請參閱the documentation

你可以嘗試下面的方法來monkeypatch編組模塊。把下面的代碼,你做任何其他進口前:

import pickle 
import marshal 
marshal.loads = pickle.loads 
marshal.dumps = pickle.dumps # I assume it needs dumps also 

我還沒有試過,所以我完全不知道這是否會工作!另外請注意,pickle加載/轉儲比marshal加載/轉儲要慢。

+0

在我測試App Engine時,我注意到pickle(而不是cPickle)有時比元帥慢了10倍以上。 – gravitation 2009-06-29 23:32:55

6

您可以通過下載和使用Whoosh-Appengine來解決您的問題,這是專門針對Google App Engine工作的Whoosh版本。

+1

我正在使用該版本...它只能在開發環境中工作。 – Martin 2009-06-23 03:42:50

1

見註釋#71在這裏: http://code.google.com/p/googleappengine/issues/detail?id=217&q=Whoosh&colspec=ID%20Type%20Status%20Priority%20Stars%20Owner%20Summary%20Log%20Component#c71

這不是我的工具,但它說:

我已經移植http://whoosh.ca/創建全文搜索API,因此它是AppEngine上avaliable 。 (它存儲索引在數據存儲)

您可以從http://github.com/tallstreet/Whoosh-AppEngine/tree/master

它包括所有Whooshes的功能,包括下載:

1 Python的API。 2分段索引和搜索。 3快速索引和檢索 4可插拔評分算法(包括BM25F),文本分析,存儲,發佈 格式等 5通過pyparsing分析的強大查詢語言。 6純Python拼寫檢查器