Mercurial Hosting > junotu
changeset 10:66d3fdffc3d2
Display search query in window title
author | Fox |
---|---|
date | Fri, 08 Apr 2022 12:27:07 +0200 |
parents | dd51276f95a2 |
children | 587b69a38915 |
files | src/junotu/Database.java src/junotu/TabSimpleSearch.java |
diffstat | 2 files changed, 35 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/junotu/Database.java Fri Apr 08 12:09:57 2022 +0200 +++ b/src/junotu/Database.java Fri Apr 08 12:27:07 2022 +0200 @@ -3,6 +3,8 @@ import java.lang.RuntimeException; import java.io.File; +import org.apache.lucene.queryParser.ParseException; + import org.apache.lucene.index.IndexWriter; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.store.Directory; @@ -207,16 +209,25 @@ { String[] split = query.split( " " ); + + Query queryTitle; + Query queryContent; - Query queryTitle = new QueryParser( + try { + /* TODO: FIXME: Don't use advanced QueryParser for simple search. */ + queryTitle = new QueryParser( + LUCENE_VERSION, + TAG_TITLE, + new StandardAnalyzer(LUCENE_VERSION)).parse(query); + queryContent = new QueryParser( LUCENE_VERSION, - TAG_TITLE, + TAG_CONTENT, new StandardAnalyzer(LUCENE_VERSION)).parse(query); - Query queryContent = new QueryParser( - LUCENE_VERSION, - TAG_CONTENT, - new StandardAnalyzer(LUCENE_VERSION)).parse(query); - + } catch( ParseException e ) { + System.out.print( "Search query parsing exception, returning zero results.\n" ); + return new Card[0]; + } + BooleanQuery queryFinal = new BooleanQuery(); queryFinal.add( queryTitle, BooleanClause.Occur.SHOULD );
--- a/src/junotu/TabSimpleSearch.java Fri Apr 08 12:09:57 2022 +0200 +++ b/src/junotu/TabSimpleSearch.java Fri Apr 08 12:27:07 2022 +0200 @@ -73,16 +73,19 @@ @Override public void changedUpdate( DocumentEvent e ) { + updateTitle(); search(); } @Override public void removeUpdate( DocumentEvent e ) { + updateTitle(); search(); } @Override public void insertUpdate( DocumentEvent e ) { + updateTitle(); search(); } } @@ -116,6 +119,20 @@ results.validate(); results.repaint(); } + + private void updateTitle() + { + Window window = (Window)this.getTopLevelAncestor(); + + String text = field.getText(); + + if( text.length() > 0 ) { + window.setTitle( window.preferredTitle( "Search: "+text ) ); + } else { + window.setTitle( window.preferredTitle( "Search" ) ); + } + + } private void buttonClickedCreate() {