public List<InteractionOntologyTerm> search(String strQuery) throws IOException, ParseException { return search(strQuery, new StandardAnalyzer(Version.LUCENE_30)); }
public InteractionOntologyTerm findByName(String value) throws IOException, ParseException { if (value == null || value.trim().length() == 0) return null; if (!value.startsWith("\"")) { value = "\"" + value + "\""; } InteractionOntologyTerm term = null; Collection<InteractionOntologyTerm> terms = searchByName(value, new WhitespaceAnalyzer(Version.LUCENE_30)); if (!terms.isEmpty()) { term = terms.iterator().next(); } return term; }
private InteractionOntologyTerm createOntologyTerm(Document document, Highlighter highlighter) throws IOException { String identifier = document.getFieldable("identifier").stringValue(); String label = document.getFieldable("label").stringValue(); String databaseLabel = document.getFieldable("databaseLabel").stringValue(); String fieldName = document.getFieldable("fieldName").stringValue(); int count = Integer.parseInt(document.getField("count").stringValue()); if (isHighlight()) { label = highlightText("label", label, highlighter); } InteractionOntologyTerm term = new InteractionOntologyTerm(label, identifier); term.setResults(new InteractionOntologyTermResults(databaseLabel, fieldName, count)); return term; }
public List<InteractionOntologyTerm> search(Query query, Sort sort) throws IOException { List<InteractionOntologyTerm> terms = new ArrayList<InteractionOntologyTerm>(); IndexReader indexReader = IndexReader.open(indexDirectory); final IndexSearcher searcher = new IndexSearcher(indexReader); Filter filter = new Filter() { @Override public DocIdSet getDocIdSet(IndexReader indexReader) throws IOException { final DocIdBitSet bitSet = new DocIdBitSet(new BitSet()); bitSet.getBitSet().flip(0, searcher.getIndexReader().numDocs()); return bitSet; } }; final TopDocs hits = searcher.search(query, filter, 30, sort); Formatter formatter = new SimpleHTMLFormatter(); Highlighter highlighter = new Highlighter(formatter, new QueryScorer(query) ); highlighter.setTextFragmenter(new SimpleFragmenter(20)); for (ScoreDoc scoreDoc : hits.scoreDocs) { Document document = searcher.getIndexReader().document(scoreDoc.doc); InteractionOntologyTerm term = createOntologyTerm(document, highlighter); terms.add(term); } searcher.close(); return terms; }
public InteractionOntologyTerm findById(String value) throws IOException, ParseException { if (value == null || value.trim().length() == 0) return null; if (!value.startsWith("\"")) { value = "\"" + value + "\""; } InteractionOntologyTerm term = null; Collection<InteractionOntologyTerm> terms = search(value, new WhitespaceAnalyzer(Version.LUCENE_30)); if (!terms.isEmpty()) { term = terms.iterator().next(); } return term; }
public List<InteractionOntologyTerm> search(String strQuery, Analyzer analyzer) throws IOException, ParseException { QueryParser queryParser = new QueryParser(Version.LUCENE_30, "identifier", analyzer); return search(queryParser.parse(strQuery), new Sort(new SortField("count", SortField.INT, true))); }
public List<InteractionOntologyTerm> searchByName(String strQuery, Analyzer analyzer) throws IOException, ParseException { QueryParser queryParser = new QueryParser(Version.LUCENE_30, "label", analyzer); return search(queryParser.parse(strQuery), new Sort(new SortField("count", SortField.INT, true))); }