/* | |
* Licensed to the Apache Software Foundation (ASF) under one or more | |
* contributor license agreements. See the NOTICE file distributed with | |
* this work for additional information regarding copyright ownership. | |
* The ASF licenses this file to You under the Apache License, Version 2.0 | |
* (the "License"); you may not use this file except in compliance with | |
* the License. You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 | |
* | |
* Unless required by applicable law or agreed to in writing, software | |
* distributed under the License is distributed on an "AS IS" BASIS, | |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
* See the License for the specific language governing permissions and | |
* limitations under the License. | |
*/ | |
package opennlp.tools.similarity.apps.solr; | |
import java.io.IOException; | |
import java.util.ArrayList; | |
import java.util.Collections; | |
import java.util.Comparator; | |
import java.util.HashMap; | |
import java.util.HashSet; | |
import java.util.Iterator; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.Map; | |
import java.util.Set; | |
import opennlp.tools.similarity.apps.HitBaseComparable; | |
import opennlp.tools.similarity.apps.utils.Pair; | |
import opennlp.tools.textsimilarity.ParseTreeChunkListScorer; | |
import opennlp.tools.textsimilarity.SentencePairMatchResult; | |
import opennlp.tools.textsimilarity.chunker2matcher.ParserChunker2MatcherProcessor; | |
import org.apache.commons.lang.ArrayUtils; | |
import org.apache.commons.lang.StringUtils; | |
import org.apache.lucene.document.Document; | |
import org.apache.lucene.index.CorruptIndexException; | |
import org.apache.lucene.index.IndexReader; | |
import org.apache.lucene.queryparser.classic.ParseException; | |
import org.apache.lucene.search.BooleanClause.Occur; | |
import org.apache.lucene.search.BooleanQuery; | |
import org.apache.lucene.search.CachingWrapperFilter; | |
import org.apache.lucene.search.Collector; | |
import org.apache.lucene.search.Filter; | |
import org.apache.lucene.search.Query; | |
import org.apache.lucene.search.QueryWrapperFilter; | |
import org.apache.lucene.search.ScoreDoc; | |
import org.apache.solr.common.SolrDocument; | |
import org.apache.solr.common.SolrDocumentList; | |
import org.apache.solr.common.SolrException; | |
import org.apache.solr.common.params.CommonParams; | |
import org.apache.solr.common.params.ModifiableSolrParams; | |
import org.apache.solr.common.params.ShardParams; | |
import org.apache.solr.common.params.SolrParams; | |
import org.apache.solr.common.util.NamedList; | |
import org.apache.solr.handler.RequestHandlerBase; | |
import org.apache.solr.handler.component.ResponseBuilder; | |
import org.apache.solr.handler.component.SearchComponent; | |
import org.apache.solr.handler.component.SearchHandler; | |
import org.apache.solr.handler.component.ShardHandler; | |
import org.apache.solr.handler.component.ShardRequest; | |
import org.apache.solr.handler.component.ShardResponse; | |
import org.apache.solr.request.SolrQueryRequest; | |
import org.apache.solr.response.ResultContext; | |
import org.apache.solr.response.SolrQueryResponse; | |
import org.apache.solr.schema.SchemaField; | |
import org.apache.solr.search.DocIterator; | |
import org.apache.solr.search.DocList; | |
import org.apache.solr.search.DocSlice; | |
import org.apache.solr.search.QParser; | |
import org.apache.solr.search.SolrIndexSearcher; | |
import org.apache.solr.util.RTimer; | |
import org.apache.solr.util.SolrPluginUtils; | |
public class QueryExpansionRequestHandler extends SearchHandler { | |
public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp){ | |
try { | |
//System.out.println("request before ="+req); | |
SolrQueryRequest req1 = substituteField(req); | |
//System.out.println("request after ="+req1); | |
super.handleRequestBody(req1, rsp); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
public static SolrQueryRequest substituteField(SolrQueryRequest req){ | |
SolrParams params = req.getParams(); | |
String query = params.get("q"); | |
System.out.println("query before ="+query); | |
query = query.replace(' ', '_'); | |
System.out.println("query after ="+query); | |
NamedList values = params.toNamedList(); | |
values.remove("q"); | |
values.add("q", query); | |
params = SolrParams.toSolrParams(values); | |
req.setParams(params); | |
return req; | |
} | |
} |