Package com.flaptor.indextank.index

Examples of com.flaptor.indextank.index.Document


            throw new IllegalArgumentException("snippet_type has to be either 'html' or 'lines'");
        }
       
        if (fetchFields.length + snippetFields.length > 0) {
          for (SearchResult result : results.getResults()) {
            Document data = storage.getDocument(result.getDocId());


            // fetch fields
            for (String field : fetchFields) {
                    // handle '*', as a fetch all
                    if ("*".equals(field.trim())){
                        // assume we get the actual fields, not a copy.
                        result.getFields().putAll(data.asMap());
                        break;
                    }
                    String text = data.getField(field);
                    if (null != text) {
                        result.setField(field, text);
                    }
        }

            // snippet fields
            for (String field : snippetFields) {
                    String text = data.getField(field);
                    if (null != text) {
                        result.setField("snippet_" + field, sn.snippet(positiveTerms, field, text));
                    }
            }
          }
View Full Code Here


      InMemoryStorage ims = new InMemoryStorage(new File(args[0]), true);
     
        Scanner in = new Scanner(System.in);
       
        while (in.hasNextLine()) {
            Document document = ims.getDocument(in.nextLine());
            System.out.println(document);
        }

  }
View Full Code Here

  }

    private static void testCorrectness(String[] args) throws IOException {
        InMemoryStorage storage = new InMemoryStorage(FileUtil.createTempDir("testInMemoryStorage", ".tmp"), false);
        Document doc1 = new Document();
        doc1.setField("text", args[0]);
        storage.saveDocument("a", doc1);
        Document dd1 = storage.getDocument("a");
        Preconditions.checkState(dd1.equals(doc1), dd1 + " - " + doc1);
        Document doc2 = new Document();
        doc2.setField("nottext", args[0]);
        storage.saveDocument("b", doc2);
        Document dd2 = storage.getDocument("b");
        Preconditions.checkState(dd2.equals(doc2), dd2);
        Document doc3 = new Document();
        doc3.setField("text", args[0]);
        doc3.setField("f1", "v1");
        doc3.setField("f2", "v2");
        storage.saveDocument("c", doc3);
        Document dd3 = storage.getDocument("c");
        Preconditions.checkState(dd3.equals(doc3), dd3);
    }
View Full Code Here

        fields.put("text", text);
    }
    while (fs-- > 0) {
      fields.put(readUTF(is), readUTF(is));
    }
    return new Document(fields);
  }
View Full Code Here

    }
   
  private void indexVeryBigDoc() {
    double timestampBoost = System.currentTimeMillis() / 1000.0;
    String docId = "docid";
    Document doc = new Document(ImmutableMap.of("text", largeText()));
    indexer.add(docId, doc, (int)timestampBoost, Maps.<Integer, Double>newHashMap());
  }
View Full Code Here

   
    @TestInfo(testType=UNIT)
    public void testCompleteLines() throws IOException, InterruptedException {
    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);
View Full Code Here

    public void testEncodesHTMLonEnd() throws IOException, InterruptedException {
    double timestampBoost = System.currentTimeMillis() / 1000.0;
        String docid = "docid";

        // 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();
View Full Code Here

        String docid = "docid";
        // \u00df is 'LATIN SMALL LETTER SHARP S'
        // ASCIIFoldingFilter converts it from 'ß' to 'ss'
        // see http://www.fileformat.info/info/unicode/char/df/index.htm
        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);
View Full Code Here

    @TestInfo(testType=UNIT)
    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

    }
   
    @TestInfo(testType=TestType.UNIT)
    public void testTextOnlyDocument() throws InterruptedException, IOException {
        InMemoryStorage storage = new InMemoryStorage(FileUtil.createTempDir("testInMemoryStorage", ".tmp"), false);
        Document doc1 = new Document();
        doc1.setField("text", text);
        storage.saveDocument("a", doc1);
        Document dd1 = storage.getDocument("a");
        assertEquals("document retrieved didn't match document stored", doc1, dd1);
    }
View Full Code Here

TOP

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

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.