Package com.flaptor.hounder.searcher

Examples of com.flaptor.hounder.searcher.GroupedSearchResults


        synchronized(execution) {
            for (Results<GroupedSearchResults> result : execution.getResultsList()) {
                @SuppressWarnings("unchecked")
                int numSearcher = ((CallableWithId<GroupedSearchResults, Integer>)result.getTask()).getId();
                if (result.isFinishedOk()) {
                  GroupedSearchResults gsr = result.getResults();
                  goodResultsMap.put(numSearcher, gsr);
                    totalDocuments += gsr.totalGroupsEstimation();
                    // gather stats from the uni-searchers
                  Statistics.getStatistics().notifyEventValue("averageTimes_" + searchers.get(numSearcher).getTextualIdentifier(), gsr.getResponseTime());
                } else {
                    badResults++;
                    logger.warn("Exception from remote searcher " +  numSearcher, result.getException());
                    //gather stats of searcher failures
                    Statistics.getStatistics().notifyEventError("averageTimes_" + searchers.get(numSearcher).getTextualIdentifier());
                    badResultsMap.put(numSearcher, result.getException().getMessage());
                }
            }
        }


        //move (sorted) entries to a list
        for (Map.Entry<Integer, GroupedSearchResults> entry : goodResultsMap.entrySet()) {
          goodResults.add(entry.getValue());
        }
        int resultsSize = goodResults.size();
        logger.debug("obtained " + totalDocuments + " documents in "+ resultsSize + " good responses and " +  badResults + " exceptions in " + (System.currentTimeMillis() - start) + " ms ");

        GroupedSearchResults gsr= null;
        if (goodResults.size() == 0) {
            logger.warn("No good results - " + badResults + " exceptions");
            gsr = new GroupedSearchResults();
        } else {
          //done collecting results, either because we have results from all the searchers or because we timed out
          //now we generate a result vector with the top results of each set
          AResultsGrouper grouper = group.getGrouper(new GroupedSearchResultsDocumentProvider(goodResults,sort));
          gsr = grouper.group(count,groupSize,firstResult);
        }

        MultiGSR result = new MultiGSR(gsr,searchers.size());

        for (Entry<Integer, GroupedSearchResults> entry: goodResultsMap.entrySet()){
          int searcherNum= entry.getKey();
          GroupedSearchResults tgsr = entry.getValue();
      result.setData(searcherNum, tgsr.getResponseTime(), tgsr.groups());
        }
        for (Entry<Integer, String> entry: badResultsMap.entrySet()){
          int searcherNum= entry.getKey();
          result.setData(searcherNum, -1L, -1);
          logger.warn("Searcher " + entry.getKey() + " failed with " + entry.getValue());
View Full Code Here


        } catch (java.io.IOException e) {
            String s = "group: error while getting documents from the topdocs: " + e.getMessage() ;
            logger.error(s,e);
            throw new RuntimeException(e);
        }
        return new GroupedSearchResults(docs,provider.totalHits()/*tdocs.totalHits*/,offset,i,scores);
    }
View Full Code Here

    @TestInfo(testType = TestInfo.TestType.UNIT)
    public void testSuggests() throws Exception {
        AQuery query = new LazyParsedQuery("foo");
        // a foo query should return no results
        GroupedSearchResults gsr = suggestSearcher.search(query,0,10,new NoGroup(),1,null,null);
System.out.println("Suggests: "+gsr.getSuggestedQuery().toString());
        assertTrue(gsr.getSuggestedQuery().toString().contains("bar"));
    }   
View Full Code Here

    }   

    @TestInfo(testType = TestInfo.TestType.UNIT)
    public void testDoesNotSuggest() throws Exception {
        AQuery query = new LazyParsedQuery("dont give results");
        GroupedSearchResults gsr = suggestSearcher.search(query,0,10,new NoGroup(),1,null,null);
        assertTrue(null == gsr.getSuggestedQuery());
    }
