In [5]:
# coding: utf-8

import os

from cheshire3.baseObjects import Session
from cheshire3.document import StringDocument
from cheshire3.internal import cheshire3Root
from cheshire3.server import SimpleServer   

session = Session()
session.database = 'db_dickens'
serv = SimpleServer(session, os.path.join(cheshire3Root, 'configs', 'serverConfig.xml'))
db = serv.get_object(session, session.database)
qf = db.get_object(session, 'defaultQueryFactory')
resultSetStore = db.get_object(session, 'resultSetStore')
idxStore = db.get_object(session, 'indexStore')

In [6]:
def count_total(result_set):
    """
    Helper function to count the total number of hits
    in the search results
    """
    count = 0 
    for result in result_set:
        count += len(result.proxInfo)
    return count

def try_query(query):
    """
    Another helper function to take a query and return
    the total number of hits
    """
    query = qf.get_query(session, query)
    result_set = db.search(session, query)
    return count_total(result_set)
  1. What is a book index?
  2. What can we do with it?
  3. What is stored in it?

In [7]:
try_query('c3.book-idx = "BH"')


Out[7]:
0

In [ ]: