List of usage examples for org.apache.solr.client.solrj SolrQuery setRequestHandler
public SolrQuery setRequestHandler(String qt)
From source file:org.sindice.siren.solr.qparser.TestJsonQParser.java
License:Apache License
@Test public void testQNamesMapping() throws SolrServerException, IOException, QueryNodeException { this.addJsonString("1", "{ \"uri\" : { " + "\"_value_\" : \"http://xmlns.com/foaf/0.1/Person\", " + "\"_datatype_\" : \"uri\" " + "} }"); final SolrQuery query = new SolrQuery(); final QueryBuilder b = new QueryBuilder(); query.setQuery(b.newTwig("uri").with(b.newNode("'foaf:Person'")).toString()); query.setRequestHandler("json"); final String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);/*from w ww . j ava2 s .c o m*/ }
From source file:org.sindice.siren.solr.qparser.TestNestedQuery.java
License:Apache License
@Test public void testCurlyBracketInNestedQuery() throws IOException, SolrServerException { this.addJsonString("1", "{ \"aaa\" : { \"bbb\" : \"ccc\" } }"); SolrQuery query = new SolrQuery(); query.setQuery("aaa : bbb"); query.setParam("nested", "{!keyword} aaa : { bbb : ccc } "); query.setRequestHandler("keyword"); String[] results = this.search(query, ID_FIELD); assertEquals(1, results.length);//from w ww . j a v a 2 s.co m query = new SolrQuery(); query.setQuery("aaa : bbb"); query.setParam("nested", "{!json} { \"node\" : { \"query\" : \"ccc\" } }"); query.setRequestHandler("keyword"); results = this.search(query, ID_FIELD); assertEquals(1, results.length); }
From source file:org.sindice.siren.solr.qparser.TestURIQuery.java
License:Apache License
@Test public void testTildeInURI() throws IOException, SolrServerException { this.addJsonString("1", " { \"uri\" : { " + "\"_value_\" : \"http://sw.deri.org/~aidanh/\", " + "\"_datatype_\" : \"uri\"" + " } }"); SolrQuery query = new SolrQuery(); query.setQuery("uri('http://sw.deri.org/~aidanh/')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query)); // test uri trailing slash filter query = new SolrQuery(); query.setQuery("uri('http://sw.deri.org/~aidanh/')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query)); }
From source file:org.sindice.siren.solr.qparser.TestURIQuery.java
License:Apache License
@Test public void testEncodedURI() throws IOException, SolrServerException { this.addJsonString("1", " { \"uri\" : { " + "\"_value_\" : \"http://dblp.l3s.de/d2r/resource/authors/Knud_M%C3%B6ller\", " + "\"_datatype_\" : \"uri\"" + " } }"); // testing search of plain URI search SolrQuery query = new SolrQuery(); query.setQuery("uri('http://dblp.l3s.de/d2r/resource/authors/Knud_M%C3%B6ller')"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query)); // testing search of decoded local name token query = new SolrQuery(); query.setQuery("Mller"); query.setRequestHandler("keyword"); assertEquals(1, this.search(query)); }
From source file:org.sleuthkit.autopsy.keywordsearch.TermComponentQuery.java
License:Open Source License
protected SolrQuery createQuery() { final SolrQuery q = new SolrQuery(); q.setRequestHandler(TERMS_HANDLER); q.setTerms(true);/*w w w.j av a 2 s . co m*/ q.setTermsLimit(TERMS_UNLIMITED); q.setTermsRegexFlag("case_insensitive"); //NON-NLS //q.setTermsLimit(200); //q.setTermsRegexFlag(regexFlag); //q.setTermsRaw(true); q.setTermsRegex(queryEscaped); q.addTermsField(TERMS_SEARCH_FIELD); q.setTimeAllowed(TERMS_TIMEOUT); return q; }
From source file:org.sleuthkit.autopsy.keywordsearch.TermsComponentQuery.java
License:Open Source License
/** * Executes the regex query as a two step operation. In the first step, the * Solr terms component is used to find any terms in the index that match * the regex. In the second step, term queries are executed for each matched * term to produce the set of keyword hits for the regex. * * @return A QueryResult object or null. * * @throws NoOpenCoreException//from w w w .ja v a 2s . c o m */ @Override public QueryResults performQuery() throws KeywordSearchModuleException, NoOpenCoreException { /* * Do a query using the Solr terms component to find any terms in the * index that match the regex. */ final SolrQuery termsQuery = new SolrQuery(); termsQuery.setRequestHandler(SEARCH_HANDLER); termsQuery.setTerms(true); termsQuery.setTermsRegexFlag(CASE_INSENSITIVE); termsQuery.setTermsRegex(searchTerm); termsQuery.addTermsField(SEARCH_FIELD); termsQuery.setTimeAllowed(TERMS_SEARCH_TIMEOUT); termsQuery.setShowDebugInfo(DEBUG_FLAG); termsQuery.setTermsLimit(MAX_TERMS_QUERY_RESULTS); List<Term> terms = KeywordSearch.getServer().queryTerms(termsQuery).getTerms(SEARCH_FIELD); /* * Do a term query for each term that matched the regex. */ QueryResults results = new QueryResults(this, keywordList); for (Term term : terms) { /* * If searching for credit card account numbers, do a Luhn check on * the term and discard it if it does not pass. */ if (keyword.getArtifactAttributeType() == ATTRIBUTE_TYPE.TSK_CARD_NUMBER) { Matcher matcher = CREDIT_CARD_NUM_PATTERN.matcher(term.getTerm()); matcher.find(); final String ccn = CharMatcher.anyOf(" -").removeFrom(matcher.group("ccn")); if (false == CREDIT_CARD_NUM_LUHN_CHECK.isValid(ccn)) { continue; } } /* * Do an ordinary query with the escaped term and convert the query * results into a single list of keyword hits without duplicates. * * Note that the filters field appears to be unused. There is an old * comment here, what does it mean? "Note: we can't set filter query * on terms query but setting filter query on fileResults query will * yield the same result." The filter is NOT being added to the term * query. */ String escapedTerm = KeywordSearchUtil.escapeLuceneQuery(term.getTerm()); LuceneQuery termQuery = new LuceneQuery(keywordList, new Keyword(escapedTerm, true)); filters.forEach(termQuery::addFilter); // This appears to be unused QueryResults termQueryResult = termQuery.performQuery(); Set<KeywordHit> termHits = new HashSet<>(); for (Keyword word : termQueryResult.getKeywords()) { termHits.addAll(termQueryResult.getResults(word)); } results.addResult(new Keyword(term.getTerm(), false), new ArrayList<>(termHits)); } return results; }
From source file:org.zaizi.manifoldcf.agents.output.solrwrapper.SolrWrapperConnector.java
License:Open Source License
/** * Returns from the Entity core all the children entities of a specific primary document * //from ww w . j a v a2 s . c o m * ATTENTION : This can be improved accessing with GET only the documentURI doc, then retrieving or entity types or * entities ID ( that are there with SMLT fields) * * @param documentURI * @param configuration * @return */ private List<String> retrieveChildrenFromSolr(String documentURI, ConfigParams configuration, String field) { QueryResponse getResponse; SolrQuery getQuery; List<String> childrenIds = new ArrayList<String>(); SolrDocumentList results = new SolrDocumentList(); HttpSolrClient solrServer = getHttpSolrServer(configuration); getQuery = new SolrQuery(); getQuery.setRequestHandler("/get"); getQuery.set("ids", documentURI); try { getResponse = solrServer.query(getQuery); results = getResponse.getResults(); if (results.size() > 0) { SolrDocument d = results.get(0); childrenIds = (List<String>) d.getFieldValue(field); } } catch (SolrServerException e) { Logging.connectors.error("Error retrieving children for : " + documentURI, e); } finally { return childrenIds; } }
From source file:org.zaizi.sensefy.api.service.SemanticSearchService.java
License:Open Source License
/** * Get an Entity from the EntityCore using the Solr GET on that core * * @param entityId//w w w .jav a2 s.co m * @return * @throws org.apache.solr.client.solrj.SolrServerException */ private SolrDocument getEntity(String entityId) throws SolrServerException { SolrDocument extractedEntity = null; if (entityId != null && !entityId.isEmpty()) { SolrQuery entityQuery = new SolrQuery(); entityQuery.setRequestHandler("/get"); entityQuery.set("ids", entityId); QueryResponse entityResponse; entityResponse = this.getEntityCore().query(entityQuery); List<SolrDocument> entities = entityResponse.getResults(); if (entities.size() > 0) { extractedEntity = entities.get(0); } } return extractedEntity; }
From source file:org.zaizi.sensefy.api.service.SolrSmartAutoCompleteService.java
License:Open Source License
/** * This method return the shingle suggestions for the term the query the * user is typing/* w w w. j a v a2 s .c o m*/ * * @param numberOfSuggestions * @param termToComplete * @param primaryIndex * @return */ private List<String> getShingleSuggestions(Integer numberOfSuggestions, String termToComplete, SolrServer primaryIndex) throws SolrServerException, SolrException, IOException { List<String> shingleSuggestions = new ArrayList<String>(); SolrQuery shingleSuggestionQuery = new SolrQuery(termToComplete); shingleSuggestionQuery.setRequestHandler("/autocomplete"); shingleSuggestionQuery.set("suggest.count", numberOfSuggestions); QueryResponse shingleTitleSuggestionResponse; shingleTitleSuggestionResponse = primaryIndex.query(shingleSuggestionQuery); shingleSuggestions = parseSuggestionsFromJson(termToComplete, shingleTitleSuggestionResponse); return shingleSuggestions; }
From source file:org.zaizi.sensefy.api.service.SolrSmartAutoCompleteService.java
License:Open Source License
/** * Query a specific Solr core to obtain advanced suggestions ( such as * Entity Types or Named entities)/*from w w w.j av a 2 s. c o m*/ * * @param numberOfSuggestions * @param core * @return * @throws SolrServerException */ private QueryResponse getSmartSuggestions(String termToComplete, Integer numberOfSuggestions, SolrServer core) throws SolrServerException, SolrException, IOException { SolrQuery namedEntitiesQuery = new SolrQuery(); this.buildAutocompleteQuery(namedEntitiesQuery, termToComplete); namedEntitiesQuery.addSort(SEMANTIC_SORTING_FIELD, SolrQuery.ORDER.desc); namedEntitiesQuery.setRows(numberOfSuggestions); QueryResponse namedEntitiesQueryResponse; namedEntitiesQuery.setRequestHandler("/suggest"); namedEntitiesQueryResponse = core.query(namedEntitiesQuery); if (namedEntitiesQueryResponse.getResults().getNumFound() == 0) { buildSpellcheckQuery(namedEntitiesQuery, termToComplete); namedEntitiesQueryResponse = core.query(namedEntitiesQuery); } return namedEntitiesQueryResponse; }