Exemple #1
0
#encoding:utf-8
#author: troycheng
#email: [email protected]

import xapian
import sys
import json
import time
import threading
from mmseg.search import seg_txt_2_dict
from globaldef import config, ilog, MSG_QUEUE

# get the xapian config
MASTER_DB_PATH = config.getXapian("master_db")
try:
    MASTER_DB = xapian.WritableDatabase(MASTER_DB_PATH, xapian.DB_CREATE_OR_OPEN)
except Exception,e:
    ilog.critical("Open xapian master db failed. [exception]: %s" % e)
    sys.exit(1)

# get the query interval for MSG_QUEUE
COMMIT_INTERVAL = int(config.getXapian("commit_interval"))

# define index function
# msg should be json format:
# {
#   "title": title, user name, label name etc.
#   "type": item tyoe
#   "id": item id
#   "icon"(optional): icon id, if exists, or do not set it
# }
Exemple #2
0
# authot: troycheng
# email: [email protected]

import xapian
import mmseg
import json
import threading
import time
from mmseg.search import seg_title_search
from collections import defaultdict
from globaldef import slog, config
from gevent import wsgi, pool
from cgi import parse_qs, escape

# get the configuration
DB_PATH = config.getXapian("master_db")
QUERY_PAGESIZE = config.getXapian("query_pagesize")

# define search db 
SEARCH_DB = xapian.Database(DB_PATH)
SEARCH_ENQUIRE = xapian.Enquire(SEARCH_DB)

# refresh db 
def refreshDB(interval):
    while True:
        SEARCH_DB.reopen()
        slog.info("Refresh DB.")
        time.sleep(interval)

# define search function
def search(querystring, offset=0, pagesize=QUERY_PAGESIZE, enquire=SEARCH_ENQUIRE):