You have to set bq.setMaxClauseCount value as the default number of
clauses BooleanQuery supports is 1024.
I am guessing you have categoryIDs between 1-30000 which means more than
1024 clauses.
-Hemant
setMaxClauseCount
Ashley Rajaratnam wrote:
Hi,
Please forgive me if this comes across as being naïve however Ive bashed my
head against it for a while and can’t come up with a solution.
Overview:
I have the following basic document structure:
…
Document doc = new Document();
doc.Add(Field.Text("itemtitle", iteminf.itemtitle));
doc.Add(Field.Text("itemSubTitle", iteminf.itemSubTitle));
doc.Add(Field.Keyword("CategoryID", iteminf.CategoryID)); -- THIS ID (1
-30000) is passed in here as a string
writer.AddDocument(doc);
…
What I would like to do is search the title and subtitle fields with what a
user types in so I build up a search query string
Qstr = (query + “ “);
Qstr += (“itemtitle:” + “(“ + query + “)” + “ “);
Qstr += (“itemSubTitle:” + “(“ + query + “)” + “ “);
Pass it to QueryParse get the Query
Query q = QueryParser.Parse(sbquerys.ToString(), SEARCH_KEY_ITEMDESC, new
StandardAnalyzer());
Execute the query searcher.Search(query); No Problem get the results etc.
Now the problem what I would like to do is restricted the results coming
back to only certain CategoryIDs so I changed my Qstr dynamically such like
string[] leafcats =
GET_ARRAY_OF_RELEVANT_CATIDS_AS_STRING_ARRAY();
sbquerys += “CategoryID:” + “(“;
for(int i=0; i< leafcats.Length; i++)
{
sbquerys += leafcats[i]+ “ “;
}
sbquerys += “)”;
Qstr += sbquerys
Pass it to QueryParse get the Query
Query q = QueryParser.Parse(Qstr SEARCH_KEY_ITEMDESC, new
StandardAnalyzer());
Now not surprisingly the Parse Function calls takes upward of about 10
seconds (or throws a toomanybool clauses exception) I think this is due to
the fact that Im passing it with so many CategoryID (between 1 -30000)
So I tried building up the Query using the API
BooleanQuery bq = new BooleanQuery();
Term t = new Term(“itemdesc”, query); <<<
Doesn’t work because query is something user has typed in and thus doesn’t
match properly
bq.Add(new TermQuery(t), false, false);
t = new Term(“itemSubTitle”, query);
bq.Add(new TermQuery(t), false, false);
t = new Term(“itemtitle”, query);
bq.Add(new TermQuery(t), false, false);
if (categoryid != null)
{
string[] leafcats =
(string[])leafcategoryids.ToArray(typeof(string));
t = new Term(SEARCH_KEY_CATEGORYID,
string.Join(" OR ",leafcats)); <<<< OR DOESN’T WORK
bq.Add(new TermQuery(t), true, false);
<< NOTE TRUE
}
But this doesn’t seem to execute the OR clause in the new Term value which
is not surprising because it’s a TermQuery which is supposed to be 1 value.
So now Im a bit lost as to where to take this perhaps QueryFilter would do
the trick but Im lost on the syntax and just don’t feel that is the right
approach.
Anyhow any help you can provide would be greatly appreciate
-A
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]