Commit b10b9757 authored by Jerome Chauveau's avatar Jerome Chauveau
Browse files

maj recherche : sélection recherche simple/multiple

parent 6d7e6740
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -37,3 +37,13 @@ div.hit {
  color: #ff8822;
  font-weight: bold;
}

input[type=radio]{
    margin: 0 5px 0px 10px;
}
#modeWrap{
    margin-bottom : 10px;
}
#searchSelect{
    margin : 20px auto;
}
 No newline at end of file
+19 −4
Original line number Diff line number Diff line
import {Plugin} from '../../core/ui/js/Plugin.js';

const ALL_TXT_SEARCH = 'all_txt';


class SearchPlugin extends Plugin{
    constructor(name) {
     super(name);
     this.searchModeChanged();
  }
  
  
@@ -22,6 +26,16 @@ class SearchPlugin extends Plugin{
      );  
   }

   searchModeChanged(){
        this.searchMode = document.querySelector('input[name="searchMode"]:checked').value;
        if(this.searchMode === ALL_TXT_SEARCH){
            document.getElementById('searchSelect').classList.add('d-none');
        }
        else {
            document.getElementById('searchSelect').classList.remove('d-none');
        }
   }
   
   
   
  /*
@@ -34,10 +48,11 @@ class SearchPlugin extends Plugin{
      return;
    }
    $("#searchLoading").show();
    let doc = $('#searchSelect').val();

    let docs = $('#searchSelect').val();
    let transform = $('#searchTransform').prop('checked') ?'yes' : 'no'

    this.runSearch(search, doc, transform, $("#searchResults"));
    this.runSearch(search, this.searchMode === ALL_TXT_SEARCH ? [] : docs, transform, $("#searchResults"));
    
  }

+29 −21
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@ import module namespace max.i18n = 'pddn/max/i18n' at '../../rxq/i18n.xqm';

declare variable $max.plugin.search:PLUGIN_ID := "search";
declare variable $max.plugin.search:ALL_TXT := "all_txt";
declare variable $max.plugin.search:SELECTION := "selection";

(:Plugin parameters  - should be defined in MAX CONFIGURATION FILE:)
declare variable $max.plugin.search:TAG_PARAMETER := "tag";
@@ -20,8 +21,8 @@ declare
%rest:path("/{$project}/search")
function max.plugin.search:searchPage($project){
  let $routeList := for $d in collection( max.config:getProjectDBPath($project)) return base-uri($d) (:max.route:HTMLRouteList($project)//a/@href :)
  let $routeSelect := <select id='searchSelect'>{
    <option value='{$max.plugin.search:ALL_TXT}'>Dans tous les textes</option>,
  let $routeSelect := <select class='form-control' id='searchSelect' multiple='true'>{
(:    <option value='{$max.plugin.search:ALL_TXT}'>Dans tous les textes</option>,:)
    for $route in $routeList
    return 
        let $docName := if(contains($route,'/page/'))(:dirty hack for pager href:)
@@ -41,7 +42,12 @@ function max.plugin.search:searchPage($project){
               $project,
               "search",
               <div id="searchWrap">
                 <div id='searchForm'>{$routeSelect}
                 <div id='searchForm'>
                     <div id='modeWrap'>
                      <input type="radio" onchange="window.search.searchModeChanged()" value="{$max.plugin.search:ALL_TXT}" name="searchMode" checked="checked"/>Dans tous les textes
                      <input type="radio" onchange="window.search.searchModeChanged()" value="{$max.plugin.search:SELECTION}" name="searchMode"/>Une séléction de textes
                     </div>
                     {$routeSelect}
                   <input id= 'searchInput' type='text'/>
                   <input type="checkbox" id="searchTransform"/> Transformer
                   <button onclick="search.runSearchFromForm();">Chercher</button>
@@ -79,19 +85,21 @@ declare
%rest:POST
%output:method("html")
%rest:query-param("search", "{$search}")
%rest:query-param("docs", "{$docs}")
%rest:query-param("docs[]", "{$docs}")
%rest:path("/{$project}/search")
function max.plugin.search:search($project,$search, $docs){
function max.plugin.search:search($project,$search, $docs as item()*){
  let $plugin := max.config:getPluginByName($project, $max.plugin.search:PLUGIN_ID)
  let $tag := string($plugin//parameter[@key=$max.plugin.search:TAG_PARAMETER]/@value)
  let $dbPath := max.config:getProjectDBPath($project)
  
  let $docList := 
    if($docs = $max.plugin.search:ALL_TXT)
      then for $d in collection($dbPath) return base-uri($d)
    else $docs  
    if(count($docs) > 0(: = $max.plugin.search:ALL_TXT:))
      then $docs
    else for $d in collection($dbPath) return base-uri($d)

  for $docPath in $docList
    let $res := for $h in doc($docPath)//*[local-name(.)=$tag]
    let $res :=
        for $h in doc($docPath)//*[local-name(.)=$tag]
        let $hits :=
            for $hit in ft:mark($h[.//text() contains text {$search}])
              let $path := replace($docPath, $dbPath||"/", '')
@@ -105,7 +113,7 @@ function max.plugin.search:search($project,$search, $docs){

        let $xsltDoc := max.util:buildXSLTDoc(max.config:getDefaultTextXSL($project),())

      return if ($docs = $max.plugin.search:ALL_TXT) then
        return  (admin:write-log('MaX DEBUG - SEARCH in '||$docPath||': ' ||$search),if ($docs = $max.plugin.search:ALL_TXT) then
               if ($res != '') then xslt:transform(
               <div class='hits'>
                 <details>
@@ -120,7 +128,7 @@ function max.plugin.search:search($project,$search, $docs){
                 <summary>{$docPath}</summary>
                 {$res}
               </details>
              </div>, $xsltDoc, ())
              </div>, $xsltDoc, ()))
};