當前位置: 首頁>>代碼示例>>Java>>正文


Java SolrQuery.setQueryType方法代碼示例

本文整理匯總了Java中org.apache.solr.client.solrj.SolrQuery.setQueryType方法的典型用法代碼示例。如果您正苦於以下問題:Java SolrQuery.setQueryType方法的具體用法?Java SolrQuery.setQueryType怎麽用?Java SolrQuery.setQueryType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.solr.client.solrj.SolrQuery的用法示例。


在下文中一共展示了SolrQuery.setQueryType方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testThatSpellCheckerShouldNotAcceptAnInexistingSpellCheckerDictionaryName

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Test
   public void testThatSpellCheckerShouldNotAcceptAnInexistingSpellCheckerDictionaryName() {
SolrQuery solrQuery = new SolrQuery();
solrQuery.setQueryType(Constants.SolrQueryType.spellcheck.toString());
solrQuery.add(Constants.SPELLCHECKER_DICTIONARY_NAME_PARAMETER,
	"notExistingInSolrConfig.xml");
solrQuery.add(Constants.SPELLCHECKER_BUILD_PARAMETER, "true");
solrQuery.add(Constants.SPELLCHECKER_ENABLED_PARAMETER, "true");
solrQuery.setQuery("spell");
try {
    QueryResponse response = solrClient.getServer().query(solrQuery);
    if (response.getStatus() != 0) {
	fail("Status should not be 0 when the name of the dictionnary name is not defined in solrConfig.xml");
    }
    fail("dictionnary name that are not defined in solrConfig.xml should not be accepted");
} catch (Exception e) {
  logger.error(e);
}

   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:21,代碼來源:SpellCheckerIndexerTest.java

示例2: searchInFulltextSearchEngine

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
private QueryResponse searchInFulltextSearchEngine(String searchWords) {
SolrQuery query = new SolrQuery();
String namefield = FullTextFields.ALL_NAME.getValue();

String queryString = "(" + namefield + ":\"" + searchWords + "\")";
query.setQuery(queryString);
query.setQueryType(Constants.SolrQueryType.advanced.toString());
query.setFields(FullTextFields.FEATUREID.getValue());

QueryResponse resultsAfterRemove = null;
try {
    resultsAfterRemove = solrClient.getServer().query(query);
} catch (SolrServerException e) {
    fail();
}
return resultsAfterRemove;
   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:18,代碼來源:SolRSynchroniserTest.java

示例3: buildIndex

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
public boolean buildIndex(
    SpellCheckerDictionaryNames spellCheckerDictionaryName) {
if (!SpellCheckerConfig.isEnabled()) {
    return false;
}

SolrQuery solrQuery = new SolrQuery();
solrQuery.setQueryType(Constants.SolrQueryType.spellcheck.toString());
solrQuery.add(Constants.SPELLCHECKER_DICTIONARY_NAME_PARAMETER,
	spellCheckerDictionaryName.toString());
solrQuery.add(Constants.SPELLCHECKER_BUILD_PARAMETER, "true");
solrQuery.add(Constants.SPELLCHECKER_ENABLED_PARAMETER, "true");
solrQuery.setQuery("spell");
try {
    QueryResponse response = solrClient.getServer().query(solrQuery);
    if (response.getStatus() != 0) {
	 logger.error("Indexing dictionary "
		    + spellCheckerDictionaryName.name()+" fails");
	return false;
    }
    logger.info("Successfully indexing dictionary "
	    + spellCheckerDictionaryName.name());
    return true;

} catch (Exception e) {
    logger.error("An error has occured when indexing spellchecker "
	    + spellCheckerDictionaryName + " : " + e);
    return false;
}

   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:32,代碼來源:SpellCheckerIndexer.java

示例4: listFromText

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
    * Do a full text search for the given name. The search will be case,
    * iso-latin, comma-separated insensitive<br>
    * search for 'saint-André', 'saint-Andre', 'SaInT-andré', 'st-andré', etc
    * will return the same results. <u>note</u> : search for zipcode too
    * Polymorphism is not supported, e.g : if clazz=GisFeature : the results
    * will only be of that type and no other feature type (e.g : City that
    * extends gisFeature...etc) will be returned. The results will be sort by
    * relevance.
    * 
    * @param name
    *                The name to search for
    * @param includeAlternateNames
    *                Wether we search in the alternatenames too
    * @param clazz
    *                specify the features we want to search for, if null : no
    *                restriction is apply
    * @return a list of gisFeatures of type of the class for the given text.
    *         the max list size is {@link GenericGisDao#MAX_FULLTEXT_RESULTS};
    * @see IGisFeatureDao#listAllFeaturesFromText(String, boolean)
    */
   protected List<T> listFromText(String name, boolean includeAlternateNames,
    Class<T> clazz) {
logger.debug("getFromText " + name);
// Set up a simple query
// Check for a null or empty string query
if (name == null || name.length() == 0) {
    return new ArrayList<T>();
}

SolrQuery query = new SolrQuery();
String namefield = FullTextFields.ALL_NAME.getValue();
if (!includeAlternateNames) {
    namefield = FullTextFields.NAME.getValue();
}
String queryString = "(" + namefield + ":\"" + name + "\" OR "
	+ FullTextFields.ZIPCODE.getValue() + ":\"" + name + "\")";
if (clazz != null) {
    queryString += " AND placetype:" + persistentClass.getSimpleName();
}
query.setQuery(queryString);
query.setQueryType(Constants.SolrQueryType.advanced.toString());
query.setFields(FullTextFields.FEATUREID.getValue());
query.setRows(MAX_FULLTEXT_RESULTS);

QueryResponse results = null;
try {
    results = solrClient.getServer().query(query);
} catch (SolrServerException e) {
    throw new RuntimeException(e);
}

List<Long> ids = new ArrayList<Long>();
for (SolrDocument doc : results.getResults()) {
    ids.add((Long) doc.getFieldValue(FullTextFields.FEATUREID
	    .getValue()));
}
// log
List<T> gisFeatureList = this.listByFeatureIds(ids);
if (logger.isDebugEnabled()) {
    logger.debug("search on " + name + " returns "
	    + gisFeatureList.size());
    for (GisFeature gisFeature : gisFeatureList) {
	logger.debug("search on " + name + " returns "
		+ gisFeature.getName());
    }
}

return gisFeatureList;
   }
 
開發者ID:gisgraphy,項目名稱:gisgraphy,代碼行數:71,代碼來源:GenericGisDao.java

示例5: createQuery

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
protected SolrQuery createQuery(String q, String fq, String qt,
		boolean highlight, String facetFields, String sort, String sortOrder, Integer rows, Integer start, 
		String otherParams) throws QueryException {
	SolrQuery query = new SolrQuery();
	if(q != null) {
		query.setQuery(q);
	}
	if(fq != null) {
		List<String> filterQueries = this.getFilterQueries(fq);
		for(String filterQuery:filterQueries) {
			query.addFilterQuery(filterQuery);
		}
	}
	if(qt != null) {
		query.setQueryType(qt);
	}
	query.setHighlight(highlight);
	if(facetFields == null || "".equals(facetFields)) {
		query.setFacet(false);
	}else {
		query.setFacet(true);
		List<String> facets = this.getFacets(facetFields);
		for(String facet:facets) {
			query.addFacetField(facet);
		}
	}
	if(sort != null && !"".equals(sort)) {
		query.setSortField(sort, ORDER.valueOf(sortOrder));
	}
	if(rows != null && rows < 0) {
		throw new QueryException("Rows can't be less than 0");
	}else if(rows != null) {
		query.setRows(rows);
	}
	if(start != null && start < 0) {
		throw new QueryException("Rows can't be less than 0");
	}else if(start != null) {
		query.setStart(start);
	}
	
	if(otherParams != null) {
		List<String> params = this.getOtherParams(otherParams);
		for(String param:params) {
			query.add(getParamName(param), getParamValue(param));
		}
	}
	return query;
}
 
開發者ID:lafourchette,項目名稱:solrmeter,代碼行數:49,代碼來源:QueryServiceSolrJImpl.java


注:本文中的org.apache.solr.client.solrj.SolrQuery.setQueryType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。