Skip to content

Word repetition issue #9

Description

@yurkor

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
      }
    }
  }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions