Package com.flaptor.indextank.query

Examples of com.flaptor.indextank.query.Query


        // 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);
        assertTrue("Search term not highlighted", snippet.contains("<b>Fu&szlig;ball</b>"));
        assertTrue("Snippet lost space before highlighted term", snippet.contains("der "));
        assertTrue("Snippet lost space after highlighted term: " + snippet, snippet.contains(" player"));

        query = new Query(new PrefixTermQuery("text", "fu"), "fu*", null);

        srs = searcher.search(query, 0, 1, 0, ImmutableMap.of("snippet_fields", "text", "snippet_type", "html"));
        sr = srs.getResults().iterator().next();
        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

        IndexingDumpCompletionListener idcl = new IndexingDumpCompletionListener(this.lsi,docs);
        idcl.start();
        this.lsi.startDump(idcl);
        idcl.waitUntilCompleted();

        assertEquals("Checkpoint made it to the index", 0, lsi.findMatches(new Query(new TermQuery("documentId","checkpoint_doc"),null,null),1, 1).getTotalMatches());
        assertEquals("First doc didn't make it to the index", 1, lsi.findMatches(new Query(new TermQuery("documentId","first_doc"),null,null),1, 1).getTotalMatches());
        // TODO test there is only one thing on the index.
       
        this.lsi.startDump(new DummyDumpCompletionListener());
        assertEquals("Checkpoint didn't make it to the index", 1, lsi.findMatches(new Query(new TermQuery("documentId","checkpoint_doc"),null,null),1, 1).getTotalMatches());
        assertEquals("First doc didn't make it to the index", 1, lsi.findMatches(new Query(new TermQuery("documentId","first_doc"),null,null),1, 1).getTotalMatches());
        // TODO test that there are limit + 2 documents on the index

  }
View Full Code Here

        IndexingDumpCompletionListener idcl = new IndexingDumpCompletionListener(this.lsi,docs);
        idcl.start();
        this.lsi.startDump(idcl);
        idcl.waitUntilCompleted();
       
        assertEquals("Bad Apple made it to the index", 0, lsi.findMatches(new Query(new TermQuery("pepe","badapple"),null,null),1, 0).getTotalMatches());

        Execute.sleep(1000);
        docs = Lists.newArrayList();
        idcl = new IndexingDumpCompletionListener(this.lsi,docs);
        idcl.start();
        this.lsi.startDump(idcl);
        idcl.waitUntilCompleted();

        assertEquals("I expected just ONE bad apple", 1, lsi.findMatches(new Query(new TermQuery("pepe","badapple"),null,null),1, 0).getTotalMatches());
        assertEquals("I expected one document that matched version:latest", 1, lsi.findMatches(new Query(new TermQuery("version","latest"),null,null),1, 0).getTotalMatches());
       
    }
View Full Code Here

    private Query dummyQuery;

    @Override
  protected void setUp() throws Exception {
        super.setUp();
        dummyQuery = new Query(new TermQuery("foo", "bar"),null,null);
        res1 = new MockSearchResults();
        res2 = new MockSearchResults();
        LargeScaleIndex lsi = new LargeScaleIndexStub(res1);
        RealTimeIndex rti = new RealTimeIndexStub(res2, 100);
        blender = new Blender(lsi,rti, new NoSuggestor(), new DummyPromoter(), new DummyBoostsManager());
View Full Code Here

  protected void setUp() throws Exception {
    parser = new IndexEngineParser("text");
  }
 
  public Query query(String queryStr) throws ParseException {
    return new Query(parser.parseQuery(queryStr),queryStr,null);
  }
View Full Code Here

        long t = System.currentTimeMillis() / 1000;
        for (int i = 0; i < 100; i++) {
            index(i, t+i);
        }
       
        Query q = new Query(this.indexEngine.getParser().parseQuery("text"),null,null);
        SearchResults rs = this.indexEngine.getSearcher().search(q, 0, 100, 0);
       
        Iterable<SearchResult> results = rs.getResults();
       
        int n = 99;
View Full Code Here

        doc = new Document(ImmutableMap.of("relevance_test", "Twinkle you better work or else I'll hack you"));     
        indexer.add("2", doc, 1, ImmutableMap.<Integer, Double>of());
        doc = new Document(ImmutableMap.of("relevance_test", "Twinkle you better work"));     
        indexer.add("3", doc, 2, ImmutableMap.<Integer, Double>of());
       
        Query q = new Query(this.indexEngine.getParser().parseQuery("relevance_test:twinkle"),null,null);

        checkResults("Relevance", searcher, q, 1, new String[] {"1","3","2"});
    }
View Full Code Here

    public void testCaretQueries() throws InterruptedException, ParseException, Exception {
        DocumentSearcher searcher = this.indexEngine.getSearcher();
        BoostingIndexer indexer = this.indexEngine.getIndexer();
        indexer.addScoreFunction(1, "relevance");
        Document doc;
        Query query;

        doc = new Document(ImmutableMap.of("text", "aaa"));
        indexer.add("1", doc, 0, ImmutableMap.<Integer, Double>of());

        doc = new Document(ImmutableMap.of("text", "aaa bbb"));
        indexer.add("2", doc, 0, ImmutableMap.<Integer, Double>of());

        doc = new Document(ImmutableMap.of("text", "aaa aaa bbb"));
        indexer.add("3", doc, 0, ImmutableMap.<Integer, Double>of());

        doc = new Document(ImmutableMap.of("text", "aaa bbb ccc eee"));
        indexer.add("4", doc, 0, ImmutableMap.<Integer, Double>of());

        doc = new Document(ImmutableMap.of("text", "ccc ddd"));
        indexer.add("5", doc, 0, ImmutableMap.<Integer, Double>of());

        query = new Query(indexEngine.getParser().parseQuery("aaa"),null,null);
        checkResults("Caret", searcher, query, 1, new String[] {"1","3","2","4"});

        query = new Query(indexEngine.getParser().parseQuery("aaa AND bbb"),null,null);
        checkResults("Caret", searcher, query, 1, new String[] {"2","3","4"});

        query = new Query(indexEngine.getParser().parseQuery("aaa OR bbb"),null,null);
        checkResults("Caret", searcher, query, 1, new String[] {"2","3","1","4"});

        query = new Query(indexEngine.getParser().parseQuery("aaa^2 OR bbb"),null,null);
        checkResults("Caret", searcher, query, 1, new String[] {"3","2","1","4"});

        query = new Query(indexEngine.getParser().parseQuery("aaa OR bbb^2"),null,null);
        checkResults("Caret", searcher, query, 1, new String[] {"2","3","4","1"});

        query = new Query(indexEngine.getParser().parseQuery("ccc OR ddd"),null,null);
        checkResults("Caret", searcher, query, 1, new String[] {"5","4"});

        query = new Query(indexEngine.getParser().parseQuery("ccc OR ddd OR eee^2"),null,null);
        checkResults("Caret", searcher, query, 1, new String[] {"4","5"});

    }
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.