<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Basic setup
Step4:  The problems
When using the any search function to search for two different terms, the results are wrong.
Problem 1
Step6:  Solving problem 1
This query gets wrong results because it the OR query is poorly constructed
Step8:  Properly structuring the OR clause takes away the problem of having different results for
for OR dense
dense OR fog
Option 1
Step11:  Option 2
Step13:  Option 3
Step15:  Solving problem 2
To really get the right results, though, one should not just use
any, but rather any/cql.proxinfo.
Step17:  Or in its simpler form
Step19:  This does not seem to be affected by whether you mention cql or not (that is a cql specification, if I am not wrong).
Step22:  The counts are now correct
<ASSISTANT_TASK:>
Python Code:
# 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')
Explanation: Basic setup
End of explanation
# This is the query that is currently being used.
# The count is the number of chapters
query = qf.get_query(session,               
                     ((c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx = "fog") or c3.chapter-idx = "dense")
                     )
result_set = db.search(session, query)
print len(result_set)
# To get a  more speficic count one also needs to include the numbers of hits 
# in the different chapters
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
count_total(result_set)
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)
Explanation: The problems
When using the any search function to search for two different terms, the results are wrong.
Problem 1: searching for fog OR dense is not the same as dense OR fog.
Problem 2: Second, the counts for fog OR dense are off. 
Currently, there are 150 results for fog OR dense and 221 for dense OR fog, but there should be many more (142 or 144 if one counts compound nouns).
End of explanation
try_query(
           ((c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx = "dense") or c3.chapter-idx = "fog")
           
           )
Explanation: Solving problem 1
This query gets wrong results because it the OR query is poorly constructed
End of explanation
try_query(
           (c3.subcorpus-idx all "dickens" and/cql.proxinfo (c3.chapter-idx = "dense" or c3.chapter-idx = "fog"))
           
           )
Explanation: Properly structuring the OR clause takes away the problem of having different results for
for OR dense
dense OR fog
Option 1
End of explanation
try_query(
           (c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx any "dense fog")
           
           )
try_query(
           (c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx any "fog dense")
           
           )
Explanation: Option 2
End of explanation
try_query(
           ((c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx = "dense") or 
           (c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx = "fog"))
           
           )
Explanation: Option 3: the verbose one
End of explanation
try_query(
           (c3.subcorpus-idx all "dickens" and/proxinfo (c3.chapter-idx = "dense" or/proxinfo c3.chapter-idx = "fog"))
           
           )
Explanation: Solving problem 2
To really get the right results, though, one should not just use
any, but rather any/cql.proxinfo.
End of explanation
try_query(
           (c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx any/proxinfo "fog dense")
           
           )
Explanation: Or in its simpler form:
End of explanation
try_query(
           (c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx any/cql.proxinfo "fog dense")
           
           )
Explanation: This does not seem to be affected by whether you mention cql or not (that is a cql specification, if I am not wrong).
End of explanation
dense = try_query((c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx = "dense"))
print dense
fog = try_query((c3.subcorpus-idx all "dickens" and/cql.proxinfo c3.chapter-idx = "fog"))
print fog
dense + fog
Explanation: The counts are now correct:
End of explanation
<END_TASK>