搜索我有在名單列表中搜索字符串的函數,然後返回一個包含匹配列表清單:Python的高級字符串與運營商和布爾
def foo(myList,keyword,first=True):
if first: #Search only first element or each sublist
return [x for x in myList if keyword in x]
else: #Search first and second elements of each sublist
return [x for x in myList if keyword in x or keyword in x[1]]
現在我想擴展它來處理高級搜索與像查詢:
matchthis -butnothis -"and not this"
this|orthis|"or this"
brand new*laptop # this is a wildcard, matches like: brand new dell laptop
"exact phrase"
是否有任何Python模塊(最好是內置的),我可以在我的函數用來處理這些查詢?
PS:我知道旋風,但它不是正確的適合我的那一刻。另外,我目前正在使用App Engine。
我想要做的基本上是在內存中進行全文搜索,因爲應用引擎不支持全文搜索。我查詢數據存儲,將這些實體放入列表中並遍歷這些列表以查找查詢匹配。
這看起來很有前途,讓我試試看吧。 – ofko 2011-12-30 02:07:18
這是完美!謝謝。 – ofko 2011-12-30 03:20:36