Is It Possible To Find Term NOT Near Other Term?

Viewed 43

I was expecting to be able to write a common search query that looks for one word but only when it is not near another word. In typical search grammar, it might look like this:

Christmas NOT WITHIN/3 father

In this case, I want to find "Christmas" but not when it is very close to the word "father".

I thought MarkLogic could do this, but I am not finding any examples of that ability.

Does anybody know if it IS supported somehow, and if not is there a way to "hack it" easily?

I support I could just do a preliminary search for "Christmas", and count the number of hits. then do a search for "Christmas" NEAR "father", and count those too, then ignore a document when the counts are the same - but I prefer not to take this long-winded approach if I can avoid it.

Thanks.

1 Answers

UPDATE: See "PROTOTYPE" below. A few notes are about assumptions and speculation, so I have updated with a re-useable sample to test query strings against phrases.

UPDATE updated query to be a not in query

You do not state how you are searching. However, the way you wrote the query, I am assuming using an interface to the search library and use of String Queries

xquery version "1.0-ml";


let $phrases := (
  "This has Christmas and Christmas and over here it has Father. However, Father is too far away from Christmas for us to care",
  "Christmas is all alone here",
  "Sometimes there is a sentance in which Father and Christmas are too close  -but no reference to those words elsewhere",
  "Sometimes there is a sentance in which Christmas and Father are too close(and reversed)  -but no reference to those words elsewhere",
  "Sometimes Father Christmas are too close and Christmas is also referenced on its own"
)

let $string-query := 'Christmas NOT_IN (Christmas NEAR/2[unordered] Father)'

let $query := cts:parse($string-query)

return for $phrase in $phrases
  let $match := if(cts:contains($phrase, $query)) then "MATCH :: " else "NO MATCH :: "
  return $match || $phrase

Result:

MATCH :: This has Christmas and Christmas and over here it has Father. However, Father is too far away from Christmas for us to care

MATCH :: Christmas is all alone here

NO MATCH :: Sometimes there is a sentance in which Father and Christmas are too close  -but no reference to those words elsewhere

NO MATCH :: Sometimes there is a sentance in which Christmas and Father are too close(and reversed)  -but no reference to those words elsewhere

MATCH :: Sometimes Father Christmas are too close and Christmas is also referenced on its own
Related