cleo
cleo copied to clipboard
Word repetition issue
PrefixSelector doesnt properly works with word repetition. I.e. you can type same word(or even short prfix) several times and get same suggestion.
You can use something like this to solve the problem: (scala code)
class MySelector(terms: Array[String]) extends PrefixSelector[MyElement](terms: _*) {
val storage = new Array[Boolean](20)
def startWith(child: Array[String], parent: Array[String]):Boolean = {
val pi = parent.toIterator.zipWithIndex
for (i <- 0 until parent.size) storage(i) = false
child.forall {
cw => pi.exists {
case (w, i) => if (w.startsWith(cw) && !storage(i)) {
storage(i) = true;
true
} else false
}
}
}
override def select(element: MyElement, ctx: SelectorContext): Boolean = {
val select = startWith(terms,element.getTerms)
select
}
}
}