Package com.flaptor.indextank.query

Examples of com.flaptor.indextank.query.TermQuery


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

    private String traverseNode(QueryNode node, String queryString) {
        if (node instanceof TermQuery) {
            TermQuery termQuery = (TermQuery)node;
            String term = termQuery.getTerm();
           
            String suggestedTerm = suggestWord(term);
            if (suggestedTerm != null) {
                queryString = replaceSuggestion(queryString, term, suggestedTerm);
                if (queryString == null) {
                    return null;
                }
                termQuery.setTerm(suggestedTerm);
            }
           
        } else if (node instanceof SimplePhraseQuery) {
            SimplePhraseQuery phraseQuery = (SimplePhraseQuery) node;
           
View Full Code Here


    public void testSwitch() throws IOException, ParseException, InterruptedException {
      indexTwelveDocs(this.indexEngine.getIndexer());

        DocumentSearcher searcher = this.indexEngine.getSearcher();

        SearchResults srs = searcher.search(new Query(new TermQuery("text","term1"),null,null),0,10, 0);
    assertEquals("Number of historic results doesn't match", 1, srs.getMatches());
       
        srs = searcher.search(new Query(new TermQuery("text","term11"),null,null),0,10, 0);
    assertEquals("Number of real time results doesn't match", 1, srs.getMatches());

        Query query = new Query(this.indexEngine.getParser().parseQuery("term1 OR term2 OR term3 OR term4 OR term5"),null,null);
        srs = searcher.search(query,0,10, 0);
    assertEquals("Number of real time results doesn't match", 5, srs.getMatches());
View Full Code Here

      assertEquals("Number of actual results doesn't match", 33, ids.size());
      assertEquals("Number of different results doesn't match", 33, ids.elementSet().size());
    }
   
    private void checkResults(DocumentSearcher searcher, int start, int len, int[] expectedIds) throws InterruptedException {
        SearchResults srs = searcher.search(new Query(new TermQuery("text","fixed"),"fixed",null),start,len, 0);
        Set<Integer> expIds = Sets.newHashSet();
        for (int i : expectedIds) {
            expIds.add(i);
        }
        int n = 0;
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

    @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

        // have & signs before tokens, > signs between them, and < signs after.
        Document doc = new Document(ImmutableMap.of("text", "contains &&& signs >>>> and stuff <.", "title", "a headline!"));
    indexer.add(docid, doc, (int)timestampBoost, Maps.<Integer, Double>newHashMap());
   
        SearchResults srs = searcher.search(new Query(new AndQuery( new TermQuery("text", "signs"), new TermQuery("text", "stuff")), 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("signs not highlighted!", sr.getField("snippet_text").contains("<b>signs</b>"));
        assertTrue("ampersands not encoded!", sr.getField("snippet_text").contains("&amp;"));
View Full Code Here

        String text = "Clown Ferdinand und der Fu\u00dfball player";
        Document doc = new Document(ImmutableMap.of("text", text));
        indexer.add(docid, doc, (int)timestampBoost, Maps.<Integer, Double>newHashMap());

        String queryText = "fussball";
        Query query = new Query(new TermQuery("text", queryText), queryText, null);

        SearchResults srs = searcher.search(query, 0, 1, 0, ImmutableMap.of("snippet_fields", "text", "snippet_type", "html"));
        SearchResult sr = srs.getResults().iterator().next();
        String snippet = sr.getField("snippet_text");
        assertNotNull("Snippet is null", snippet);
View Full Code Here

    public void testFetchAll() throws IOException, InterruptedException {
    double timestampBoost = System.currentTimeMillis() / 1000.0;
        String docid = "docid";
        Document doc = new Document(ImmutableMap.of("text", "this is a sample text", "title", "a headline!"));
        indexer.add(docid, doc, (int)timestampBoost, Maps.<Integer, Double>newHashMap());
        SearchResults srs = searcher.search(new Query(new TermQuery("text","sample"),null,null),0,10, 0, ImmutableMap.of("fetch_fields", "*"));
        SearchResult sr = srs.getResults().iterator().next();
        assertEquals("document data modified. fetch_fields='*' should retrieve the same data.", sr.getFields(), doc.asMap());
    }
View Full Code Here

TOP

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

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.