write_message("......... unchanged hitlist for ``%s''"% \
word,verbose=9)
else:
# yes there were some new words:
write_message("......... updating hitlist for ``%s''"% \
word,verbose=9)
run_sql("UPDATE %s SET hitlist=%%s WHERE term=%%s"%wash_table_column_name(self.table_name),(set.fastdump(),word))# kwalitee: disable=sql
else:# the word is new, will create new set:
write_message("......... inserting hitlist for ``%s''"% \
word,verbose=9)
set=intbitset(self.value[word].keys())
try:
run_sql("INSERT INTO %s (term, hitlist) VALUES (%%s, %%s)"%wash_table_column_name(self.table_name),(word,set.fastdump()))# kwalitee: disable=sql
exceptException,e:
## We send this exception to the admin only when is not
## already reparing the problem.
register_exception(prefix="Error when putting the term '%s' into db (hitlist=%s): %s\n"%(repr(word),set,e),alert_admin=(task_get_option('cmd')!='repair'))
ifnotset:# never store empty words
run_sql("DELETE FROM %s WHERE term=%%s"%wash_table_column_name(self.table_name),(word,))# kwalitee: disable=sql
defput(self,recID,word,sign):
"""Keeps track of changes done during indexing
and stores these changes in memory for further use.
Indexing process needs this information later while
filling in the database.
@param recID: recID of the record we want to update in memory
@param word: word we want to update
@param sing: sign of the word, 1 means keep this word in database,
-1 remove word from database
"""
value=self.value
try:
ifself.wash_index_terms:
word=wash_index_term(word,self.wash_index_terms)
ifwordinvalue:
# the word 'word' exist already: update sign
value[word][recID]=sign
else:
value[word]={recID:sign}
exceptExceptionase:
write_message("Error: Cannot put word %s with sign %d for recID %s."% \
(word,sign,recID))
defload_old_recIDs(self,word):
"""Load existing hitlist for the word from the database index files."""
query="SELECT hitlist FROM %s WHERE term=%%s"%self.table_name
res=run_sql(query,(word,))
ifres:
returnintbitset(res[0][0])
else:
returnNone
defmerge_with_old_recIDs(self,word,set):
"""Merge the system numbers stored in memory
(hash of recIDs with value +1 or -1 according
to whether to add/delete them) with those stored
in the database index and received in set universe
of recIDs for the given word.
Return False in case no change was done to SET, return True in case SET
was changed.
"""
oldset=intbitset(set)
set.update_with_signs(self.value[word])
returnset!=oldset
defclean(self):
"Cleans the cache."
self.value={}
classVirtualIndexTable(AbstractIndexTable):
"""
There are two types of indexes: virtual and regular/normal.
Check WordTable class for more on normal indexes.
This class represents a single index table for virtual index
(see also: AbstractIndexTable).
Virtual index doesn't store its own terms,
it accumulates terms from other indexes.
Good example of virtual index is the global index which stores
terms from title, abstract, keyword, author and so on.
This class contains methods for indexing virtual indexes.