We’ve noticed that when using a Field constraint with the Search API, that 
search strings such as:

KW:(war peace) 

are parsed in such a way that the two words are treated as a phrase.  The 
resulting query looks like this:

(cts:search(/book, cts:field-word-query("keywords", "war peace", 
("case-insensitive","diacritic-insensitive","punctuation-insensitive","wildcarded","lang=en"),
 1), ("score-logtfidf",cts:score-order("descending")), 1))[1 to 10]

This is different than how a none-constrained search is treated, where the two 
words are passed to two separate cts:word-query functions, which in turn are 
AND’d together.

(cts:search(/book, cts:and-query((cts:word-query("war", 
("case-insensitive","diacritic-insensitive","punctuation-insensitive","wildcarded","lang=en"),
 1), cts:word-query("peace", 
("case-insensitive","diacritic-insensitive","punctuation-insensitive","wildcarded","lang=en"),
 1)), ()), ("score-logtfidf",cts:score-order("descending")), 1))[1 to 10]

It is also not the same way that non-Field based constraints are handled.  For 
example, we have an element constraint (SE) defined on the element 
“collection-meta” that produces an AND’d query like this

(cts:search(/book, cts:element-query(fn:QName("","collection-meta"), 
cts:and-query((cts:word-query("war", 
("case-insensitive","diacritic-insensitive","punctuation-insensitive","wildcarded","lang=en"),
 1), cts:word-query("peace", 
("case-insensitive","diacritic-insensitive","punctuation-insensitive","wildcarded","lang=en"),
 1)), ()), ()), ("score-logtfidf",cts:score-order("descending")), 1))[1 to 10]

in response to this input SE:(war peace)

What we need is a way to produce the following:

(cts:search(/book, cts:and-query((cts:field-word-query("keywords", "war", 
("case-insensitive","diacritic-insensitive","punctuation-insensitive","wildcarded","lang=en"),
 1), cts:field-word-query("keywords", "peace", 
("case-insensitive","diacritic-insensitive","punctuation-insensitive","wildcarded","lang=en"),
 1)), ()), ("score-logtfidf",cts:score-order("descending")), 1))[1 to 10]

We can do this by passing this string to search:

KW:war AND KW:peace

but that’s not practical from a user perspective.  We’d also like to avoid 
either editing the Search query module code or having to parse out the user 
entered string and tokenize for words and prefix each of these with the 
constraint name.  The first doesn’t seem wise and the second seems too much 
like a hack. 

Question:

Is there a way to override the default behaviour of Field based constraints in 
the Search API (using options) so that words passed to the constraint are 
parsed as individual words and used to construct an AND query in the same way 
non-Field based constraints and unconstrained searches operate?

Thanks for any help.


Alan





_______________________________________________
General mailing list
General@developer.marklogic.com
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to