@Test public void search() throws IOException, SQLException { Path tempDir = Files.createTempDirectory("foo"); CorpusDb storage = new CorpusDb(tempDir); Map<Integer, CorpusDocument> docMap = saveDocuments(storage); for (Integer key : docMap.keySet()) { CorpusDocument doc = docMap.get(key); List<String> paragraphs = Splitter.on("\n").splitToList(doc.content); List<String> sentences = TurkishSentenceExtractor.DEFAULT.fromParagraphs(paragraphs); storage.saveSentences(key, sentences); } List<SentenceSearchResult> searchResults = storage.search("milyar"); for (SentenceSearchResult searchResult : searchResults) { System.out.println(searchResult); } IOUtil.deleteTempDir(tempDir); }
public List<SentenceSearchResult> search(String text) { try (Connection connection = connectionPool.getConnection()) { String sql = "SELECT T.* FROM FT_SEARCH_DATA('" + text + "', 0, 0) FT, SENTENCE_TABLE T " + "WHERE FT.TABLE='SENTENCE_TABLE' AND T.ID=FT.KEYS[0];"; Statement stat = connection.createStatement(); ResultSet set = stat.executeQuery(sql); List<SentenceSearchResult> result = new ArrayList<>(); while (set.next()) { result.add(new SentenceSearchResult(set.getInt(1), set.getInt(2), set.getString(3))); } return result; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } }
CorpusDb { public List<SentenceSearchResult> search(String text) { try (Connection connection = connectionPool.getConnection()) { String sql = "SELECT T.* FROM FT_SEARCH_DATA('" + text + "', 0, 0) FT, SENTENCE_TABLE T " + "WHERE FT.TABLE='SENTENCE_TABLE' AND T.ID=FT.KEYS[0];"; Statement stat = connection.createStatement(); ResultSet set = stat.executeQuery(sql); List<SentenceSearchResult> result = new ArrayList<>(); while (set.next()) { result.add(new SentenceSearchResult(set.getInt(1), set.getInt(2), set.getString(3))); } return result; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } }
CorpusDb { public List<SentenceSearchResult> search(String text) { try (Connection connection = connectionPool.getConnection()) { String sql = "SELECT T.* FROM FT_SEARCH_DATA('" + text + "', 0, 0) FT, SENTENCE_TABLE T " + "WHERE FT.TABLE='SENTENCE_TABLE' AND T.ID=FT.KEYS[0];"; Statement stat = connection.createStatement(); ResultSet set = stat.executeQuery(sql); List<SentenceSearchResult> result = new ArrayList<>(); while (set.next()) { result.add(new SentenceSearchResult(set.getInt(1), set.getInt(2), set.getString(3))); } return result; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } CorpusDb(Path dbRoot); private  CorpusDb(JdbcConnectionPool connectionPool); }
CorpusDb { public List<SentenceSearchResult> search(String text) { try (Connection connection = connectionPool.getConnection()) { String sql = "SELECT T.* FROM FT_SEARCH_DATA('" + text + "', 0, 0) FT, SENTENCE_TABLE T " + "WHERE FT.TABLE='SENTENCE_TABLE' AND T.ID=FT.KEYS[0];"; Statement stat = connection.createStatement(); ResultSet set = stat.executeQuery(sql); List<SentenceSearchResult> result = new ArrayList<>(); while (set.next()) { result.add(new SentenceSearchResult(set.getInt(1), set.getInt(2), set.getString(3))); } return result; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } CorpusDb(Path dbRoot); private  CorpusDb(JdbcConnectionPool connectionPool); void addAll(List<CorpusDocument> docs); void generateTables(); void saveSentences(int docKey, List<String> sentences); List<SentenceSearchResult> search(String text); CorpusDocument loadDocumentByKey(int key); void addDocs(Path corpusFile); }
CorpusDb { public List<SentenceSearchResult> search(String text) { try (Connection connection = connectionPool.getConnection()) { String sql = "SELECT T.* FROM FT_SEARCH_DATA('" + text + "', 0, 0) FT, SENTENCE_TABLE T " + "WHERE FT.TABLE='SENTENCE_TABLE' AND T.ID=FT.KEYS[0];"; Statement stat = connection.createStatement(); ResultSet set = stat.executeQuery(sql); List<SentenceSearchResult> result = new ArrayList<>(); while (set.next()) { result.add(new SentenceSearchResult(set.getInt(1), set.getInt(2), set.getString(3))); } return result; } catch (Exception e) { e.printStackTrace(); throw new RuntimeException(e); } } CorpusDb(Path dbRoot); private  CorpusDb(JdbcConnectionPool connectionPool); void addAll(List<CorpusDocument> docs); void generateTables(); void saveSentences(int docKey, List<String> sentences); List<SentenceSearchResult> search(String text); CorpusDocument loadDocumentByKey(int key); void addDocs(Path corpusFile);  }