diff --git a/src/main/java/org/segrada/controller/SearchController.java b/src/main/java/org/segrada/controller/SearchController.java index e0dcc0e5..39b0b306 100644 --- a/src/main/java/org/segrada/controller/SearchController.java +++ b/src/main/java/org/segrada/controller/SearchController.java @@ -84,4 +84,18 @@ public Viewable index( } return new Viewable("search/index", model); } + + @GET + @Path("/in_document") + @Produces(MediaType.TEXT_HTML) + public Viewable searchInDocument( + @QueryParam("s") String term, + @QueryParam("id") String id + ) { + // create model map + Map model = new HashMap<>(); + model.put("hits", searchEngine.searchInDocument(term, id)); + + return new Viewable("search/in_document", model); + } } diff --git a/src/main/java/org/segrada/search/SearchEngine.java b/src/main/java/org/segrada/search/SearchEngine.java index 38f30618..a35a97d8 100644 --- a/src/main/java/org/segrada/search/SearchEngine.java +++ b/src/main/java/org/segrada/search/SearchEngine.java @@ -47,6 +47,14 @@ public interface SearchEngine { */ PaginationInfo search(String searchTerm, Map filters); + /** + * search within a document for certain terms and return list of highlighted hits + * @param searchTerm term(s) to search for + * @param id of document to search in + * @return list of highlighted hits or empty array + */ + String[] searchInDocument(String searchTerm, String id); + /** * Remove entity from index * diff --git a/src/main/java/org/segrada/search/lucene/LuceneSearchEngine.java b/src/main/java/org/segrada/search/lucene/LuceneSearchEngine.java index b3abe86c..5481713b 100644 --- a/src/main/java/org/segrada/search/lucene/LuceneSearchEngine.java +++ b/src/main/java/org/segrada/search/lucene/LuceneSearchEngine.java @@ -313,6 +313,43 @@ else if (searchFilters.size() > 1) { return new PaginationInfo<>(page, 1, 0, entriesPerPage, new LinkedList<>()); } + @Override + public String[] searchInDocument(String searchTerm, String id) { + // sanity check + if (searchTerm == null || id == null || searchTerm.isEmpty() || id.isEmpty()) return new String[]{}; + + try { + DirectoryReader iReader = DirectoryReader.open(directory); + IndexSearcher iSearcher = new IndexSearcher(iReader); + + // only search content + MultiFieldQueryParser parser = new MultiFieldQueryParser(Version.LUCENE_47, new String[]{"content"}, analyzer); + + // set operator and contain by id + parser.setDefaultOperator(QueryParser.Operator.AND); + Query query = parser.parse(searchTerm); + Filter filter = new QueryWrapperFilter(new TermQuery(new Term("id", id))); + + // do search, maximum of 1 document + TopDocs topDocs = iSearcher.search(query, filter, 1); + + if (topDocs.scoreDocs.length > 0) { + ScoreDoc scoreDoc = topDocs.scoreDocs[0]; + + // get highlighted text + FastVectorHighlighter highlighter = new FastVectorHighlighter(); + FieldQuery fieldQuery = highlighter.getFieldQuery(new QueryParser(Version.LUCENE_47, "content", analyzer).parse(searchTerm), iReader); + + // return max of 100 highlighted elements + return highlighter.getBestFragments(fieldQuery, iReader, scoreDoc.doc, "content", 100, 100); + } + } catch (Throwable e) { + logger.error("Error in search.", e); + } + + return new String[]{}; + } + @Override public synchronized void remove(String id) { try { diff --git a/src/main/java/org/segrada/service/repository/orientdb/OrientDbNodeRepository.java b/src/main/java/org/segrada/service/repository/orientdb/OrientDbNodeRepository.java index 12497616..0bd5c352 100644 --- a/src/main/java/org/segrada/service/repository/orientdb/OrientDbNodeRepository.java +++ b/src/main/java/org/segrada/service/repository/orientdb/OrientDbNodeRepository.java @@ -2,7 +2,6 @@ import com.google.inject.Inject; import com.orientechnologies.orient.core.record.impl.ODocument; -import com.orientechnologies.orient.core.sql.OCommandSQL; import com.orientechnologies.orient.core.sql.query.OSQLSynchQuery; import org.apache.lucene.index.Term; import org.apache.lucene.queryparser.flexible.standard.QueryParserUtil; diff --git a/src/main/resources/js/segrada.js b/src/main/resources/js/segrada.js index ec0d265b..2993d43b 100644 --- a/src/main/resources/js/segrada.js +++ b/src/main/resources/js/segrada.js @@ -502,6 +502,33 @@ } }); + // second type of data form (left side) + $("form.sg-simple-form", part).ajaxForm({ + beforeSubmit: function (arr, $form, options) { + // disable form elements + $(":input", $form).attr("disabled", true); + + // determine target to replace + var target = $form.attr('data-id'); + if (typeof target !== 'undefined') target = $('#' + target); + target = target || $form; + + target.html($('#sg-wait')); + + return true; + }, + success: function (responseText, statusText, xhr, $form) { + // determine target to replace + var target = $form.attr('data-id'); + if (typeof target !== 'undefined') target = $('#' + target); + target = target || $form; + + target.html(responseText); + + $(":input", $form).attr("disabled", false); + } + }); + // ******************************************************* // period handler $('.sg-periods').each(function() { diff --git a/src/main/resources/less/single/segrada.less b/src/main/resources/less/single/segrada.less index 276d76ce..7c5bd873 100644 --- a/src/main/resources/less/single/segrada.less +++ b/src/main/resources/less/single/segrada.less @@ -147,6 +147,13 @@ a.sg-data-icon { overflow: hidden; } +.sg-highlight-list div { + margin-bottom: 0.1ex; +} +.sg-highlight-list div:hover { + background: #eee; +} + /* Settings for icons */ img.sg-img-pictogram { width: 24px; diff --git a/src/main/webapp/WEB-INF/i18n/messages.properties b/src/main/webapp/WEB-INF/i18n/messages.properties index 6ccf942e..9ca5be8b 100644 --- a/src/main/webapp/WEB-INF/i18n/messages.properties +++ b/src/main/webapp/WEB-INF/i18n/messages.properties @@ -33,6 +33,7 @@ error.calendar.fromTo=Start date must not be after end date. error.calendar.incorrect=Date entry is not a correct date (try MM/DD/YYYY or MM/YYY or YYYY). error.double=This field has to be unique. error.entityNotFound=Entity not found! +error.nothingFound=Nothing found! error.notEmpty=Value must not be empty error.notNull=Value must not be empty error.rangeLatCoordinate=Coordinate must be between -90 and 90. @@ -162,4 +163,5 @@ Tags=Tags Tag=Tag Unlink=Delete connection Users=Users -User=User \ No newline at end of file +User=User +field.searchWithinDocument=Search within full text of document \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/i18n/messages_de.properties b/src/main/webapp/WEB-INF/i18n/messages_de.properties index 7e99d6cd..1f0752ed 100644 --- a/src/main/webapp/WEB-INF/i18n/messages_de.properties +++ b/src/main/webapp/WEB-INF/i18n/messages_de.properties @@ -33,6 +33,7 @@ error.calendar.fromTo=Startdatum darf nicht hinter Anfangsdatum liegen. error.calendar.incorrect=Datumseintrag ist nicht korrekt (Format sollte TT.MM.YYYY, MM.YYYY oder YYYY sein). error.double=Feldinhalt muss einzigartig sein. error.entityNotFound=Datensatz wurde nicht gefunden! +error.nothingFound=Nichts gefunden! error.notEmpty=Wert darf nicht leer sein. error.notNull=Wert darf nicht leer sein. error.rangeLatCoordinate=Koordinate muss zwischen -180 und 180 liegen. @@ -162,4 +163,5 @@ Tags=Tags Tag=Tag Unlink=Verkn\u00FCpfung l\u00F6schen User=Benutzer -Users=Benutzer \ No newline at end of file +Users=Benutzer +field.searchWithinDocument=Innerhalb des Dokuments suchen \ No newline at end of file diff --git a/src/main/webapp/WEB-INF/templates/file/show.html b/src/main/webapp/WEB-INF/templates/file/show.html index aaa313a8..e63100d1 100644 --- a/src/main/webapp/WEB-INF/templates/file/show.html +++ b/src/main/webapp/WEB-INF/templates/file/show.html @@ -58,6 +58,20 @@

+
+
+ + +
+ + +
+ +
+
+ +
+
diff --git a/src/main/webapp/WEB-INF/templates/search/in_document.html b/src/main/webapp/WEB-INF/templates/search/in_document.html new file mode 100644 index 00000000..e6e158b3 --- /dev/null +++ b/src/main/webapp/WEB-INF/templates/search/in_document.html @@ -0,0 +1,25 @@ + + + + + + Search +
+ + + +
+ +
+
+
+
+
+ +
+
+ + + \ No newline at end of file diff --git a/src/main/webapp/css/segrada.css b/src/main/webapp/css/segrada.css index a205fad7..15c49f09 100644 --- a/src/main/webapp/css/segrada.css +++ b/src/main/webapp/css/segrada.css @@ -1 +1 @@ -body{margin-top:2em}.form-group{margin-bottom:0}.twitter-typeahead{width:100%}.sg-margin-bottom{margin-bottom:1em}.sg-margin-top{margin-top:1em}.sg-margin-bottom-sm{margin-bottom:.5em}.sg-margin-top-sm{margin-top:.5em}.sg-disabled{z-index:1000;background-color:lightgrey;opacity:.6;pointer-events:none}.browserupgrade{margin:.2em 0;background:#ccc;color:#000;padding:.2em 0}div.sg-fileupload-small .file-preview-frame{height:auto;width:160px}div.sg-fileupload-small .file-caption-name{padding-right:0!important;width:auto!important}.sg-pictogram-modal-link{display:block;padding:15px 0;width:100%}.sg-pictogram-modal-link img{display:block}.col-xs-1.sg-no-padding-right{padding-right:0}.sg-dynamic-data{padding:1em;margin-bottom:.5em;border:2px solid #e5e5e5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.sg-headbox-right{float:right;margin:-1em -0.6em 0 0;display:none}a.btn-link{color:#000;opacity:.5;filter:alpha(opacity=50)}a.btn-link:hover,a.btn-link:focus{color:#000;opacity:.8;filter:alpha(opacity=80)}.sg-data-icon-bar{white-space:nowrap}a.sg-data-icon{padding-left:.15em;color:#000;font-size:16px;font-weight:bold;opacity:.2;filter:alpha(opacity=20)}a.sg-data-icon:hover,a.sg-data-icon:focus{color:#000;text-decoration:none;cursor:pointer;opacity:.5;filter:alpha(opacity=50)}.sg-headbox-right a{padding:.25em;float:right;font-size:21px;line-height:1}.sg-data-taglist span{margin-right:.25em}.sg-tag-show{cursor:pointer}.sg-tag-show:hover,.sg-tag-show:focus{opacity:.5;filter:alpha(opacity=50)}.sg-headbox-info{padding:.25em;color:#000;opacity:.2;filter:alpha(opacity=20);font-size:13px;line-height:31px}.sg-data-content{margin-top:1em}.sg-description{margin-top:20px}.sg-map{height:400px;width:100%}.sg-stop-flow{overflow:hidden}img.sg-img-pictogram{width:24px;height:24px;vertical-align:baseline}span.sg-color-icon{width:24px;height:24px;display:inline-block}.label a{color:#fff;text-decoration:none} \ No newline at end of file +body{margin-top:2em}.form-group{margin-bottom:0}.twitter-typeahead{width:100%}.sg-margin-bottom{margin-bottom:1em}.sg-margin-top{margin-top:1em}.sg-margin-bottom-sm{margin-bottom:.5em}.sg-margin-top-sm{margin-top:.5em}.sg-disabled{z-index:1000;background-color:lightgrey;opacity:.6;pointer-events:none}.browserupgrade{margin:.2em 0;background:#ccc;color:#000;padding:.2em 0}div.sg-fileupload-small .file-preview-frame{height:auto;width:160px}div.sg-fileupload-small .file-caption-name{padding-right:0!important;width:auto!important}.sg-pictogram-modal-link{display:block;padding:15px 0;width:100%}.sg-pictogram-modal-link img{display:block}.col-xs-1.sg-no-padding-right{padding-right:0}.sg-dynamic-data{padding:1em;margin-bottom:.5em;border:2px solid #e5e5e5;-webkit-border-radius:4px;-moz-border-radius:4px;border-radius:4px}.sg-headbox-right{float:right;margin:-1em -0.6em 0 0;display:none}a.btn-link{color:#000;opacity:.5;filter:alpha(opacity=50)}a.btn-link:hover,a.btn-link:focus{color:#000;opacity:.8;filter:alpha(opacity=80)}.sg-data-icon-bar{white-space:nowrap}a.sg-data-icon{padding-left:.15em;color:#000;font-size:16px;font-weight:bold;opacity:.2;filter:alpha(opacity=20)}a.sg-data-icon:hover,a.sg-data-icon:focus{color:#000;text-decoration:none;cursor:pointer;opacity:.5;filter:alpha(opacity=50)}.sg-headbox-right a{padding:.25em;float:right;font-size:21px;line-height:1}.sg-data-taglist span{margin-right:.25em}.sg-tag-show{cursor:pointer}.sg-tag-show:hover,.sg-tag-show:focus{opacity:.5;filter:alpha(opacity=50)}.sg-headbox-info{padding:.25em;color:#000;opacity:.2;filter:alpha(opacity=20);font-size:13px;line-height:31px}.sg-data-content{margin-top:1em}.sg-description{margin-top:20px}.sg-map{height:400px;width:100%}.sg-stop-flow{overflow:hidden}.sg-highlight-list div{margin-bottom:.1ex}.sg-highlight-list div:hover{background:#eee}img.sg-img-pictogram{width:24px;height:24px;vertical-align:baseline}span.sg-color-icon{width:24px;height:24px;display:inline-block}.label a{color:#fff;text-decoration:none} \ No newline at end of file diff --git a/src/main/webapp/js/segrada.min.js b/src/main/webapp/js/segrada.min.js index cd60d4b5..3f3b22ee 100644 --- a/src/main/webapp/js/segrada.min.js +++ b/src/main/webapp/js/segrada.min.js @@ -1 +1 @@ -(function(h){var i=new Bloodhound({datumTokenizer:function(l){return Bloodhound.tokenizers.whitespace(l.title)},queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{wildcard:"%QUERY",url:urlSegradaTagSearch+"%QUERY"}});var a=new Bloodhound({datumTokenizer:function(l){return Bloodhound.tokenizers.whitespace(l.title)},queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{url:urlSegradaNodeSearch,replace:function(m,n){var o=m+n;var l=h(".sg-node-search").filter(":focus");var q=h("#"+l.attr("data-select-id")+" option").filter(":selected");var p=q.attr(l.attr("data-attr"));if(p!=null&&p.length>0){o+="&tags="+encodeURIComponent(p)}return o}}});var c=new Bloodhound({datumTokenizer:function(l){return Bloodhound.tokenizers.whitespace(l.title)},queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{wildcard:"%QUERY",url:urlSegradaFileSearch+"%QUERY"}});var f=new Bloodhound({datumTokenizer:function(l){return Bloodhound.tokenizers.whitespace(l.title)},queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{wildcard:"%QUERY",url:urlSegradaSourceSearch+"%QUERY"}});var g=(typeof google==="object"&&typeof google.maps==="object")?new google.maps.Geocoder():null;h.fn.onEnter=function(l){this.bind("keypress",function(m){if(m.keyCode==13){l.apply(this,[m])}});return this};var b=new RegExp(/<([^\s]+).*?id="([^"]*?)".*?>/i);function j(q,p,o,l,n){var m=urlSegradaPictogramSearch+encodeURIComponent(n);h.getJSON(m,function(s){var r=[];h.each(s,function(t,u){var v=h("
").text(u.title).html();r.push('
'+v+'
')});p.html("
"+r.join("")+"
");h("a",p).click(function(w){var v=h(this).attr("data-id");var u=h(this).attr("data-uid");var t=h("
").text(h(this).attr("title")).html();h("#value-"+o,l).val(v);h("#preview-"+o,l).html(''+t+' '+t);h("#clear-"+o,l).show();w.preventDefault();q.modal("hide")})})}function k(l){l=l||h("body");h(".sg-data").addClass("sg-dynamic-data");h(".sg-headbox-right").show();h(".sg-dynamic-hide").hide();h(".sg-data-add",l).click(function(m){h.get(h(this).attr("href"),function(q){var p=q.match(b);if(p!=null&&p.length>=2){h("#"+p[2]).remove()}var o=h("#sg-data");o.prepend(q);var n=o.children(":first");k(n);h("html, body").animate({scrollTop:n.offset().top},500)});m.preventDefault()});h(".sg-control-form",l).ajaxForm({beforeSubmit:function(m,o,p){var q=o.attr("data-target-id");if(typeof q=="undefined"||q==null||q.length==0){q="#sg-control"}var n=h(q);n.wrapInner("
");n.prepend(h("#sg-wait").html());return true},success:function(o,q,r,n){var p=n.attr("data-target-id");if(typeof p=="undefined"||p==null||p.length==0){p="#sg-control"}var m=h(p);m.html(o);k(m)}});h(".sg-control-set",l).click(function(p){var o=h(this);var n=o.attr("data-target-id");if(typeof n=="undefined"||n==null||n.length==0){n="#sg-control"}var m=h(n);m.wrapInner("
");m.prepend(h("#sg-wait").html());h.get(o.attr("href"),function(q){m.html(q);k(m)});p.preventDefault()});h("[data-data-dblclick]",l).dblclick(function(){h.get(h(this).attr("data-data-dblclick"),function(p){var o=p.match(b);if(o!=null&&o.length>=2){h("#"+o[2]).remove()}var n=h("#sg-data");n.prepend(p);var m=n.children(":first");k(m);h("html, body").animate({scrollTop:m.offset().top},500)})});h("tr [data-confirm]",l).click(function(n){var m=h(this);if(confirm(m.attr("data-confirm"))){var o=m.closest("tr");o.addClass("sg-disabled");h.get(m.attr("href"),function(p){o.slideUp("fast",function(){o.remove()})})}n.preventDefault()});h(".sg-replace-content",l).on("shown.bs.tab",function(o){var n=h(h(this).attr("href"));var m=h(this).attr("data-url");h.get(m,function(p){n.html(p);k(n)});h(this).removeClass("sg-replace-content");h(this).unbind("shown.bs.tab")});h(".sg-data-close",l).click(function(m){h(this).parent().parent().fadeOut("fast",function(){h(this).remove()})});h("input.sg-fileupload",l).fileinput({showUpload:false});h("input.sg-fileupload-small",l).fileinput({showUpload:false,previewSettings:{image:{width:"auto",height:"24px"}}});h(".sg-pictogram-modal").on("shown.bs.modal",function(){var p=h(this);var o=p.attr("id");var n=h("#container-"+o,p);var m=h("#filter-"+o,p);m.on("input propertychange paste",function(){j(p,n,o,l,h(this).val())}).onEnter(function(){var r=h(".sg-pictogram-modal-link",n).first();if(r.length>0){var t=r.attr("data-id");var s=r.attr("data-id");var q=h("
").text(r.attr("title")).html();h("#value-"+o,l).val(t);h("#preview-"+o,l).html(''+q+' '+q);h("#clear-"+o,l).show();p.modal("hide")}});if(m.val()===""){j(p,n,o,l,"")}});h(".sg-pictogram-chooser",l).click(function(m){h("#"+h(this).attr("data-id")).modal("show");m.preventDefault()});h(".sg-pictogram-clearer",l).click(function(n){var m=h(this).attr("data-id");h("#value-"+m,l).val("");h("#preview-"+m,l).html("");h(this).hide();n.preventDefault()});h(".sg-source-ref-modal").on("shown.bs.modal",function(){var o=h(this);var n=o.attr("id");var m=h(".modal-body",o);h.get(o.attr("data-href"),function(p){m.html(p);h("form",m).ajaxForm({beforeSubmit:function(q,r,s){r.wrapInner("
");r.prepend(h("#sg-wait").html());return true},success:function(r,t,u,q){var s=h(o.attr("data-target"));s.html(r);k(s);o.modal("hide")}})})}).on("hidden.bs.modal",function(){h(".modal-body",h(this)).html(h("#sg-wait").html())});h(".sg-source-ref-editor",l).click(function(n){var m=h("#"+h(this).attr("data-id"));m.attr("data-href",h(this).attr("href"));m.modal("show");n.preventDefault()});h(".sg-taglist-contract",l).each(function(){var m=h("span",h(this));if(m.length>1){m.hide().filter(":first-child").show().after('');h("span.sg-tag-show",h(this)).click(function(){h(this).remove();m.show()})}});h("select.sg-colorpicker",l).simplepicker({theme:"fontawesome"});h("select.sg-tags",l).tagsinput({trimValue:true,confirmKeys:[13],typeaheadjs:{name:"tags",displayKey:"title",valueKey:"title",source:i.ttAdapter()}});h("input.sg-node-search",l).each(function(){var n=h(this);var m=h("#"+n.attr("data-id"));n.typeahead({hint:true,highlight:true,minLength:1},{name:"node",displayKey:"title",valueKey:"id",source:a.ttAdapter()}).bind("typeahead:selected",function(p,o){m.val(o.id)}).bind("keyup",function(){if(!this.value){m.val("")}})});h("input.sg-file-search",l).each(function(){var n=h(this);var m=h("#"+n.attr("data-id"));n.typeahead({hint:true,highlight:true,minLength:1},{name:"file",displayKey:"title",valueKey:"id",source:c.ttAdapter()}).bind("typeahead:selected",function(p,o){m.val(o.id)}).bind("keyup",function(){if(!this.value){m.val("")}})});h("input.sg-source-search",l).each(function(){var n=h(this);var m=h("#"+n.attr("data-id"));n.typeahead({hint:true,highlight:true,minLength:1},{name:"source",displayKey:"title",valueKey:"id",source:f.ttAdapter()}).bind("typeahead:selected",function(p,o){m.val(o.id)}).bind("keyup",function(){if(!this.value){m.val("")}})});h(".sg-link-external").click(function(o){var m=h(this).attr("href");var n=window.open(m,"_blank");n.focus();o.preventDefault()});h("form.sg-data-form",l).ajaxForm({beforeSubmit:function(m,n,o){h(":input",n).attr("disabled",true);return true},success:function(o,q,r,m){var p=m.attr("data-id");if(typeof p!=="undefined"){p=h("#"+p)}p=p||m;p.replaceWith(o);var n=o.match(b);if(n!=null&&n.length>=2){k(h("#"+n[2]))}}});h(".sg-periods").each(function(){var m=h(this);var o=m.attr("id");var n=h(".sg-period-form",m);h(".sg-period-add",m).click(function(p){h(this).hide();n.show();p.preventDefault()});h(".sg-period-form-period",m).change(function(p){if(h(this).is(":checked")){h(".sg-period-toggle",m).show()}else{h(".sg-period-toggle",m).hide()}});n.ajaxForm({beforeSubmit:function(p,q,r){m.addClass("disabled");return true},success:function(q,r,s,p){m.replaceWith(q);k(m)}})});h(".sg-geotab",l).on("shown.bs.tab",function(r){var q=h(r.target);if(q.attr("data-created")=="1"){return}q.attr("data-created","1");var s=q.attr("data-locations-id");var n=h(s);var p=h(".sg-map-form",n);var o=h(".sg-geocomplete",p);var m=new google.maps.LatLng(0,0);o.geocomplete({map:s+"-map",details:s+"-form",markerOptions:{draggable:true},mapOptions:{mapTypeId:google.maps.MapTypeId.HYBRID,zoom:1,center:m,scrollwheel:true,draggable:true}}).bind("geocode:result",function(u,t){h("input[type=submit]",p).show()}).bind("geocode:dragged",function(u,t){h("input[name=lat]",p).val(t.lat());h("input[name=lng]",p).val(t.lng())});h(".sg-map-add-marker",n).click(function(t){h(this).hide();p.show();t.preventDefault()});d(s,h(s+"-markers",n),o);h(s+"-map").on("destroyed",function(){if(typeof e[s]!=="undefined"){for(var t=0;t"+h(this).attr("data-lat")+","+h(this).attr("data-lng")+'

'+p+"

"});var s=new google.maps.Marker({position:t,map:q,icon:"https://maps.google.com/mapfiles/ms/micons/blue-dot.png"});google.maps.event.addListener(s,"click",function(){v.open(q,s);var w=h("#"+u);w.unbind("click");w.click(function(x){h.get(h(this).attr("href"),function(y){m.replaceWith(y);d(r,h(r+"-markers"),l)});x.preventDefault()})});e[r][e[r].length]=s});if(e[r].length==0){q.setZoom(1);q.setCenter(new google.maps.LatLng(0,0))}else{q.fitBounds(o)}}h.event.special.destroyed={remove:function(l){if(l.handler){l.handler()}}};h(document).ready(function(){h("#sg-close-all").click(function(l){h(".sg-data").fadeOut("fast",function(){h(this).remove()});l.preventDefault()});h(".sg-locale").click(function(l){h.get(h(this).attr("href"),function(n){var m=h("#sg-base").html();if(n!=""){window.location.href=m}});l.preventDefault()});i.initialize();k(h("body"))})})(jQuery); \ No newline at end of file +(function(h){var i=new Bloodhound({datumTokenizer:function(l){return Bloodhound.tokenizers.whitespace(l.title)},queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{wildcard:"%QUERY",url:urlSegradaTagSearch+"%QUERY"}});var a=new Bloodhound({datumTokenizer:function(l){return Bloodhound.tokenizers.whitespace(l.title)},queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{url:urlSegradaNodeSearch,replace:function(m,n){var o=m+n;var l=h(".sg-node-search").filter(":focus");var q=h("#"+l.attr("data-select-id")+" option").filter(":selected");var p=q.attr(l.attr("data-attr"));if(p!=null&&p.length>0){o+="&tags="+encodeURIComponent(p)}return o}}});var c=new Bloodhound({datumTokenizer:function(l){return Bloodhound.tokenizers.whitespace(l.title)},queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{wildcard:"%QUERY",url:urlSegradaFileSearch+"%QUERY"}});var f=new Bloodhound({datumTokenizer:function(l){return Bloodhound.tokenizers.whitespace(l.title)},queryTokenizer:Bloodhound.tokenizers.whitespace,remote:{wildcard:"%QUERY",url:urlSegradaSourceSearch+"%QUERY"}});var g=(typeof google==="object"&&typeof google.maps==="object")?new google.maps.Geocoder():null;h.fn.onEnter=function(l){this.bind("keypress",function(m){if(m.keyCode==13){l.apply(this,[m])}});return this};var b=new RegExp(/<([^\s]+).*?id="([^"]*?)".*?>/i);function j(q,p,o,l,n){var m=urlSegradaPictogramSearch+encodeURIComponent(n);h.getJSON(m,function(s){var r=[];h.each(s,function(t,u){var v=h("
").text(u.title).html();r.push('
'+v+'
')});p.html("
"+r.join("")+"
");h("a",p).click(function(w){var v=h(this).attr("data-id");var u=h(this).attr("data-uid");var t=h("
").text(h(this).attr("title")).html();h("#value-"+o,l).val(v);h("#preview-"+o,l).html(''+t+' '+t);h("#clear-"+o,l).show();w.preventDefault();q.modal("hide")})})}function k(l){l=l||h("body");h(".sg-data").addClass("sg-dynamic-data");h(".sg-headbox-right").show();h(".sg-dynamic-hide").hide();h(".sg-data-add",l).click(function(m){h.get(h(this).attr("href"),function(q){var p=q.match(b);if(p!=null&&p.length>=2){h("#"+p[2]).remove()}var o=h("#sg-data");o.prepend(q);var n=o.children(":first");k(n);h("html, body").animate({scrollTop:n.offset().top},500)});m.preventDefault()});h(".sg-control-form",l).ajaxForm({beforeSubmit:function(m,o,p){var q=o.attr("data-target-id");if(typeof q=="undefined"||q==null||q.length==0){q="#sg-control"}var n=h(q);n.wrapInner("
");n.prepend(h("#sg-wait").html());return true},success:function(o,q,r,n){var p=n.attr("data-target-id");if(typeof p=="undefined"||p==null||p.length==0){p="#sg-control"}var m=h(p);m.html(o);k(m)}});h(".sg-control-set",l).click(function(p){var o=h(this);var n=o.attr("data-target-id");if(typeof n=="undefined"||n==null||n.length==0){n="#sg-control"}var m=h(n);m.wrapInner("
");m.prepend(h("#sg-wait").html());h.get(o.attr("href"),function(q){m.html(q);k(m)});p.preventDefault()});h("[data-data-dblclick]",l).dblclick(function(){h.get(h(this).attr("data-data-dblclick"),function(p){var o=p.match(b);if(o!=null&&o.length>=2){h("#"+o[2]).remove()}var n=h("#sg-data");n.prepend(p);var m=n.children(":first");k(m);h("html, body").animate({scrollTop:m.offset().top},500)})});h("tr [data-confirm]",l).click(function(n){var m=h(this);if(confirm(m.attr("data-confirm"))){var o=m.closest("tr");o.addClass("sg-disabled");h.get(m.attr("href"),function(p){o.slideUp("fast",function(){o.remove()})})}n.preventDefault()});h(".sg-replace-content",l).on("shown.bs.tab",function(o){var n=h(h(this).attr("href"));var m=h(this).attr("data-url");h.get(m,function(p){n.html(p);k(n)});h(this).removeClass("sg-replace-content");h(this).unbind("shown.bs.tab")});h(".sg-data-close",l).click(function(m){h(this).parent().parent().fadeOut("fast",function(){h(this).remove()})});h("input.sg-fileupload",l).fileinput({showUpload:false});h("input.sg-fileupload-small",l).fileinput({showUpload:false,previewSettings:{image:{width:"auto",height:"24px"}}});h(".sg-pictogram-modal").on("shown.bs.modal",function(){var p=h(this);var o=p.attr("id");var n=h("#container-"+o,p);var m=h("#filter-"+o,p);m.on("input propertychange paste",function(){j(p,n,o,l,h(this).val())}).onEnter(function(){var r=h(".sg-pictogram-modal-link",n).first();if(r.length>0){var t=r.attr("data-id");var s=r.attr("data-id");var q=h("
").text(r.attr("title")).html();h("#value-"+o,l).val(t);h("#preview-"+o,l).html(''+q+' '+q);h("#clear-"+o,l).show();p.modal("hide")}});if(m.val()===""){j(p,n,o,l,"")}});h(".sg-pictogram-chooser",l).click(function(m){h("#"+h(this).attr("data-id")).modal("show");m.preventDefault()});h(".sg-pictogram-clearer",l).click(function(n){var m=h(this).attr("data-id");h("#value-"+m,l).val("");h("#preview-"+m,l).html("");h(this).hide();n.preventDefault()});h(".sg-source-ref-modal").on("shown.bs.modal",function(){var o=h(this);var n=o.attr("id");var m=h(".modal-body",o);h.get(o.attr("data-href"),function(p){m.html(p);h("form",m).ajaxForm({beforeSubmit:function(q,r,s){r.wrapInner("
");r.prepend(h("#sg-wait").html());return true},success:function(r,t,u,q){var s=h(o.attr("data-target"));s.html(r);k(s);o.modal("hide")}})})}).on("hidden.bs.modal",function(){h(".modal-body",h(this)).html(h("#sg-wait").html())});h(".sg-source-ref-editor",l).click(function(n){var m=h("#"+h(this).attr("data-id"));m.attr("data-href",h(this).attr("href"));m.modal("show");n.preventDefault()});h(".sg-taglist-contract",l).each(function(){var m=h("span",h(this));if(m.length>1){m.hide().filter(":first-child").show().after('');h("span.sg-tag-show",h(this)).click(function(){h(this).remove();m.show()})}});h("select.sg-colorpicker",l).simplepicker({theme:"fontawesome"});h("select.sg-tags",l).tagsinput({trimValue:true,confirmKeys:[13],typeaheadjs:{name:"tags",displayKey:"title",valueKey:"title",source:i.ttAdapter()}});h("input.sg-node-search",l).each(function(){var n=h(this);var m=h("#"+n.attr("data-id"));n.typeahead({hint:true,highlight:true,minLength:1},{name:"node",displayKey:"title",valueKey:"id",source:a.ttAdapter()}).bind("typeahead:selected",function(p,o){m.val(o.id)}).bind("keyup",function(){if(!this.value){m.val("")}})});h("input.sg-file-search",l).each(function(){var n=h(this);var m=h("#"+n.attr("data-id"));n.typeahead({hint:true,highlight:true,minLength:1},{name:"file",displayKey:"title",valueKey:"id",source:c.ttAdapter()}).bind("typeahead:selected",function(p,o){m.val(o.id)}).bind("keyup",function(){if(!this.value){m.val("")}})});h("input.sg-source-search",l).each(function(){var n=h(this);var m=h("#"+n.attr("data-id"));n.typeahead({hint:true,highlight:true,minLength:1},{name:"source",displayKey:"title",valueKey:"id",source:f.ttAdapter()}).bind("typeahead:selected",function(p,o){m.val(o.id)}).bind("keyup",function(){if(!this.value){m.val("")}})});h(".sg-link-external").click(function(o){var m=h(this).attr("href");var n=window.open(m,"_blank");n.focus();o.preventDefault()});h("form.sg-data-form",l).ajaxForm({beforeSubmit:function(m,n,o){h(":input",n).attr("disabled",true);return true},success:function(o,q,r,m){var p=m.attr("data-id");if(typeof p!=="undefined"){p=h("#"+p)}p=p||m;p.replaceWith(o);var n=o.match(b);if(n!=null&&n.length>=2){k(h("#"+n[2]))}}});h("form.sg-simple-form",l).ajaxForm({beforeSubmit:function(m,n,o){h(":input",n).attr("disabled",true);var p=n.attr("data-id");if(typeof p!=="undefined"){p=h("#"+p)}p=p||n;p.html(h("#sg-wait"));return true},success:function(n,p,q,m){var o=m.attr("data-id");if(typeof o!=="undefined"){o=h("#"+o)}o=o||m;o.html(n);h(":input",m).attr("disabled",false)}});h(".sg-periods").each(function(){var m=h(this);var o=m.attr("id");var n=h(".sg-period-form",m);h(".sg-period-add",m).click(function(p){h(this).hide();n.show();p.preventDefault()});h(".sg-period-form-period",m).change(function(p){if(h(this).is(":checked")){h(".sg-period-toggle",m).show()}else{h(".sg-period-toggle",m).hide()}});n.ajaxForm({beforeSubmit:function(p,q,r){m.addClass("disabled");return true},success:function(q,r,s,p){m.replaceWith(q);k(m)}})});h(".sg-geotab",l).on("shown.bs.tab",function(r){var q=h(r.target);if(q.attr("data-created")=="1"){return}q.attr("data-created","1");var s=q.attr("data-locations-id");var n=h(s);var p=h(".sg-map-form",n);var o=h(".sg-geocomplete",p);var m=new google.maps.LatLng(0,0);o.geocomplete({map:s+"-map",details:s+"-form",markerOptions:{draggable:true},mapOptions:{mapTypeId:google.maps.MapTypeId.HYBRID,zoom:1,center:m,scrollwheel:true,draggable:true}}).bind("geocode:result",function(u,t){h("input[type=submit]",p).show()}).bind("geocode:dragged",function(u,t){h("input[name=lat]",p).val(t.lat());h("input[name=lng]",p).val(t.lng())});h(".sg-map-add-marker",n).click(function(t){h(this).hide();p.show();t.preventDefault()});d(s,h(s+"-markers",n),o);h(s+"-map").on("destroyed",function(){if(typeof e[s]!=="undefined"){for(var t=0;t"+h(this).attr("data-lat")+","+h(this).attr("data-lng")+'

'+p+"

"});var s=new google.maps.Marker({position:t,map:q,icon:"https://maps.google.com/mapfiles/ms/micons/blue-dot.png"});google.maps.event.addListener(s,"click",function(){v.open(q,s);var w=h("#"+u);w.unbind("click");w.click(function(x){h.get(h(this).attr("href"),function(y){m.replaceWith(y);d(r,h(r+"-markers"),l)});x.preventDefault()})});e[r][e[r].length]=s});if(e[r].length==0){q.setZoom(1);q.setCenter(new google.maps.LatLng(0,0))}else{q.fitBounds(o)}}h.event.special.destroyed={remove:function(l){if(l.handler){l.handler()}}};h(document).ready(function(){h("#sg-close-all").click(function(l){h(".sg-data").fadeOut("fast",function(){h(this).remove()});l.preventDefault()});h(".sg-locale").click(function(l){h.get(h(this).attr("href"),function(n){var m=h("#sg-base").html();if(n!=""){window.location.href=m}});l.preventDefault()});i.initialize();k(h("body"))})})(jQuery); \ No newline at end of file diff --git a/src/test/java/org/segrada/search/lucene/LuceneSearchEngineTest.java b/src/test/java/org/segrada/search/lucene/LuceneSearchEngineTest.java index 305d50b8..d0f6574b 100644 --- a/src/test/java/org/segrada/search/lucene/LuceneSearchEngineTest.java +++ b/src/test/java/org/segrada/search/lucene/LuceneSearchEngineTest.java @@ -304,4 +304,32 @@ public void testDoubleAdd() throws Exception { SearchHit hit = searchResult.entities.get(0); assertEquals("Hello World 2", hit.getTitle()); // should be second title which has been saved } + + @Test + public void testSearchInDocument() throws Exception { + // index + searchEngine.index("4", "DummyClass", "Hello World", "Another Title\nAnd my subtitle", + "Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut " + + "x labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo " + + "dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor " + + "sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod " + + "tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et " + + "accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus " + + "est Lorem ipsum dolor sit amet.", new String[]{}, null, null, 1.0f); + + // assert null and empty values + assertEquals(0, searchEngine.searchInDocument("", "").length); + assertEquals(0, searchEngine.searchInDocument(null, null).length); + assertEquals(0, searchEngine.searchInDocument("", null).length); + assertEquals(0, searchEngine.searchInDocument(null, "").length); + + // now check normal operation + assertEquals(0, searchEngine.searchInDocument("notExistant", "4").length); + + String[] highlights = searchEngine.searchInDocument("labore", "4"); + + assertEquals(2, highlights.length); + assertEquals("elitr, sed diam nonumy eirmod tempor invidunt ut x labore et dolore magna aliquyam erat, sed diam voluptua", highlights[0]); + assertEquals("elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua", highlights[1]); + } } \ No newline at end of file