Package com.flaptor.indextank.index

Examples of com.flaptor.indextank.index.TopMatches


  public TopMatches findMatches(Query query, Predicate<DocId> docFilter, int limit, int scoringFunctionIndex) throws InterruptedException {
    Predicate<DocId> historyFilter = notModified(currentSearcher, docFilter);
   
        /* instrumentation */ long historyStart = System.currentTimeMillis();
   
        TopMatches history = historySearcher.findMatches(query, historyFilter, limit, scoringFunctionIndex);
    int historyMatches = history.getTotalMatches();
   
    /* instrumentation */ long currentStart = System.currentTimeMillis();
   
        TopMatches current = docFilter == null ? currentSearcher.findMatches(query, limit, scoringFunctionIndex) : currentSearcher.findMatches(query, docFilter, limit, scoringFunctionIndex);
    int currentMatches = current.getTotalMatches();

    /* instrumentation */ long endSearch = System.currentTimeMillis();
   
    List<ScoredMatch> currentResults = Lists.newArrayList(current);
   
    Iterable<ScoredMatch> historyResults = filterIds(history, getIds(currentResults));
    List<ScoredMatch> results = mergeIntoList(currentResults, historyResults, limit);
        int matches = Math.abs(currentMatches) + Math.abs(historyMatches);
    if (results.size() < limit) {
      matches = results.size();
    }
   
    if (currentMatches < 0 || historyMatches < 0) {
        matches = -matches;
    }
   
    /* instrumentation */  long end = System.currentTimeMillis();
   
        logger.debug("(Search) historic searcher took: " + (currentStart - historyStart) + " ms., current searcher took: " +
                + (endSearch - currentStart) + " ms., merge took: " + (end - endSearch) + " ms.");
       
        Map<String, Multiset<String>> facets = FacetingManager.mergeFacets(history.getFacetingResults(), current.getFacetingResults());
       
    return new SimpleScoredDocIds(results, limit, matches, facets);
  }
View Full Code Here


      return matcher;
    }
   
    @Override
    public TopMatches findMatches(Query query, Predicate<DocId> docFilter, int limit, int scoringFunctionIndex) throws InterruptedException {
        TopMatches retVal = getSearcher().findMatches(query, docFilter, limit, scoringFunctionIndex);
      suggestor.noteQuery(query, retVal.getTotalMatches());
      return retVal;
    }
View Full Code Here

   
    @Override
    public TopMatches findMatches(Query query, int limit, int scoringFunctionIndex) throws InterruptedException {
        Preconditions.checkNotNull(query);
        Preconditions.checkArgument(limit > 0);
        TopMatches retVal = getSearcher().findMatches(query, limit, scoringFunctionIndex);
      suggestor.noteQuery(query, retVal.getTotalMatches());
      return retVal;
    }
View Full Code Here

    return getSearcher().hasChanges(docid);
  }

  @Override
    public SearchResults search(Query query, int start, int limit, int scoringFunctionIndex, Map<String, String> extraParameters) throws InterruptedException {
        TopMatches matches = this.findMatches(query, start+limit, scoringFunctionIndex);
        Iterable<ScoredMatch> ids = matches;
       
        // apply pagination
        ids = SkippingIterable.skipping(ids, start);
        ids = CollectionsUtil.limit(ids, limit);
       
        // base transform function
        final Function<ScoredMatch, SearchResult> baseTransform = ScoredMatch.SEARCH_RESULT_FUNCTION;
        Function<ScoredMatch, SearchResult> transformFunction = baseTransform;
        String fetchCategories = extraParameters.get("fetch_categories");
        String fetchVariables = extraParameters.get("fetch_variables");

        // adds fetch variables to the transform function
        if ("*".equals(fetchVariables) || "true".equalsIgnoreCase(fetchVariables)) {
            transformFunction = new Function<ScoredMatch, SearchResult>() {
                @Override
                public SearchResult apply(ScoredMatch scoredMatch) {
                    SearchResult searchResult = baseTransform.apply(scoredMatch);
                    searchResult.setVariables(boostsManager.getVariablesAsMap(scoredMatch.getDocId()));
                    return searchResult;
                }
            };
        }

        // adds fetch categories to the transform function
        final Function<ScoredMatch, SearchResult> prevTransform = transformFunction;
        if ("*".equals(fetchCategories) || "true".equalsIgnoreCase(fetchCategories)) {
            transformFunction = new Function<ScoredMatch, SearchResult>() {
                @Override
                public SearchResult apply(ScoredMatch scoredMatch) {
                    SearchResult searchResult = prevTransform.apply(scoredMatch);
                    searchResult.setCategories(boostsManager.getCategoryValues(scoredMatch.getDocId()));
                    return searchResult;
                }
            };
        }
       
        // convert to search results
        Iterable<SearchResult> results = Iterables.transform(ids, transformFunction);       

        // fix'em in a list
        results = Lists.newArrayList(results);

        return new SearchResults(results, matches.getTotalMatches(), matches.getFacetingResults());
    }
View Full Code Here

        res2.addResult(0.9f, "2");
        res1.addResult(0.8f, "3");
        res2.addResult(0.7f, "4");
        res2.addResult(0.6f, "5");
        res1.addResult(0.5f, "6");
        TopMatches res = blender.findMatches(dummyQuery, 10, 0);
    assertEquals("Number of results doesn't match", res.getTotalMatches(), res1.getTotalMatches()+res2.getTotalMatches());
        int i = 0;
        for (ScoredMatch r : res) {
            assertEquals("blend out of order", r.getDocId().toString(), String.valueOf(++i));
        }
  }
View Full Code Here

    @TestInfo(testType=UNIT)
  public void testDedupIgnoresOldVersionEvenIfItHasHigherScore() throws ParseException, InterruptedException {
        res1.addResult(1.0,"1");
        res2.addResult(0.7,"1");

        TopMatches res = blender.findMatches(dummyQuery, 10, 0);
    assertEquals("Number of results doesn't match", res.getTotalMatches(), 1);

        assertEquals("Did not choose the freshest document",0.7, Lists.newArrayList(res).get(0).getScore());

    }
View Full Code Here

TOP

Related Classes of com.flaptor.indextank.index.TopMatches

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.