Might be able to do it with some combination of SpanNearQuery, with suitable values for slop and inOrder, combined into a BooleanQuery with setMinimumNumberShouldMatch = number of SpanNearQuery instances - 1.
So, making this up as I go along, you'd have SpanNearQuery sn1 = B after A, slop 0, in order SpanNearQuery sn2 = C after B, slop 0, in order SpanNearQuery sn3 = D after C, slop 0, in order SpanNearQuery sn4 = E after D, slop 0, in order BooleanQuery bq = whatever(sn1, sn2, sn3, sn4) bq.setMinimumNumberShouldMatch(3) Might work. The value 3 should perhaps be 2. Or a larger value of slop might help to match C X E rather than C D E. In that case minshouldmatch would be 4, I think, I'm getting confused so will stop. -- Ian. On Thu, Jul 17, 2014 at 8:22 AM, Yonghui Zhao <zhaoyong...@gmail.com> wrote: > Hi, > > I want to implement a query like phrase query with slop 0, but I can allow > one term mismatch. > > For example, the text is "A B C D E" > > I want to match this text with the query "A B C X E". > > X mismatches the D. > > i.e. Query "A B C D E" will match “W1 W2 W3 W4 W5”, the 5 words are > consecutive and at most one word is mismatched. --------------------------------------------------------------------- To unsubscribe, e-mail: java-user-unsubscr...@lucene.apache.org For additional commands, e-mail: java-user-h...@lucene.apache.org