List of usage examples for org.apache.solr.common.params CommonParams DF
String DF
To view the source code for org.apache.solr.common.params CommonParams DF.
Click Source Link
From source file:at.newmedialab.lmf.util.solr.suggestion.service.SuggestionService.java
License:Apache License
private SolrQueryResponse query(String query, String df, String[] fields, String[] fqs) { SolrQueryResponse rsp = new SolrQueryResponse(); //append *//from www . jav a 2 s .c om if (!query.endsWith("*")) { query = query.trim() + "*"; } //Prepare query ModifiableSolrParams params = new ModifiableSolrParams(); SolrQueryRequest req = new LocalSolrQueryRequest(solrCore, params); params.add(CommonParams.Q, query.toLowerCase()); params.add(CommonParams.DF, df); params.add("q.op", "AND"); params.add(FacetParams.FACET, "true"); params.add(FacetParams.FACET_LIMIT, internalFacetLimit); params.add(FacetParams.FACET_MINCOUNT, "1"); for (String field : fields) { params.add(FacetParams.FACET_FIELD, field); } if (fqs != null) { for (String fq : fqs) { params.add(CommonParams.FQ, fq); } } if (spellcheck_enabled) { params.add("spellcheck", "true"); params.add("spellcheck.collate", "true"); } try { //execute query and return searchHandler.handleRequestBody(req, rsp); return rsp; } catch (SolrException se) { throw se; } catch (Exception e) { e.printStackTrace(); throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "internal server error"); } finally { req.close(); } }
From source file:com.browseengine.bobo.servlet.BrowseServlet.java
License:Open Source License
@Override protected void service(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { SolrParams params = new BoboHttpRequestParam(req); String qstring = params.get(CommonParams.Q); String df = params.get(CommonParams.DF); String sortString = params.get(CommonParams.SORT); BoboDefaultQueryBuilder qbuilder = new BoboDefaultQueryBuilder(); Query query = qbuilder.parseQuery(qstring, df); Sort sort = qbuilder.parseSort(sortString); BrowseRequest br = null;//from w ww .jav a 2 s . c o m try { br = BoboRequestBuilder.buildRequest(params, query, sort); BrowseResult result = _svc.browse(br); res.setCharacterEncoding("UTF-8"); Writer writer = res.getWriter(); try { String val = BrowseJSONSerializer.serialize(result); writer.write(val); } catch (JSONException je) { throw new IOException(je.getMessage()); } } catch (BrowseException e) { throw new ServletException(e.getMessage(), e); } }
From source file:com.memonews.solr.search.HighlightQParserPlugin.java
License:Apache License
@Override public Query parse() throws ParseException { String qstr = getString();//from w w w . j a va 2 s . c o m if (qstr == null) { return null; } String defaultField = getParam(CommonParams.DF); if (defaultField == null) { defaultField = getReq().getSchema().getDefaultSearchFieldName(); } HighlightQueryParserNew parser = new HighlightQueryParserNew(this, defaultField, this.fieldNames); parser.setDefaultOperator( QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(), getParam(QueryParsing.OP))); Query q = parser.parse(qstr); return q; }
From source file:com.sindicetech.siren.solr.qparser.SirenQParser.java
License:Open Source License
/** * Uses {@link SolrPluginUtils#parseFieldBoosts(String)} with the 'qf' * parameter. Falls back to the 'df' parameter or * {@link org.apache.solr.schema.IndexSchema#getDefaultSearchFieldName()}. *//*from w w w . j av a2s . c o m*/ public static Map<String, Float> parseQueryFields(final IndexSchema indexSchema, final SolrParams solrParams) throws SyntaxError { final Map<String, Float> queryFields = SolrPluginUtils .parseFieldBoosts(solrParams.getParams(SirenParams.QF)); if (queryFields.isEmpty()) { final String df = QueryParsing.getDefaultField(indexSchema, solrParams.get(CommonParams.DF)); if (df == null) { throw new SyntaxError("Neither " + SirenParams.QF + ", " + CommonParams.DF + ", nor the default search field are present."); } queryFields.put(df, 1.0f); } checkFieldTypes(indexSchema, queryFields); return queryFields; }
From source file:elhuyar.bilakit.PayloadQParserPlugin.java
License:Open Source License
@Override public Query parse() throws SyntaxError { String qstr = getString();/* w w w . j a v a2 s. c o m*/ if (qstr == null || qstr.length() == 0) return null; String defaultField = getParam(CommonParams.DF); if (defaultField == null) { defaultField = getReq().getSchema().getDefaultSearchFieldName(); } pqParser = new PayloadQueryParser(this, defaultField); pqParser.setDefaultOperator( QueryParsing.getQueryParserDefaultOperator(getReq().getSchema(), getParam(QueryParsing.OP))); return pqParser.parse(qstr); }
From source file:net.yacy.http.servlets.SolrSelectServlet.java
License:Open Source License
@Override public void service(ServletRequest request, ServletResponse response) throws IOException, ServletException { HttpServletRequest hrequest = (HttpServletRequest) request; HttpServletResponse hresponse = (HttpServletResponse) response; SolrQueryRequest req = null;/* ww w . j a v a 2s . co m*/ final Method reqMethod = Method.getMethod(hrequest.getMethod()); Writer out = null; try { // prepare request to solr MultiMapSolrParams mmsp = SolrRequestParsers.parseQueryString(hrequest.getQueryString()); Switchboard sb = Switchboard.getSwitchboard(); boolean authenticated = true; // count remote searches if this was part of a p2p search if (mmsp.getMap().containsKey("partitions")) { final int partitions = mmsp.getInt("partitions", 30); sb.searchQueriesGlobal += 1.0f / partitions; // increase query counter } // get the ranking profile id int profileNr = mmsp.getInt("profileNr", 0); // rename post fields according to result style String querystring = ""; if (!mmsp.getMap().containsKey(CommonParams.Q) && mmsp.getMap().containsKey(CommonParams.QUERY)) { querystring = mmsp.get(CommonParams.QUERY, ""); mmsp.getMap().remove(CommonParams.QUERY); QueryModifier modifier = new QueryModifier(0); querystring = modifier.parse(querystring); modifier.apply(mmsp); QueryGoal qg = new QueryGoal(querystring); StringBuilder solrQ = qg.collectionTextQuery(); mmsp.getMap().put(CommonParams.Q, new String[] { solrQ.toString() }); // sru patch } String q = mmsp.get(CommonParams.Q, ""); if (querystring.length() == 0) querystring = q; if (!mmsp.getMap().containsKey(CommonParams.START)) { int startRecord = mmsp.getFieldInt("startRecord", null, 0); mmsp.getMap().remove("startRecord"); mmsp.getMap().put(CommonParams.START, new String[] { Integer.toString(startRecord) }); // sru patch } if (!mmsp.getMap().containsKey(CommonParams.ROWS)) { int maximumRecords = mmsp.getFieldInt("maximumRecords", null, 10); mmsp.getMap().remove("maximumRecords"); mmsp.getMap().put(CommonParams.ROWS, new String[] { Integer.toString(maximumRecords) }); // sru patch } mmsp.getMap().put(CommonParams.ROWS, new String[] { Integer .toString(Math.min(mmsp.getInt(CommonParams.ROWS, 10), (authenticated) ? 100000000 : 100)) }); // set ranking according to profile number if ranking attributes are not given in the request Ranking ranking = sb.index.fulltext().getDefaultConfiguration().getRanking(profileNr); if (!mmsp.getMap().containsKey(CommonParams.SORT) && !mmsp.getMap().containsKey(DisMaxParams.BQ) && !mmsp.getMap().containsKey(DisMaxParams.BF) && !mmsp.getMap().containsKey("boost")) { if (!mmsp.getMap().containsKey("defType")) mmsp.getMap().put("defType", new String[] { "edismax" }); String fq = ranking.getFilterQuery(); String bq = ranking.getBoostQuery(); String bf = ranking.getBoostFunction(); if (fq.length() > 0) mmsp.getMap().put(CommonParams.FQ, new String[] { fq }); if (bq.length() > 0) mmsp.getMap().put(DisMaxParams.BQ, new String[] { bq }); if (bf.length() > 0) mmsp.getMap().put("boost", new String[] { bf }); // a boost function extension, see http://wiki.apache.org/solr/ExtendedDisMax#bf_.28Boost_Function.2C_additive.29 } // get a response writer for the result String wt = mmsp.get(CommonParams.WT, "xml"); // maybe use /solr/select?q=*:*&start=0&rows=10&wt=exml QueryResponseWriter responseWriter = RESPONSE_WRITER.get(wt); if (responseWriter == null) throw new ServletException("no response writer"); if (responseWriter instanceof OpensearchResponseWriter) { // set the title every time, it is possible that it has changed final String promoteSearchPageGreeting = (sb .getConfigBool(SwitchboardConstants.GREETING_NETWORK_NAME, false)) ? sb.getConfig("network.unit.description", "") : sb.getConfig(SwitchboardConstants.GREETING, ""); ((OpensearchResponseWriter) responseWriter).setTitle(promoteSearchPageGreeting); } // if this is a call to YaCys special search formats, enhance the query with field assignments if ((responseWriter instanceof YJsonResponseWriter || responseWriter instanceof OpensearchResponseWriter) && "true".equals(mmsp.get("hl", "true"))) { // add options for snippet generation if (!mmsp.getMap().containsKey("hl.q")) mmsp.getMap().put("hl.q", new String[] { q }); if (!mmsp.getMap().containsKey("hl.fl")) mmsp.getMap().put("hl.fl", new String[] { CollectionSchema.description_txt + "," + CollectionSchema.h4_txt.getSolrFieldName() + "," + CollectionSchema.h3_txt.getSolrFieldName() + "," + CollectionSchema.h2_txt.getSolrFieldName() + "," + CollectionSchema.h1_txt.getSolrFieldName() + "," + CollectionSchema.text_t.getSolrFieldName() }); if (!mmsp.getMap().containsKey("hl.alternateField")) mmsp.getMap().put("hl.alternateField", new String[] { CollectionSchema.description_txt.getSolrFieldName() }); if (!mmsp.getMap().containsKey("hl.simple.pre")) mmsp.getMap().put("hl.simple.pre", new String[] { "<b>" }); if (!mmsp.getMap().containsKey("hl.simple.post")) mmsp.getMap().put("hl.simple.post", new String[] { "</b>" }); if (!mmsp.getMap().containsKey("hl.fragsize")) mmsp.getMap().put("hl.fragsize", new String[] { Integer.toString(SearchEvent.SNIPPET_MAX_LENGTH) }); } // get the embedded connector String requestURI = hrequest.getRequestURI(); boolean defaultConnector = (requestURI.startsWith("/solr/" + WebgraphSchema.CORE_NAME)) ? false : requestURI.startsWith("/solr/" + CollectionSchema.CORE_NAME) || mmsp.get("core", CollectionSchema.CORE_NAME).equals(CollectionSchema.CORE_NAME); mmsp.getMap().remove("core"); SolrConnector connector = defaultConnector ? sb.index.fulltext().getDefaultEmbeddedConnector() : sb.index.fulltext().getEmbeddedConnector(WebgraphSchema.CORE_NAME); if (connector == null) { connector = defaultConnector ? sb.index.fulltext().getDefaultConnector() : sb.index.fulltext().getConnectorForRead(WebgraphSchema.CORE_NAME); } if (connector == null) throw new ServletException("no core"); // add default queryfield parameter according to local ranking config (or defaultfield) if (ranking != null) { // ranking normally never null final String qf = ranking.getQueryFields(); if (qf.length() > 4) { // make sure qf has content (else use df) addParam(DisMaxParams.QF, qf, mmsp.getMap()); // add QF that we set to be best suited for our index // TODO: if every peer applies a decent QF itself, this can be reverted to getMap().put() } else { mmsp.getMap().put(CommonParams.DF, new String[] { CollectionSchema.text_t.getSolrFieldName() }); } } else { mmsp.getMap().put(CommonParams.DF, new String[] { CollectionSchema.text_t.getSolrFieldName() }); } // do the solr request, generate facets if we use a special YaCy format final SolrQueryResponse rsp; if (connector instanceof EmbeddedSolrConnector) { req = ((EmbeddedSolrConnector) connector).request(mmsp); rsp = ((EmbeddedSolrConnector) connector).query(req); // prepare response hresponse.setHeader("Cache-Control", "no-cache, no-store"); HttpCacheHeaderUtil.checkHttpCachingVeto(rsp, hresponse, reqMethod); // check error if (rsp.getException() != null) { AccessTracker.addToDump(querystring, "0", new Date()); sendError(hresponse, rsp.getException()); return; } NamedList<?> values = rsp.getValues(); DocList r = ((ResultContext) values.get("response")).docs; int numFound = r.matches(); AccessTracker.addToDump(querystring, Integer.toString(numFound), new Date()); // write response header final String contentType = responseWriter.getContentType(req, rsp); if (null != contentType) response.setContentType(contentType); if (Method.HEAD == reqMethod) { return; } // write response body if (responseWriter instanceof BinaryResponseWriter) { ((BinaryResponseWriter) responseWriter).write(response.getOutputStream(), req, rsp); } else { out = new FastWriter(new OutputStreamWriter(response.getOutputStream(), UTF8.charset)); responseWriter.write(out, req, rsp); out.flush(); } } else { // write a 'faked' response using a call to the backend SolrDocumentList sdl = connector.getDocumentListByQuery(mmsp.getMap().get(CommonParams.Q)[0], mmsp.getMap().get(CommonParams.SORT) == null ? null : mmsp.getMap().get(CommonParams.SORT)[0], Integer.parseInt(mmsp.getMap().get(CommonParams.START)[0]), Integer.parseInt(mmsp.getMap().get(CommonParams.ROWS)[0]), mmsp.getMap().get(CommonParams.FL)); OutputStreamWriter osw = new OutputStreamWriter(response.getOutputStream()); EnhancedXMLResponseWriter.write(osw, req, sdl); osw.close(); } } catch (final Throwable ex) { sendError(hresponse, ex); } finally { if (req != null) { req.close(); } SolrRequestInfo.clearRequestInfo(); if (out != null) try { out.close(); } catch (final IOException e1) { } } }
From source file:net.yacy.search.index.ErrorCache.java
License:Open Source License
public ErrorCache(final Fulltext fulltext) { this.fulltext = fulltext; this.cache = new LinkedHashMap<String, CollectionConfiguration.FailDoc>(); // concurrently fill stack with latest values new Thread() { @Override//from www. j a v a2 s . c o m public void run() { final SolrQuery params = new SolrQuery(); params.setParam("defType", "edismax"); params.setStart(0); params.setRows(1000); params.setFacet(false); params.setSort( new SortClause(CollectionSchema.last_modified.getSolrFieldName(), SolrQuery.ORDER.desc)); params.setFields(CollectionSchema.id.getSolrFieldName()); params.setQuery( CollectionSchema.failreason_s.getSolrFieldName() + AbstractSolrConnector.CATCHALL_DTERM); params.set(CommonParams.DF, CollectionSchema.id.getSolrFieldName()); // DisMaxParams.QF or CommonParams.DF must be given SolrDocumentList docList; try { docList = fulltext.getDefaultConnector().getDocumentListByParams(params); if (docList != null) for (int i = docList.size() - 1; i >= 0; i--) { SolrDocument doc = docList.get(i); String hash = (String) doc.getFieldValue(CollectionSchema.id.getSolrFieldName()); cache.put(hash, null); } } catch (IOException e) { ConcurrentLog.logException(e); } } }.start(); }
From source file:net.yacy.search.index.ErrorCacheFiller.java
License:Open Source License
/** * Fills the error cache with recently failed document hashes found in the index *//*from w w w . j a v a2 s.c o m*/ @Override public void run() { final SolrQuery params = new SolrQuery(); params.setParam("defType", "edismax"); params.setStart(0); params.setRows(1000); params.setFacet(false); params.setSort(new SortClause(CollectionSchema.load_date_dt.getSolrFieldName(), SolrQuery.ORDER.desc)); // load_date_dt = faildate params.setFields(CollectionSchema.id.getSolrFieldName()); params.setQuery(CollectionSchema.failreason_s.getSolrFieldName() + AbstractSolrConnector.CATCHALL_DTERM); params.set(CommonParams.DF, CollectionSchema.id.getSolrFieldName()); // DisMaxParams.QF or CommonParams.DF must be given SolrDocumentList docList; try { docList = this.sb.index.fulltext().getDefaultConnector().getDocumentListByParams(params); if (docList != null) for (int i = docList.size() - 1; i >= 0; i--) { SolrDocument doc = docList.get(i); String hash = (String) doc.getFieldValue(CollectionSchema.id.getSolrFieldName()); cache.putHashOnly(hash); } } catch (IOException e) { ConcurrentLog.logException(e); } }
From source file:net.yacy.search.index.SingleDocumentMatcher.java
License:Open Source License
/** * @param query a Solr query string to parse * @param targetCore an open Solr index core that is the target of the query * @return a lucene Query instance parsed from the given Solr query string on the provided Solr core. * @throws SyntaxError when the query syntax is not valid * @throws SolrException when a query required element is missing, or when a problem occurred when accessing the target core *///w w w. j a va 2s . co m public static Query toLuceneQuery(final String query, final SolrCore targetCore) throws SyntaxError, SolrException { if (query == null || targetCore == null) { throw new IllegalArgumentException("All parameters must be non null"); } final SolrQuery solrQuery = new SolrQuery(query); solrQuery.setParam(CommonParams.DF, CollectionSchema.text_t.getSolrFieldName()); final SolrQueryRequestBase solrRequest = new SolrQueryRequestBase(targetCore, solrQuery) { }; final LuceneQParserPlugin luceneParserPlugin = new LuceneQParserPlugin(); final QParser solrParser = luceneParserPlugin.createParser(query, null, solrRequest.getParams(), solrRequest); return solrParser.parse(); }
From source file:net.yacy.server.serverObjects.java
License:Open Source License
public MultiMapSolrParams toSolrParams(CollectionSchema[] facets) { // check if all required post fields are there if (!this.containsKey(CommonParams.DF)) this.put(CommonParams.DF, CollectionSchema.text_t.getSolrFieldName()); // set default field to the text field if (!this.containsKey(CommonParams.START)) this.put(CommonParams.START, "0"); // set default start item if (!this.containsKey(CommonParams.ROWS)) this.put(CommonParams.ROWS, "10"); // set default number of search results if (facets != null && facets.length > 0) { this.remove("facet"); this.put("facet", "true"); for (int i = 0; i < facets.length; i++) this.add("facet.field", facets[i].getSolrFieldName()); }// w w w .j av a2s. co m return this.map; }