View Full Code Here

        // every query, that does not contain "bar", will return empty
        public GroupedSearchResults search(AQuery query, int firstResult, int groupCount, AGroup groupBy, int groupSize,AFilter filter, ASort sort) throws com.flaptor.hounder.searcher.SearcherException {
      
            if (!query.toString().contains("bar")) {
                return new GroupedSearchResults();
            }
            // else
            Vector<Pair<String,Vector<Document>>> vec = new Vector<Pair<String,Vector<Document>>>();
            Vector<Vector<Float>> scores = new Vector<Vector<Float>>();
            for (int i = 0; i < 10; i++) {
                Vector<Document> doc = new Vector<Document>();
                doc.add(new Document());
                vec.add(new Pair<String,Vector<Document>>("",doc));
                Vector<Float> score = new Vector<Float>();
                score.add(new Float(10-i));
                scores.add(score);
            }
            return new GroupedSearchResults(vec,1000,0,11,scores);
           
        }
View Full Code Here

                    Thread.sleep(500);
                } catch (InterruptedException e) {}
            }
            synchronized(this) {
                queriesInProgress--;
                return new GroupedSearchResults();
            }
        }
View Full Code Here

    // As there was a bug of IndexOutOfBoundsException when every GroupedSearchResults
    // on the list for the GroupedSearchResultsDocumentProvider constructor was empty,
    // this test checks that that bug is not present anymore
    @TestInfo(testType = TestInfo.TestType.UNIT)
    public void testEmptyResults() throws Exception {
        GroupedSearchResults gsr1 = new GroupedSearchResults();
        GroupedSearchResults gsr2 = new GroupedSearchResults();

        List<GroupedSearchResults> list = new ArrayList<GroupedSearchResults>();
        list.add(gsr1);
        list.add(gsr2);
View Full Code Here

                docs.add(new Pair<String,Vector<Document>>(String.valueOf(10*j+i),group));
                Vector<Float> score = new Vector<Float>();
                score.add(1f);
                scores.add(score);
            }
            GroupedSearchResults gsr = new GroupedSearchResults(docs,10,0,10,scores);
            gsrs.add(gsr);
        }

        java.util.Collections.shuffle(gsrs);
        GroupedSearchResultsDocumentProvider provider = new GroupedSearchResultsDocumentProvider(gsrs,sort);
View Full Code Here

        }

        public GroupedSearchResults search(AQuery query, int firstResult, int count, AGroup group, int groupSize, AFilter filter, ASort sort) {
            synchronized(this) {queriesInProgress++;}
            ThreadUtil.sleep(random ? new Random().nextInt(waitingTime) : waitingTime);
            synchronized(this) {queriesInProgress--;return new GroupedSearchResults();}
        }
View Full Code Here

    @TestInfo(testType = TestInfo.TestType.SYSTEM,
            requiresPort = {10000, 10001, 10010, 10011, 10012})
  public void testLatinText() throws SearcherException{
    indexer.index(latin1);
    Execute.sleep(8000);
    GroupedSearchResults sr;
        sr = searcher.search(new LazyParsedQuery("xsín"), 0, 10, noGroup, 1, null, null);
    assertEquals("Searching 'xsín'", 1, sr.totalGroupsEstimation());
        sr = searcher.search(new LazyParsedQuery("xsin"), 0, 10, noGroup, 1, null, null);
    assertEquals("Searching 'xsin'", 1, sr.totalGroupsEstimation());
        sr = searcher.search(new LazyParsedQuery("xcón"), 0, 10, noGroup, 1, null, null);
    assertEquals("Searching 'xcón'", 1, sr.totalGroupsEstimation());
        sr = searcher.search(new LazyParsedQuery("xcon"), 0, 10, noGroup, 1, null, null);
    assertEquals("Searching 'xcon'", 1, sr.totalGroupsEstimation());
  }
View Full Code Here

TOP

Related Classes of com.flaptor.hounder.searcher.GroupedSearchResults

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.