3 from whoosh
import store
4 from whoosh
.fields
import Schema
, TEXT
, ID
5 from whoosh
.index
import Index
6 from whoosh
.qparser
import QueryParser
8 from shutil
import rmtree
10 from django
.conf
import settings
12 os
.environ
['DJANGO_SETTINGS_MODULE'] = 'ebuilds.settings'
14 INDEX_BASE
= settings
.ROOT_PATH
+ "ebuilds" + "/ebuildfind/commands/var/index"
16 class WhooshEbuildManager
:
17 def __init__(self
, reset
=False):
19 if os
.path
.exists(INDEX_BASE
):
22 storage
= store
.FileStorage(INDEX_BASE
)
24 storage
= store
.FileStorage(INDEX_BASE
)
25 storage
= store
.copy_to_ram(storage
)
27 schema
= Schema(permalink
=ID(stored
=True),
28 content
=TEXT(phrase
=False))
30 self
.index
= Index(storage
, schema
=schema
, create
=reset
)
31 self
.searcher
= self
.index
.searcher()
32 self
.parser
= QueryParser("content", schema
= self
.index
.schema
)
34 def Update(self
, ebuild
):
35 writer
= self
.index
.writer()
38 return text
.lower
.replace("-", " ")
40 content_raw
= [ebuild
.overlay
.name
, ebuild
.category
, ebuild
.name
, ebuild
.description
]
44 e
= e
.lower().replace("-", " ")
47 content
.append(ebuild
.version
)
49 content
= ' '.join(content
)
51 writer
.add_document(permalink
=unicode(ebuild
.id),
53 print ">", ebuild
.overlay
.name
, ">>> ", ebuild
.name
56 def Search(self
, query
):
57 return self
.searcher
.search(self
.parser
.parse(query
), sortedby
= "permalink")