completer is not a SuggestField

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

completer is not a SuggestField

Hello everyone,

java.lang.IllegalArgumentException: completer is not a SuggestField, is the exception I got when I run a completion query against a suggest field.

At index-time I have a CustomAnalyzer like:

ClasspathResourceLoader resourceLoader = new
Analyzer analyzer = CustomAnalyzer.builder(resourceLoader)
              "ignoreCase", "true")
CompletionAnalyzer completionAnalyzer = new CompletionAnalyzer(analyzer);

Directory directory ="completionIndex"));
IndexWriterConfig writerConfig = new IndexWriterConfig(completionAnalyzer);
IndexWriter indexWriter = new IndexWriter(directory, writerConfig);

Then I walk along a file tree to index the suggester field like:

Files.walkFileTree(Paths.get("docs"), new SimpleFileVisitor<Path>() {
  public FileVisitResult visitFile(Path ofEachFile, BasicFileAttributes attr)
          throws IOException {

    Document doc = new Document();
    SuggestField suggestField;

    List<String> fileLines = Files.readAllLines(ofEachFile);

    List<String> contentLines = fileLines.subList(6, fileLines.size());

    StringBuilder sb = new StringBuilder();
    for(int i = 0; i < contentLines.size(); i++) {
    String content = sb.toString();

    suggestField = new SuggestField("completer", content, 4);




    return FileVisitResult.CONTINUE;



At search time, I got the same CustomAnalyzer as above and then:

// CustomAnalyzer...

Directory indexDirectory ="completionIndex"));
IndexReader indexReader =;
// IndexSearcher indexSearcher = new IndexSearcher(indexReader);
SuggestIndexSearcher suggestSearcher = new SuggestIndexSearcher(indexReader);

//Term term = new Term("completer", "blatavts");
CompletionQuery query = new PrefixCompletionQuery(completionAnalyzer,
  new Term("completer", "blavats"));
TopSuggestDocs suggestDocs = sis.suggest(query, 4, false);

int docID;
Document doc;
for(ScoreDoc sd : suggestDocs.scoreDocs) {
  docID = sd.doc;
  doc = sis.doc(docID);

And got the exception.