Package org.elasticsearch.search

Examples of org.elasticsearch.search.SearchHits


            }

            // get existing tweets and users               
            JetwickQuery query = new TweetQuery().addFilterQuery(_ID + getIndexType(), idStr.toString()).setSize(counts);
            SearchResponse rsp = query(query);
            SearchHits docs = rsp.getHits();

            for (SearchHit sd : docs) {
                JTweet tw = readDoc(sd.getId(), sd.getVersion(), sd.getSource());
                existingTweets.put(tw.getTwitterId(), tw);
                JUser u = tw.getFromUser();
View Full Code Here


            //  fetch 10 tweets if less than 5 tweets are in the cache           
            JetwickQuery query = new TweetQuery().addFilterQuery("user", us.getScreenName()).setSize(10);
            try {
                SearchResponse rsp = query(query);
                SearchHits docs = rsp.getHits();
                for (SearchHit sd : docs) {
                    JTweet tw = readDoc(sd.getId(), sd.getVersion(), sd.getSource());
                    JTweet twOld = tweets.get(tw.getTwitterId());
                    if (twOld == null)
                        us.addOwnTweet(tw);
View Full Code Here

    protected void findRepliesForOriginalTweets(JetwickQuery query, Map<Long, JTweet> tweets,
            Collection<JTweet> updatedTweets) {

        Map<Long, JTweet> replyMap = new LinkedHashMap<Long, JTweet>();
        SearchResponse rsp = query(query);
        SearchHits docs = rsp.getHits();

        for (SearchHit sd : docs) {
            JTweet tw = readDoc(sd.getId(), sd.getVersion(), sd.getSource());
            replyMap.put(tw.getTwitterId(), tw);
        }
View Full Code Here

    protected void selectOriginalTweetsWithReplies(JetwickQuery query, Collection<JTweet> tweets,
            Collection<JTweet> updatedTweets) {

        SearchResponse rsp = query(query);
        SearchHits docs = rsp.getHits();
        Map<Long, JTweet> origMap = new LinkedHashMap<Long, JTweet>();
        for (SearchHit sd : docs) {
            JTweet tw = readDoc(sd.getId(), sd.getVersion(), sd.getSource());
            origMap.put(tw.getTwitterId(), tw);
        }
View Full Code Here

        return collectObjects(query(q));
    }
   
    @Override
    public List<T> collectObjects(SearchResponse rsp) {
        SearchHits docs = rsp.getHits();
        List<T> list = new ArrayList<T>(docs.hits().length);
        for (SearchHit sd : docs) {
            if (sd.getExplanation() != null) {
                String res = "";
                for (Explanation str : sd.getExplanation().getDetails()) {
                    res += str.toString();
View Full Code Here

    }

    @Test
    public void testLetUpdateFailButMergeToGetCorrectRetweetCount() throws IOException {
        twSearch.testUpdate(createTweet(1L, "text", "peter"));
        SearchHits h = twSearch.query(new TweetQuery()).hits();
        assertEquals(1, h.totalHits());

        Collection<Integer> res = twSearch.bulkUpdate(
                Arrays.asList(createTweet(1L, "text", "peter").setRetweetCount(1).setVersion(10)),
                twSearch.getIndexName());
        assertEquals(1, res.size());
View Full Code Here

    }

    @Test
    public void testVersionCollision() throws IOException {
        twSearch.testUpdate(createTweet(1L, "text", "peter"));
        SearchHits h = twSearch.query(new TweetQuery()).hits();
        assertEquals(1, h.totalHits());

        Collection<Integer> res = twSearch.bulkUpdate(
                Arrays.asList(createTweet(1L, "text", "peter").setRetweetCount(1).setVersion(h.hits()[0].getVersion())),
                twSearch.getIndexName());
        assertEquals(0, res.size());
        twSearch.refresh();

        assertEquals(1, twSearch.searchTweets(new TweetQuery()).size());
View Full Code Here

        RangeFacet.Entry entries[] = new RangeFacet.Entry[2];       
        entries[0] = newEntry("-Infinity", "xy");       
        entries[1] = newEntry("xy", "Infinity");
        final RangeFacet rf = new InternalRangeFacet(ElasticTweetSearch.DATE_FACET, entries);

        SearchHits sh = mock(SearchHits.class);
        when(sh.getTotalHits()).thenReturn(10L);

        SearchResponse sr = mock(SearchResponse.class);
        when(sr.hits()).thenReturn(sh);
        when(sr.facets()).thenReturn(new Facets() {
View Full Code Here

    // find nearby Address objects
    QueryBuilder qb1 = QueryBuilders.filteredQuery(QueryBuilders.matchAllQuery(),
        FilterBuilders.geoDistanceFilter("latlng").point(lat, lng).
        distance(radius, DistanceUnit.KILOMETERS));

    SearchHits hits1 = searchQueryRaw(appid, Utils.type(Address.class), qb1, pager);

    if (hits1 == null) {
      return new ArrayList<P>();
    }

    // then find their parent objects
    String[] ridsarr = new String[(int) hits1.getTotalHits()];
    for (int i = 0; i < hits1.getTotalHits(); i++) {
      Object pid = hits1.getAt(i).getSource().get(Config._PARENTID);
      if (pid != null) {
        ridsarr[i] = pid.toString();
      }
    }

    QueryBuilder qb2 = QueryBuilders.filteredQuery(QueryBuilders.queryString(query),
        FilterBuilders.idsFilter(type).ids(ridsarr));
    SearchHits hits2 = searchQueryRaw(appid, type, qb2, pager);

    return searchQuery(appid, hits2);
  }
View Full Code Here

    }
    if (sort == null) {
      sort = SortBuilders.scoreSort();
    }

    SearchHits hits = null;

    try {
      SearchRequestBuilder srb = client().prepareSearch(appid).
        setSearchType(SearchType.DFS_QUERY_THEN_FETCH).
        setQuery(query).addSort(sort).setFrom(start).setSize(max);

      if (type != null) {
        srb.setTypes(type);
      }

      hits = srb.execute().actionGet().getHits();
      page.setCount(hits.getTotalHits());
    } catch (Exception e) {
      logger.warn(null, e);
    }

    return hits;
View Full Code Here

TOP

Related Classes of org.elasticsearch.search.SearchHits

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.