package com.ifactory.press.db.solr.spelling.suggest;

import java.io.IOException;
import java.util.Comparator;
import java.util.Set;

import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.search.suggest.InputIterator;
import org.apache.lucene.search.suggest.analyzing.AnalyzingInfixSuggester;
import org.apache.lucene.store.Directory;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Version;

public class SafeInfixSuggester extends AnalyzingInfixSuggester {

    public SafeInfixSuggester(Version matchVersion, Directory dir, Analyzer indexAnalyzer, Analyzer queryAnalyzer, int minPrefixChars) throws IOException {
        super(matchVersion, dir, indexAnalyzer, queryAnalyzer, minPrefixChars);
        
        if (!DirectoryReader.indexExists(dir)) {
            // no index in place -- build an empty one so we are prepared for updates

            build (new InputIterator() {

                @Override
                public BytesRef next() throws IOException {
                    return null;
                }

                @Override
                public Comparator<BytesRef> getComparator() {
                    return null;
                }

                @Override
                public long weight() {
                    return 0;
                }

                @Override
                public BytesRef payload() {
                    return null;
                }

                @Override
                public boolean hasPayloads() {
                    return false;
                }

                @Override
                public Set<BytesRef> contexts() {
                    return null;
                }

                @Override
                public boolean hasContexts() {
                    return false;
                }
                
            });
        }
    }

    /*
     * TODO: control highlighting here
    @Override
    public List<LookupResult> lookup(CharSequence key, Set<BytesRef> contexts, boolean onlyMorePopular, int num) throws IOException {
      return lookup(key, contexts, num, true, false);
    }
    */

}

@@ -100,24 +100,47 @@
 Comparator;%0A
+import java.util.List;%0A
 import java.
@@ -1945,21 +1945,15 @@
   * 
-TODO: control
+disable
  hig
@@ -1965,13 +1965,16 @@
 ting
- here
+%0A     */
 %0A   
@@ -2181,15 +2181,8 @@
    %7D
-%0A    */
 %0A%0A%7D%0A

disable match highlighting in suggestions (we strip and re-apply in JS)