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


Java SolrQuery.getFilterQueries方法代碼示例

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


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

示例1: testCreateDocumentQueryForSelection

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Test of createDocumentQuery method, of class
 * SolrDocumentQueryFactoryImpl.
 */
@Test
public void testCreateDocumentQueryForSelection() {
    final Map<String, FacetSelection> selectionMap = Collections.<String, FacetSelection>singletonMap("field1", new FacetSelection(Collections.singleton("value 1")));
    final QueryFacetsSelection selection = new QueryFacetsSelection("query", selectionMap);
    final int first = 100;
    final int count = 15;

    final SolrQuery query = instance.createDocumentQuery(selection, first, count);

    assertEquals(Integer.valueOf(100), query.getStart());
    assertEquals(Integer.valueOf(15), query.getRows());

    final String[] filterQueries = query.getFilterQueries();
    assertEquals(1, filterQueries.length);
    assertEquals("field1:\"value\\ 1\"", filterQueries[0]);

    final String fields = query.getFields();
    assertTrue(fields.contains("field1"));
    assertTrue(fields.contains("field2"));
    assertTrue(fields.contains("field3"));
    assertEquals("query", query.getQuery());
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:27,代碼來源:SolrDocumentQueryFactoryImplTest.java

示例2: sanitise

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Basic sanitising of Solr queries.
 *
 * TODO: Move this to QueryFacetSelection level??
 *
 * Query is based on the URL to the VLO web application. Also, explain about
 * the URL and ?fq=language:dutch Assume filters have the form a:b like for
 * example language:dutch
 *
 * @param query
 * @return
 */
protected SolrQuery sanitise(SolrQuery query) {

    // String [] facetsFromConfig; 
    // try and get the filters facets from the query
    String[] filtersInQuery;
    filtersInQuery = query.getFilterQueries();
    
    if (filtersInQuery == null) {
        // the query does not contain filters
    } else {
        // get the facets from the configuration file
        // facetsFromConfig = VloConfig.getFacetFields();

        // check the filters in the query by name
        for (String filter : filtersInQuery) {
            // split up a filter, look at the string preceeding the semicolon 
            String facetInFilter = filter.split(":")[0]
                    .replaceFirst("^\\{!tag=.*\\}", ""); //strip out tag syntax (may be used for OR queries, see query factory implementation)
            
            if (FacetConstants.AVAILABLE_FACETS.contains(facetInFilter)) {
                // facet in the filter is in the set that is defined by the config file
            } else {
                if (facetInFilter.startsWith("_")) {
                    // this facet is hidden, do not consider it
                } else {
                    // the filter name does not match a facet in the facet
                    query.removeFilterQuery(filter);
                }
            }
        }
    }

    // finally, return the sanitised query
    return query;
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:48,代碼來源:SolrDaoImpl.java

示例3: testCreateDocumentQueryForDocId

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
/**
 * Test of createDocumentQuery method, of class
 * SolrDocumentQueryFactoryImpl.
 */
@Test
public void testCreateDocumentQueryForDocId() {
    final SolrQuery query = instance.createDocumentQuery("document\"Id");

    final String[] filterQueries = query.getFilterQueries();
    assertEquals(1, filterQueries.length);
    // expecting query that looks in both id and selflink fields with properly escaped values
    assertEquals("id:\"document\\\"Id\" OR _selfLink:\"document\\\"Id\"", filterQueries[0]);

    final String fields = query.getFields();
    assertTrue(fields.contains("field1"));
    assertTrue(fields.contains("field2"));
    assertTrue(fields.contains("field3"));
}
 
開發者ID:acdh-oeaw,項目名稱:vlo-curation,代碼行數:19,代碼來源:SolrDocumentQueryFactoryImplTest.java

示例4: testRule1144

import org.apache.solr.client.solrj.SolrQuery; //導入方法依賴的package包/類
@Test
public void testRule1144() throws CdxRestrictionService.RulesOutOfDateException, ParseException {
  // Rule 1144 was just odd. has a left-anchored wildcard plus an empty string.
  SimpleDateFormat sdf = new SimpleDateFormat(RestrictionsDAO.DATE_FORMAT);

  Document doc = new Document();
  setUrl(doc, "http://blocked.adultshop.com.au");

  // Rule 953) Multiple URL patterns from a Pandora conversion. 2nd is a broad wildcard for a whole domain
  // *.adultshop.com.au
  // Embargoed for 70 years!!!
  // Fake 'today' is =>           "2014-01-01T00:00:00+1100"
  Date MATCH_DATE     = sdf.parse("1945-01-01T00:00:00+1100"); // - 69 years
  Date NOT_MATCH_DATE = sdf.parse("1943-01-01T00:00:00+1100"); // - 71 years

  doc.setDate(MATCH_DATE);
  assertEquals(DocumentStatus.RESTRICTED_FOR_BOTH, service.filterDocument(doc).getIndexerPolicy());

  doc.setDate(NOT_MATCH_DATE);
  assertEquals(DocumentStatus.ACCEPTED, service.filterDocument(doc).getIndexerPolicy());

  // Let's eyeball what that empty String will do
  RuleChangeUpdateManager manager = new RuleChangeUpdateManager();
  SolrQuery query = manager.convertRuleToSearch(ruleSet.getRules().get(1144L), "");
  boolean found = false;
  // We do not want to see *:* on the end
  String target = "(" + SolrEnum.URL_TOKENIZED + ":pandora.nla.gov.au\\/pan\\/35531\\/) OR ("
          + SolrEnum.URL_TOKENIZED + ":adultshop.com.au\\/)";
  for (String fq : query.getFilterQueries()) {
    if (target.equals(fq)) {
      found = true;
    }
  }
  if (!found) {
    // This behaviour is only ok when a single URL pattern was provided and it was empty.
    Assert.fail("An empty URL pattern should not be part of a query when there are other valid patterns");
  }
}
 
開發者ID:nla,項目名稱:bamboo,代碼行數:39,代碼來源:CdxRestrictionServiceTest.java


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