Package com.flaptor.indextank.query

Examples of com.flaptor.indextank.query.Query


        this.npi = suggestor.getPopularityIndex();
        this.dictAutomaton = NewPopularityIndex.PopularityIndexAutomaton.adapt(this.npi);
    }

    public List<Pair<Query, String>> suggest(Query query) {
        Query newQuery = query.duplicate();
       
        String newOriginal = traverseNode(newQuery.getRoot(), newQuery.getOriginalStr());
       
        if (newQuery.equals(query)) {
            return Lists.newArrayList();
        }

        return Lists.newArrayList(new Pair<Query, String>(newQuery, newOriginal));
    }
View Full Code Here


     
      return results;
  }

  private Query generateQuery(String str, int start, int len, QueryVariables vars, Multimap<String, String> facetsFilter, MatchFilter rangeFilters) throws ParseException {
        return new Query(parser.parseQuery(str), str, vars, facetsFilter, rangeFilters);
    }
View Full Code Here

        }

        public ResultSet search(String queryStr, int start, int len, int scoringFunctionIndex, Map<Integer, Double> queryVariables, List<CategoryFilter> facetsFilter, List<RangeFilter> variableRangeFilters, List<RangeFilter> functionRangeFilters, Map<String,String> extraParameters) throws IndextankException, InvalidQueryException, MissingQueryVariableException {
            logger.debug("Searching: start: " + start + ", len: " + len +", query: \"" + queryStr + "\"");
            try {
                Query query = generateQuery(queryStr,start,len, QueryVariablesImpl.fromMap(queryVariables), convertToMultimap(facetsFilter), new IntersectionMatchFilter(convertToVariableRangeFilter(variableRangeFilters), convertToFunctionRangeFilter(functionRangeFilters)));
                ResultSet resultSet = toResultSet(this.searcher.search(query, start, len, scoringFunctionIndex, extraParameters));
                logger.info("Search found " + resultSet.get_matches() + " results - start: " + start + ", len: " + len +", query: \"" + queryStr + "\"");
                return resultSet;
            } catch (NoSuchQueryVariableException e) {
                if (logger.isDebugEnabled()) {
View Full Code Here

    @Override
        public int count(String queryStr) throws IndextankException {
            logger.debug("Counting: query: \"" + queryStr + "\"");
            try {
                Query query = generateQuery(queryStr,0,1,null, ImmutableMultimap.<String, String>of(), VariablesRangeFilter.NO_FILTER);
                int count = this.searcher.countMatches(query);
                logger.info("Counted " + count + " for query: \"" + queryStr + "\"");
                return count;
            } catch (ParseException pe) {
                if (logger.isDebugEnabled()){
View Full Code Here

       
        @Override
        public int size() throws IndextankException {
            try {
                logger.debug("Fetching size");
                Query query = new Query(new MatchAllQuery(),null,null);
                int size = this.searcher.countMatches(query);
                logger.info("Fetched size: " + size);
                return size;
            } catch (RuntimeException e) {
                logger.error("RuntimeException while processing size. Will throw an IndexTankException. Original Exception is:", e);
View Full Code Here

    @TestInfo(testType=SYSTEM)
    public void testFacetedSearch() throws InterruptedException {
      indexForwardFacetedToDocuments(this.indexEngine.getIndexer());
        DocumentSearcher searcher = this.indexEngine.getSearcher();
       
        SearchResults searchResults = searcher.search(new Query(new TermQuery("text","a"),"a",null), 0, 10, 0);
       
        Map<String, Multiset<String>> facets = searchResults.getFacets();
       
        //System.out.println("Matches: " + searchResults.getMatches());
        //System.out.println(facets);
       
        assertEquals(2, facets.keySet().size());
       
        Multiset<String> precioFacet = facets.get("PRECIO");
    
        assertEquals(2, precioFacet.elementSet().size());
        assertEquals(2, precioFacet.count("ALTO"));
        assertEquals(3, precioFacet.count("BAJO"));
       
        Multiset<String> tipoFacet = facets.get("TIPO");
       
        assertEquals(2, tipoFacet.elementSet().size());
        assertEquals(3, tipoFacet.count("NAH"));
        assertEquals(2, tipoFacet.count("SI"));
       
       
        searchResults = searcher.search(new Query(new TermQuery("text","b"),"b",null), 0, 10, 0);
       
        facets = searchResults.getFacets();
       
        //System.out.println("Matches: " + searchResults.getMatches());
        //System.out.println(facets);
View Full Code Here

    @TestInfo(testType=SYSTEM)
    public void testBackwardsFacetedSearch() throws InterruptedException {
      indexBackwardsFacetedToDocuments(this.indexEngine.getIndexer());
        DocumentSearcher searcher = this.indexEngine.getSearcher();
       
        SearchResults searchResults = searcher.search(new Query(new TermQuery("text","a"),"a",null), 0, 10, 0);
       
        Map<String, Multiset<String>> facets = searchResults.getFacets();
       
        //System.out.println("Matches: " + searchResults.getMatches());
        //System.out.println(facets);
       
        assertEquals(2, facets.keySet().size());
       
        Multiset<String> precioFacet = facets.get("PRECIO");
    
        assertEquals(2, precioFacet.elementSet().size());
        assertEquals(2, precioFacet.count("ALTO"));
        assertEquals(3, precioFacet.count("BAJO"));
       
        Multiset<String> tipoFacet = facets.get("TIPO");
       
        assertEquals(2, tipoFacet.elementSet().size());
        assertEquals(3, tipoFacet.count("NAH"));
        assertEquals(2, tipoFacet.count("SI"));
       
       
        searchResults = searcher.search(new Query(new TermQuery("text","b"),"b",null), 0, 10, 0);
       
        facets = searchResults.getFacets();
       
        //System.out.println("Matches: " + searchResults.getMatches());
        //System.out.println(facets);
View Full Code Here

       
        Multimap<String, String> categoriesFilter = HashMultimap.create();
       
        categoriesFilter.put("PRECIO", "BAJO");
       
    SearchResults searchResults = searcher.search(new Query(indexEngine.getParser().parseQuery("a OR b"),"a OR b", null, categoriesFilter, VariablesRangeFilter.NO_FILTER), 0, 10, 0);
   
    int matches = searchResults.getMatches();
    Map<String, Multiset<String>> facets = searchResults.getFacets();
    //System.out.println(matches);
    //System.out.println(searchResults.getResults());
    //System.out.println(searchResults.getFacets());
   
    assertEquals(4, matches);
    checkSearchResults(searchResults.getResults(), new String[] {"D6", "D5", "D2", "D1"});
   
    categoriesFilter = HashMultimap.create();
   
    categoriesFilter.put("TIPO", "NAH");
    categoriesFilter.put("TIPO", "TERCERO");
   
    searchResults = searcher.search(new Query(indexEngine.getParser().parseQuery("a OR b"),"a OR b", null, categoriesFilter, VariablesRangeFilter.NO_FILTER), 0, 10, 0);
   
    matches = searchResults.getMatches();
    //System.out.println(matches);
    //System.out.println(searchResults.getResults());
    //System.out.println(searchResults.getFacets());

    assertEquals(5, matches);
    checkSearchResults(searchResults.getResults(), new String[] {"D8", "D7", "D5", "D3", "D1"});

    categoriesFilter = HashMultimap.create();
   
    categoriesFilter.put("TIPO", "NAH");
    categoriesFilter.put("TIPO", "TERCERO");
    categoriesFilter.put("PRECIO", "BAJO");
   
    searchResults = searcher.search(new Query(indexEngine.getParser().parseQuery("a OR b"),"a OR b", null, categoriesFilter, VariablesRangeFilter.NO_FILTER), 0, 10, 0);
   
    matches = searchResults.getMatches();
    //System.out.println(matches);
    //System.out.println(searchResults.getResults());
    //System.out.println(searchResults.getFacets());
View Full Code Here

    @TestInfo(testType=SYSTEM)
    public void testSnippet() throws IOException, ParseException, InterruptedException {
      indexVeryBigDoc();
      long t = System.currentTimeMillis();
        SearchResults srs = searcher.search(new Query(new TermQuery("text","term29925"),null,null),0,10, 0, ImmutableMap.of("snippet_fields", "text"));
        srs.getResults().iterator().next();
        long dt = System.currentTimeMillis() - t;
        //this test is ignored since it fails on some machines
        //assertTrue("Snippetting took too long: " + dt + "ms. and the limit was 300ms.", dt < 300);
    }
View Full Code Here

    double timestampBoost = System.currentTimeMillis() / 1000.0;
        String docid = "docid";
        Document doc = new Document(ImmutableMap.of("text", multipleLines(), "title", "a headline!"));
    indexer.add(docid, doc, (int)timestampBoost, Maps.<Integer, Double>newHashMap());

        SearchResults srs = searcher.search(new Query(new TermQuery("text", "term29925"), null, null), 0, 10, 0, ImmutableMap.of("snippet_fields", "text", "snippet_type", "lines"));
        SearchResult sr = srs.getResults().iterator().next();
        assertNotNull("sr is null!", sr);
        assertTrue("line does not start on linestart!", sr.getField("snippet_text").startsWith("linestart"));
        assertEquals("line does not end on a newline!", sr.getField("snippet_text").charAt(sr.getField("snippet_text").length()-1), '\n');
    }
View Full Code Here

TOP

Related Classes of com.flaptor.indextank.query.Query

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.