Search in sources :

Example 1 with IndexQuery

use of com.thinkaurelius.titan.diskstorage.indexing.IndexQuery in project titan by thinkaurelius.

the class ElasticSearchIndexTest method testUnescapedDollarInSet.

@Test
public void testUnescapedDollarInSet() throws Exception {
    initialize("vertex");
    Multimap<String, Object> initialDoc = HashMultimap.create();
    initialDoc.put(PHONE_SET, "12345");
    add("vertex", "unescaped", initialDoc, true);
    clopen();
    Multimap<String, Object> updateDoc = HashMultimap.create();
    updateDoc.put(PHONE_SET, "$123");
    add("vertex", "unescaped", updateDoc, false);
    add("vertex", "other", getRandomDocument(), true);
    clopen();
    assertEquals("unescaped", tx.query(new IndexQuery("vertex", PredicateCondition.of(PHONE_SET, Cmp.EQUAL, "$123"))).get(0));
    assertEquals("unescaped", tx.query(new IndexQuery("vertex", PredicateCondition.of(PHONE_SET, Cmp.EQUAL, "12345"))).get(0));
}
Also used : IndexQuery(com.thinkaurelius.titan.diskstorage.indexing.IndexQuery) IndexProviderTest(com.thinkaurelius.titan.diskstorage.indexing.IndexProviderTest) Test(org.junit.Test)

Example 2 with IndexQuery

use of com.thinkaurelius.titan.diskstorage.indexing.IndexQuery in project incubator-atlas by apache.

the class Solr5Index method query.

@Override
public List<String> query(IndexQuery query, KeyInformation.IndexRetriever informations, BaseTransaction tx) throws BackendException {
    List<String> result;
    String collection = query.getStore();
    String keyIdField = getKeyFieldId(collection);
    SolrQuery solrQuery = new SolrQuery("*:*");
    String queryFilter = buildQueryFilter(query.getCondition(), informations.get(collection));
    solrQuery.addFilterQuery(queryFilter);
    if (!query.getOrder().isEmpty()) {
        List<IndexQuery.OrderEntry> orders = query.getOrder();
        for (IndexQuery.OrderEntry order1 : orders) {
            String item = order1.getKey();
            SolrQuery.ORDER order = order1.getOrder() == Order.ASC ? SolrQuery.ORDER.asc : SolrQuery.ORDER.desc;
            solrQuery.addSort(new SolrQuery.SortClause(item, order));
        }
    }
    solrQuery.setStart(0);
    if (query.hasLimit()) {
        solrQuery.setRows(query.getLimit());
    } else {
        solrQuery.setRows(maxResults);
    }
    try {
        QueryResponse response = solrClient.query(collection, solrQuery);
        if (logger.isDebugEnabled())
            logger.debug("Executed query [{}] in {} ms", query.getCondition(), response.getElapsedTime());
        int totalHits = response.getResults().size();
        if (!query.hasLimit() && totalHits >= maxResults)
            logger.warn("Query result set truncated to first [{}] elements for query: {}", maxResults, query);
        result = new ArrayList<>(totalHits);
        for (SolrDocument hit : response.getResults()) {
            result.add(hit.getFieldValue(keyIdField).toString());
        }
    } catch (IOException e) {
        logger.error("Query did not complete : ", e);
        throw new PermanentBackendException(e);
    } catch (SolrServerException e) {
        logger.error("Unable to query Solr index.", e);
        throw new PermanentBackendException(e);
    }
    return result;
}
Also used : IndexQuery(com.thinkaurelius.titan.diskstorage.indexing.IndexQuery) PermanentBackendException(com.thinkaurelius.titan.diskstorage.PermanentBackendException) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) SolrQuery(org.apache.solr.client.solrj.SolrQuery) SolrDocument(org.apache.solr.common.SolrDocument) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse)

Aggregations

IndexQuery (com.thinkaurelius.titan.diskstorage.indexing.IndexQuery)2 PermanentBackendException (com.thinkaurelius.titan.diskstorage.PermanentBackendException)1 IndexProviderTest (com.thinkaurelius.titan.diskstorage.indexing.IndexProviderTest)1 IOException (java.io.IOException)1 SolrQuery (org.apache.solr.client.solrj.SolrQuery)1 SolrServerException (org.apache.solr.client.solrj.SolrServerException)1 QueryResponse (org.apache.solr.client.solrj.response.QueryResponse)1 SolrDocument (org.apache.solr.common.SolrDocument)1 Test (org.junit.Test)1