~slub.team/goobi-indexserver/3.x

« back to all changes in this revision

Viewing changes to solr/core/src/test/org/apache/solr/handler/component/DummyCustomParamSpellChecker.java

  • Committer: Sebastian Meyer
  • Date: 2012-08-03 09:12:40 UTC
  • Revision ID: sebastian.meyer@slub-dresden.de-20120803091240-x6861b0vabq1xror
Remove Lucene and Solr source code and add patches instead
Fix Bug #985487: Auto-suggestion for the search interface

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package org.apache.solr.handler.component;
2
 
 
3
 
import org.apache.lucene.analysis.Token;
4
 
import org.apache.lucene.index.IndexReader;
5
 
import org.apache.solr.core.SolrCore;
6
 
import org.apache.solr.search.SolrIndexSearcher;
7
 
import org.apache.solr.spelling.SolrSpellChecker;
8
 
import org.apache.solr.spelling.SpellingOptions;
9
 
import org.apache.solr.spelling.SpellingResult;
10
 
 
11
 
import java.io.IOException;
12
 
import java.util.Collection;
13
 
import java.util.Collections;
14
 
import java.util.Iterator;
15
 
/**
16
 
 * Licensed to the Apache Software Foundation (ASF) under one or more
17
 
 * contributor license agreements.  See the NOTICE file distributed with
18
 
 * this work for additional information regarding copyright ownership.
19
 
 * The ASF licenses this file to You under the Apache License, Version 2.0
20
 
 * (the "License"); you may not use this file except in compliance with
21
 
 * the License.  You may obtain a copy of the License at
22
 
 *
23
 
 *     http://www.apache.org/licenses/LICENSE-2.0
24
 
 *
25
 
 * Unless required by applicable law or agreed to in writing, software
26
 
 * distributed under the License is distributed on an "AS IS" BASIS,
27
 
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
28
 
 * See the License for the specific language governing permissions and
29
 
 * limitations under the License.
30
 
 */
31
 
 
32
 
 
33
 
/**
34
 
 * A Dummy SpellChecker for testing purposes
35
 
 *
36
 
 **/
37
 
public class DummyCustomParamSpellChecker extends SolrSpellChecker {
38
 
 
39
 
  @Override
40
 
  public void reload(SolrCore core, SolrIndexSearcher searcher) throws IOException {
41
 
 
42
 
  }
43
 
 
44
 
  @Override
45
 
  public void build(SolrCore core, SolrIndexSearcher searcher) {
46
 
 
47
 
  }
48
 
 
49
 
  @Override
50
 
  public SpellingResult getSuggestions(Collection<Token> tokens, IndexReader reader, int count, boolean onlyMorePopular, boolean extendedResults) throws IOException {
51
 
    return getSuggestions(new SpellingOptions(tokens, reader, count, onlyMorePopular, extendedResults, 0, null));
52
 
  }
53
 
 
54
 
  @Override
55
 
  public SpellingResult getSuggestions(SpellingOptions options) throws IOException {
56
 
 
57
 
    SpellingResult result = new SpellingResult();
58
 
    //just spit back out the results
59
 
    Iterator<String> iterator = options.customParams.getParameterNamesIterator();
60
 
    int i = 0;
61
 
    while (iterator.hasNext()){
62
 
      String name = iterator.next();
63
 
      String value = options.customParams.get(name);
64
 
      result.add(new Token(name, i++, i++),  Collections.singletonList(value));
65
 
    }    
66
 
    return result;
67
 
  }
68
 
}