List of usage examples for org.apache.solr.common.params CommonParams QT
String QT
To view the source code for org.apache.solr.common.params CommonParams QT.
Click Source Link
From source file:cz.incad.vdk.client.tools.Search.java
License:Open Source License
public JSONArray getSuggest() { try {/*from w w w .j a v a 2s.c om*/ String q = req.getParameter("term"); SolrQuery query = new SolrQuery(); if (q == null || q.equals("")) { return new JSONArray(); } query.setParam(CommonParams.QT, "/terms"); query.setTerms(true); query.setTermsPrefix(q.toUpperCase()); query.setTermsLowerInclusive(true); query.addTermsField("title_suggest"); JSONArray ja = new JSONObject(IndexerQuery.terms(query)).getJSONObject("terms") .getJSONArray("title_suggest"); JSONArray ret = new JSONArray(); for (int i = 0; i < ja.length(); i = i + 2) { String val = ja.getString(i); ret.put(new JSONObject().put("value", val).put("label", val.substring(val.indexOf("##") + 2))); } return ret; } catch (IOException ex) { Logger.getLogger(Search.class.getName()).log(Level.SEVERE, null, ex); return new JSONArray(); } }
From source file:datacite.oai.provider.service.MDSSearchServiceSolrImpl.java
License:Open Source License
static SolrQuery constructSolrQuery(Date updateDateFrom, Date updateDateTo, String setspec, int offset, int length) throws ServiceException { SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setRows(length);//from w ww . j a v a 2s. c o m query.setStart(offset); query.setSortField("updated", ORDER.asc); setspec = StringUtils.trimToEmpty(setspec); if (setspec.contains(Constants.Set.BASE64_PART_DELIMITER)) { String split[] = setspec.split(Constants.Set.BASE64_PART_DELIMITER, 2); setspec = split[0]; String base64 = split[1]; String solrfilter = new String(Base64.decodeBase64(base64)); logger.info("decoded base64 setspec: " + solrfilter); solrfilter = solrfilter.replaceAll("^[?&]+", ""); List<NameValuePair> params = URLEncodedUtils.parse(solrfilter, Charset.defaultCharset()); for (NameValuePair param : params) { String name = param.getName(); String value = param.getValue(); if (name.equals("q")) query.setQuery(value); else if (name.equals("fq")) query.addFilterQuery(value); else throw new ServiceException("parameter '" + name + "' is not supported"); } } if (setspec != null && setspec.trim().length() > 0) { setspec = setspec.trim().toUpperCase(); String field = setspec.contains(".") ? "datacentre_symbol" : "allocator_symbol"; query.addFilterQuery(field + ":" + setspec); } String from = dateFormat.format(updateDateFrom); String to = dateFormat.format(updateDateTo); query.addFilterQuery("updated:[" + from + " TO " + to + "]"); query.setParam(CommonParams.QT, "/api"); return query; }
From source file:de.kp.ames.web.core.search.SearcherImpl.java
License:Open Source License
public String suggest(String request, String start, String limit) throws Exception { /*/*from ww w .j ava 2 s.c om*/ * Retrieve terms */ SolrQuery query = new SolrQuery(); query.setParam(CommonParams.QT, "/terms"); query.setParam(TermsParams.TERMS, true); query.setParam(TermsParams.TERMS_LIMIT, SearchConstants.TERMS_LIMIT); query.setParam(TermsParams.TERMS_FIELD, SearchConstants.TERMS_FIELD); query.setParam(TermsParams.TERMS_PREFIX_STR, request); QueryResponse response = solrProxy.executeQuery(query); NamedList<Object> terms = getTerms(response); JSONArray jTerms = getTermValues(SearchConstants.TERMS_FIELD, terms); /* * Render result for DataSource */ return jTerms.toString(); }
From source file:learning.SolrJTest.java
License:Mozilla Public License
@Test @Ignore("it used to work because segments were there. It shouldnt depend on that.") public void can_get_auto_complete_suggestions() throws Exception { add2Documents();/*from w w w.j av a 2 s . c o m*/ SolrQuery solrQuery = new SolrQuery(); solrQuery.setParam(CommonParams.QT, "/suggest"); solrQuery.setParam(CommonParams.Q, "do"); List<String> suggestions = suggestionsOfQuery(solrQuery); assertThat(suggestions.size(), is(2)); }
From source file:learning.SolrJTest.java
License:Mozilla Public License
private QueryResponse createCoreWithName(String name) throws Exception { SolrQuery solrQuery = new SolrQuery(); solrQuery.setParam(CommonParams.QT, "/admin/cores"); solrQuery.setParam(CoreAdminParams.ACTION, CoreAdminParams.CoreAdminAction.CREATE.name()); solrQuery.setParam(CoreAdminParams.NAME, name); solrQuery.setParam(CoreAdminParams.INSTANCE_DIR, "./" + name); solrQuery.setParam(CoreAdminParams.CONFIG, solrHomeRelativePath + solrConfigHomeRelativePath); solrQuery.setParam(CoreAdminParams.SCHEMA, solrHomeRelativePath + solrSchemaHomeRelativePath); solrQuery.setParam(CoreAdminParams.DATA_DIR, "."); return solrServer.query(solrQuery); }
From source file:net.yacy.cora.federate.SolrFederateSearchConnector.java
License:Open Source License
/** * Core query implementation// w w w . j ava2 s . c o m * all query and search routines will use this routine to query the remote system * * @param query * @return list of solr documents (metadata) accordng to local YaCy internal schema */ @Override public List<URIMetadataNode> query(QueryParams query) { List<URIMetadataNode> docs = new ArrayList<URIMetadataNode>(); Collection<String> remotecorename = new ArrayList<String>(); remotecorename.add(corename); ModifiableSolrParams msp = new SolrQuery(query.getQueryGoal().getQueryString(false)); msp.add(CommonParams.QT, "/"); // important to override default append of /select msp.add(CommonParams.ROWS, Integer.toString(query.itemsPerPage)); try { RemoteInstance instance = new RemoteInstance(baseurl, remotecorename, corename, 20000); try { SolrConnector solrConnector = new RemoteSolrConnector(instance, false, null); try { this.lastaccesstime = System.currentTimeMillis(); SolrDocumentList docList = solrConnector.getDocumentListByParams(msp); // convert to YaCy schema documentlist for (SolrDocument doc : docList) { URIMetadataNode anew = toYaCySchema(doc); docs.add(anew); } } catch (IOException | SolrException e) { } finally { solrConnector.close(); } } catch (Throwable ee) { } finally { instance.close(); } } catch (IOException eee) { } return docs; }
From source file:org.alfresco.solr.tracker.CascadeTrackerTest.java
License:Open Source License
/** * After updating the test data hierarchy (folders and file), the test checks that the cascade tracker properly * reflects the changes in the index./* w ww .ja va 2 s .c o m*/ */ @Test public void solrTracking_folderUpdate_shouldReIndexFolderAndChildren() throws Exception { // Update the folder Transaction txn = getTransaction(0, 1); folderMetaData.getProperties().put(ContentModel.PROP_CASCADE_TX, new StringPropertyValue(Long.toString(txn.getId()))); folderMetaData.getProperties().put(ContentModel.PROP_NAME, new StringPropertyValue("folder2")); folderNode.setTxnId(txn.getId()); folderMetaData.setTxnId(txn.getId()); // Change the ancestor on the file just to see if it's been updated NodeRef nodeRef = new NodeRef(new StoreRef("workspace", "SpacesStore"), createGUID()); childFolderMetaData.setAncestors(ancestors(nodeRef)); fileMetaData.setAncestors(ancestors(nodeRef)); upsertData(txn, singletonList(folderNode), singletonList(folderMetaData)); // Check that the ancestor has been changed and indexed TermQuery query = new TermQuery(new Term(QueryConstants.FIELD_ANCESTOR, nodeRef.toString())); waitForDocCount(query, 2, MAX_WAIT_TIME); // Child folder and grandchild document must be updated // This is the same query as before but instead of using a Lucene query, it uses the /afts endpoint (request handler) ModifiableSolrParams params = new ModifiableSolrParams() .add(CommonParams.Q, QueryConstants.FIELD_ANCESTOR + ":\"" + nodeRef.toString() + "\"") .add(CommonParams.QT, "/afts").add(CommonParams.START, "0").add(CommonParams.ROWS, "6") .add(CommonParams.SORT, "id asc").add(CommonParams.FQ, "{!afts}AUTHORITY_FILTER_FROM_JSON"); SolrServletRequest req = areq(params, "{\"locales\":[\"en\"], \"templates\": [{\"name\":\"t1\", \"template\":\"%cm:content\"}], \"authorities\": [ \"mike\"], \"tenants\": [ \"\" ]}"); assertQ(req, "*[count(//doc)=2]", "//result/doc[1]/long[@name='DBID'][.='" + childFolderNode.getId() + "']", "//result/doc[2]/long[@name='DBID'][.='" + fileNode.getId() + "']"); }
From source file:org.apache.gora.solr.store.SolrStore.java
License:Apache License
@Override public T get(K key, String[] fields) { ModifiableSolrParams params = new ModifiableSolrParams(); params.set(CommonParams.QT, "/get"); params.set(CommonParams.FL, toDelimitedString(fields, ",")); params.set("id", key.toString()); try {/*from ww w . ja v a 2s. c o m*/ QueryResponse rsp = server.query(params); Object o = rsp.getResponse().get("doc"); if (o == null) { return null; } return newInstance((SolrDocument) o, fields); } catch (Exception e) { LOG.error(e.getMessage(), e); } return null; }
From source file:org.mitre.opensextant.extraction.PlacenameMatcher.java
License:Apache License
/** *//*from www.j av a 2 s. c o m*/ protected static void initialize() throws IOException { if (solr != null) { return; } // NOTE: This is set via opensextant.apps.Config or by some other means // But it is required to intialize. "gazetteer" is the core name of interest. // Being explicit here about the core name allows integrator to field multiple cores // in the same gazetteer. // String config_solr_home = System.getProperty("solr.solr.home"); solr = new SolrProxy(config_solr_home, "gazetteer"); ModifiableSolrParams _params = new ModifiableSolrParams(); _params.set(CommonParams.QT, requestHandler); //request all fields in the Solr index // Do we need specific fields or *? If faster use specific fields. TODO. //_params.set(CommonParams.FL, "*,score"); // Note -- removed score for now, as we have not evaluated how score could be used in this sense. // Score depends on FST creation and other factors. // // TODO: verify that all the right metadata is being retrieved here _params.set(CommonParams.FL, "id,name,cc,adm1,adm2,feat_class,feat_code,lat,lon,place_id,name_bias,id_bias,name_type"); _params.set("tagsLimit", 100000); _params.set(CommonParams.ROWS, 100000); _params.set("subTags", false); _params.set("matchText", false);//we've got the input doc as a string instead /* Possible overlaps: ALL, NO_SUB, LONGEST_DOMINANT_RIGHT * See Solr Text Tagger documentation for details. */ _params.set("overlaps", "LONGEST_DOMINANT_RIGHT"); //_params.set("overlaps", "NO_SUB"); params = _params; }
From source file:org.mitre.opensextant.extraction.TaxonMatcher.java
License:Apache License
protected static void initialize() throws IOException { if (solr != null) { return;/*ww w.j a va 2s. c o m*/ } String config_solr_home = System.getProperty("solr.solr.home"); solr = new SolrProxy(config_solr_home, "taxcat"); params = new ModifiableSolrParams(); params.set(CommonParams.QT, requestHandler); params.set(CommonParams.FL, "id,catalog,taxnode,phrase,tag"); params.set("tagsLimit", 100000); params.set("subTags", false); params.set("matchText", false);//we've got the input doc as a string instead /* Possible overlaps: ALL, NO_SUB, LONGEST_DOMINANT_RIGHT * See Solr Text Tagger documentation for details. */ params.set("overlaps", "NO_SUB"); }