Reds เป็น Redis ที่มีน้ำหนักเบาค้นหา Node.js
Pyreds เป็นพอร์ต Python of Reds
Pyreds ต้องการเซิร์ฟเวอร์ Redis ที่กำลังทำงานอยู่ ดู QuickStart ของ Redis สำหรับคำแนะนำในการติดตั้ง
ในการติดตั้ง pyreds เพียง:
$ pip install pyredsคุณอาจต้องติดตั้งข้อมูล NLTK:
>>> import nltk
>>> nltk.download( ' stopwords ' )สิ่งแรกที่คุณต้องทำคือสร้างอินสแตนซ์การค้นหาซึ่งอนุญาตให้คุณผ่านคีย์ใช้สำหรับการกำหนดเวลาภายใน Redis เพื่อให้คุณมีการค้นหาหลายครั้งในฐานข้อมูลเดียวกัน
>>> import pyreds
>>> search = pyreds.create_search( ' pets ' )Pyreds ทำหน้าที่ต่อต้าน ID ที่เป็นตัวเลขหรือสตริงโดยพลการดังนั้นคุณสามารถใช้ห้องสมุดนี้กับสิ่งที่คุณต้องการเป็นหลักแม้แต่การรวมร้านค้าข้อมูล ตัวอย่างต่อไปนี้เพียงแค่ใช้รายการสำหรับ "ฐานข้อมูล" ของเราซึ่งมีสตริงบางอย่างซึ่งเราเพิ่มลงใน pyreds โดยการเรียกค้นหา#index () padding body of text และ id บางชนิดในกรณีนี้ดัชนี
>>> strs = []
>>> strs.append( ' Tobi wants four dollars ' )
>>> strs.append( ' Tobi only wants $4 ' )
>>> strs.append( ' Loki is really fat ' )
>>> strs.append( ' Loki, Jane, and Tobi are ferrets ' )
>>> strs.append( ' Manny is a cat ' )
>>> strs.append( ' Luna is a cat ' )
>>> strs.append( ' Mustachio is a cat ' )
>>> for i, v in enumerate (strs):
... search.index(v, i)ในการดำเนินการค้นหากับ pyreds เพียงเรียกใช้การค้นหา#query () ด้วยสตริงซึ่งส่งคืนอินสแตนซ์แบบสอบถาม จากนั้นเรียกใช้ Query#end () ซึ่งส่งคืนรายการรหัสเมื่อมีอยู่หรือรายการว่างเป็นอย่างอื่น
>>> ids = search.query( ' Tobi dollars ' ).end()
>>> print ( ' Search results for "Tobi dollars" ' ))
>>> for id in ids:
... print ( ' - {} ' .format(strs[ id ]))โดยค่าเริ่มต้น Pyreds จะทำการแยกคำค้นหา ตัวอย่างก่อนหน้านี้จะให้ผลลัพธ์ต่อไปนี้เนื่องจากมีเพียงหนึ่งสตริงเดียวที่มีทั้ง "Tobi" และ "ดอลลาร์":
Search results for "Tobi dollars":
- Tobi wants four dollarsเราสามารถปรับแต่ง pyreds เพื่อดำเนินการสหภาพโดยผ่าน "Union" หรือ "หรือ" เพื่อค้นหา#type () ระหว่างการค้นหา#query () และ Query#end () ซึ่งบ่งชี้ว่าค่าคงที่ใด ๆ ที่คำนวณอาจมีอยู่สำหรับ ID ให้ตรงกัน
>>> ids = search.query( ' tobi dollars ' ).type( ' or ' ).end()
>>> print ( ' Search results for "Tobi dollars" ' ))
>>> for id in ids:
... print ( ' - {} ' .format(strs[ id ]))การค้นหายูเนี่ยนจะให้ผลต่อไปนี้เนื่องจากสามสายมีทั้ง "โทบี" หรือ "ดอลลาร์":
Search results for "tobi dollars":
- Tobi wants four dollars
- Tobi only wants $4
- Loki, Jane, and Tobi are ferrets>>> search = pyreds.create_search(key)
>>> search.index(text, id )
>>> search.remove( id )
>>> query = search.query(text[, type ]) # will return a `Query` instance
>>>
>>> query.between(start, stop)
>>> query.type( type )
>>> query.end()ใบอนุญาต MIT