Commit 7edc4b45 authored by Anne Goloubkoff-Duponchel's avatar Anne Goloubkoff-Duponchel Committed by Jerome Chauveau
Browse files

Ajout de la recherche simple dans le plugin ead_search

parent 0b754398
Loading
Loading
Loading
Loading
+114 −5
Original line number Diff line number Diff line
@@ -13,6 +13,21 @@
    padding:0
}

section.browse section p,  section.browse section ul{
    line-height: 1.3;
   
}

section.browse section p {
    margin-bottom: 2px;
    margin-top:7px;
}

section.browse section ul{
    margin: 0px;
}


.ead-search-ul li {
    display: inline-block;
    margin-left:5px;
@@ -26,8 +41,8 @@
    display :inline-block;
    border: none;
    background-color: none;
    padding: 5px;
    margin-left: 5px;
    padding: 4px;
    margin: 0px 0px 0px 7px;
    color: red;
    cursor : pointer;
}
@@ -37,11 +52,17 @@
    min-width: 200px;
}

#ead-search-date-wrap{
section#ead-search-section #ead-search-date-wrap{
    border-top: 1px solid #ccc;
    margin-top:10px;
    padding-top:10px;
    width: 70%;
}

section#ead-search-section #ead-search-date-wrap div{
margin:10px;
}

#ead-search-date-wrap div span{
    display :inline-block;
    min-width: 50px;
@@ -49,6 +70,26 @@

#ead-search-results {
    border-top: 1px solid #888;
    margin-bottom:51px;
}

#ead-search-results section{
    width: 66%;
    min-width: 700px;
    margin-bottom:66px;
}

#searchLoading{
    padding-top: 20px;
    display:none;
    text-align: center;
    position: absolute;

  }

div.boutonSearch button {
    margin-left: 365px;
  
}

.ead-search-popup-wrap{
@@ -79,8 +120,8 @@
    align-items: center;
    max-width: 32px;
    max-height: 32px;
    min-width: 32px;
    min-height: 32px;

    padding: 3px 6px;
}

.ead-search-popup ul {
@@ -91,6 +132,7 @@

.ead-search-popup ul li{
    cursor: pointer;
    line-height: 1.2;
}

.ead-search-popup ul li:hover{
@@ -126,3 +168,70 @@
    color: black;
    font-weight: bold;
}

section.browse section#ead-search-section div#ead-search-simple {
    border-bottom: 1px solid #888;
    padding-bottom: 3px;
    border-top: 1px solid #888;
    padding-top: 3px;
    margin-top:10px;
    margin-left:0px;
    margin-bottom:10px;
}


section#ead-search-section ul li {
    line-height: 1.5;
}

section#ead-search-section div {
    margin: 0px;
}

section#ead-search-section div.ead-search-popup-alphabet {
    margin: 10px;
    padding-left:5px;
}



section.browse .ead-search {
    margin-top: 17em;
    margin-left: 24px;
}

input[type="text"] {
    padding: 6px 10px;
    margin: 8px 0;
    border: 1px solid #ccc;
    background-size: 18px;
}

input[type="text"][id="searchInput"] {
    padding: 6px 33px;
background: transparent url("loupe.png") no-repeat 10px 4px;
background-size: 18px;
}

button {
    border: 1px solid #ccc;
    padding: 6px 15px;
    margin: 8px 0;
}

section.porte-documents button {
    padding: 3px 6px;
}

button.iconeListe {
    padding: 18px 15px;
    margin: 8px 0;
    border: none;
    background: transparent url("liste.png") no-repeat 6px 4px;
background-size: 21px;
}

section#ead-search-section div.contexte {
    margin: 3px 0px 2px 9px;
    line-height: 1.3;
}
 No newline at end of file
+32 −5
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ class EadSearchPlugin extends Plugin{
                document.getElementById('ead-search-date-from').removeAttribute('disabled');
                document.getElementById('ead-search-date-to').removeAttribute('disabled')
            }

        })
        this.bindIndexAutocompletes();
     }
@@ -234,7 +233,13 @@ class EadSearchPlugin extends Plugin{
   }

  runEadSearch(){
      //pour ne pas que les résultats précédents restent affichés, on vide le contenu html
    let resultsDiv = document.querySelector("#ead-search-results");
	while (resultsDiv.firstChild) {
		resultsDiv.removeChild(resultsDiv.firstChild);
	}
        let query = 'resultats.html';
        document.querySelector("#searchLoading").style.display = "block";
        let filtered = false;
        Object.keys(this.filters).forEach((k,i) => {
            query+= (i===0 ? '?' : '&') + 'indexes[]=' + k;
@@ -261,15 +266,37 @@ class EadSearchPlugin extends Plugin{
                query+=(!filtered ? "?" : "&") + "in="+dateIn
            }
        }

       fetch(query).then(res => res.text()).then(text => {
        document.getElementById('ead-search-results').innerHTML = text
       }).then(function() {
		document.querySelector("#searchLoading").style.display = "none";    	
    })
 
  }

  runEadSimpleSearch() {
    var simpleSearch = document.querySelector('#searchInput').value;
    //pour ne pas que les résultats précédents restent affichés, on vide le contenu html
    let resultsDiv = document.querySelector("#ead-search-results");
	while (resultsDiv.firstChild) {
		resultsDiv.removeChild(resultsDiv.firstChild);
	}
	if(simpleSearch.trim() === ''){
		alert('Recherche vide ou incorrecte.');
		return;
    }
    document.querySelector("#searchLoading").style.display = "block";
    let query = 'resultatsSimple.html?search='+simpleSearch;
    query = baseURI + projectId + '/' +query;
    
    fetch(query).then(res => res.text()).then(text => {
        document.getElementById('ead-search-results').innerHTML = text
       }).then(function() {
		document.querySelector("#searchLoading").style.display = "none";    	
    })

  buildFtIndex(){
    //fetch(this.baseURL + )
  }

 }

let eadSearch = new EadSearchPlugin('EadSearchPlugin')
+66 −12
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import module namespace max.config = 'pddn/max/config' at '../../rxq/config.xqm'
import module namespace max.html = 'pddn/max/html' at '../../rxq/html.xqm';
import module namespace max = 'pddn/max' at '../../max.xq';
import module namespace max.util = 'pddn/max/util' at '../../rxq/util.xqm';
import module namespace max.i18n = 'pddn/max/i18n' at '../../rxq/i18n.xqm';


declare %private function max.plugin.ead_search:getSearchConfiguration($project){
@@ -18,7 +19,18 @@ declare
%rest:path("/{$project}/rechercher.html")
function max.plugin.ead_search:searchPage($project){
    let $dbPath := max.config:getProjectDBPath($project)
    let $simpleSearch := 
        <section>
    <p>La recherche peut se faire de deux manières indépendantes : </p><ul><li>soit par une recherche en plein texte,</li> <li>soit par une recherche multicritère (dont fait partie la recherche par année de production).</li></ul>
    <p>On ne peut croiser ces deux types de recherche.</p>
        <div id="ead-search-simple">
            <label>Recherche plein texte </label>
            <input id="searchInput" type="text" placeholder="Texte..."/>
            <button id="boutonChercher" class="btn btn-secondary" onclick="window.eadSearch.runEadSimpleSearch();">Rechercher</button>
        </div>
        </section>
    let $datalists := <section id="ead-search-section" class="ead-search">
        {$simpleSearch}
        {
        for $indexTag at $tagNumber in  max.plugin.ead_search:getSearchConfiguration($project)//tag
        let $tagName := string($indexTag/@name)
@@ -41,7 +53,7 @@ function max.plugin.ead_search:searchPage($project){
                       list="{$tagId}"
                       multiple="multiple"></input>
                <div class="ead-search-popup-wrap">
                    <button onclick="window.eadSearch.togglePopup('{$tagId}')">&#x1F4D6;</button>
                    <button class="iconeListe" onclick="window.eadSearch.togglePopup('{$tagId}')"></button>
                    <div class="ead-search-popup" id="ead-search-popup-{$tagId}">
                            <button class="ead-search-close-popup" onclick="window.eadSearch.togglePopup('{$tagId}')">&#215;</button>
                            <div id="ead-search-popup-{$tagId}-alphabet" class="ead-search-popup-alphabet">
@@ -91,8 +103,10 @@ function max.plugin.ead_search:searchPage($project){
                    <input type="number" id="ead-search-date-to" value="2000" disabled="disabled"/>
                </div>
            </div>
            <div><button onclick="window.eadSearch.runEadSearch()">Rechercher</button></div>
            <div class="boutonSearch"><button onclick="window.eadSearch.runEadSearch()">Rechercher</button></div>
            <div id='searchLoading'>{max.i18n:getText($project,'search.loading')}</div>
            <div id="ead-search-results"></div>
            
        </section>

    return max.html:render($project, 'rechercher', $datalists)
@@ -131,15 +145,16 @@ function max.plugin.ead_search:runSearch($project as xs:string, $indexes as xs:s

    let $html:= <ol class="ead-search-results">{
        for $c at $pos in $matches
        return max.plugin.ead_search:formatSearchResult($c, $pos)
        return max.plugin.ead_search:formatSearchResult($c, $pos, $project)
            (:<li>{$c/*:did/*:unitid/text()} | <em>{string($c/*:did/*:unitdate[1]/@normal)}</em></li>:)

    }
    </ol>

    return <section>
            
            <h3>Résultats - {count($html/li/@id)}</h3>
            <!--<h4>XQuery = {$fullQuery} - (db = {$dbPath})</h4>-->
            <!-- <h4>XQuery = {$matches} - (db = {$dbPath})</h4> -->
            {$html}
           </section>
    }
@@ -147,17 +162,54 @@ function max.plugin.ead_search:runSearch($project as xs:string, $indexes as xs:s
        max:max-error("Erreur code " || $err:code, $err:description ||'('||$fullQuery||')',$err:module, $err:line-number)
    }
};
declare %private function max.plugin.ead_search:formatSearchResult($c as node(), $n as xs:integer){

declare
%rest:GET
%output:method("html")
%rest:query-param("search", "{$search}")
%rest:path("/{$project}/resultatsSimple.html")
function max.plugin.ead_search:runSearchSimple($project,$search){
    let $dbPath := max.config:getProjectDBPath($project)
    let $matches := 
        for $c in collection($dbPath)//*:c
        where count($c/*[not(local-name(.)="c")]) > 0 and $c[.//text() contains text {$search}]
        return $c
    return try{ 
        let $html:= <ol class="ead-search-results">{
        for $c at $pos in $matches
        return max.plugin.ead_search:formatSearchResult($c, $pos, $project)
        }
        </ol>
        return 
                <section>
                    <div id='searchLoading'>{max.i18n:getText($project,'search.loading')}</div>
                    <h3>Résultats - {count($html/li/@id)}</h3>
                    <!--<h4>XQuery = {$search} - (db = {$dbPath})</h4>-->
                    {$html}
                </section>
    }
    catch * {
        max:max-error("Erreur code " || $err:code, $err:description ||'('||$matches||')',$err:module, $err:line-number)
    }
};

declare %private function max.plugin.ead_search:formatSearchResult($c as node(), $n as xs:integer, $project as xs:string){
    <li class="ead-search-result" id="{$n}">{
        (: let $titles := for $i in $c/ancestor-or-self::*:c
            return (string-join($i/*:did/*:unitid/text(),''))
        return string-join($titles, " &#x25B8; ") :)

        for $i in $c
        let $id := $i/self::*:c/@*:id
        let $baseuriXml := base-uri($c)
        let $baseuri := base-uri($id)
        return <a href='{$baseuri}/{$id}.html'>{(string-join($i/ancestor-or-self::*:c/*:did/*:unitid/text(),' &#x25B8; '))}</a> 
        let $baseuri := substring-after(base-uri($id),'/')
        let $xslRes := file:parent(file:parent(file:parent(static-base-uri())))||"editions/"||$project||"/ui/xsl/ead/resSearch.xsl"
        let $req := <div><a href='{max.config:getBaseURI()}{$baseuri}/{$id}.html'>{$i/ancestor-or-self::*:c/*:did}</a><section>{$i/ancestor-or-self::*:c/*:did}</section></div>
        return 
            if (file:exists($xslRes)) 
            then 
                (xslt:transform($req, $xslRes, ()))
            else ($req)
        (: return <a href='{$baseuri}/{$id}.html'>{(string-join($i/ancestor-or-self::*:c/*:did,' &#x25B8; '))}</a>  :)
        
    }</li>
(:    for $c in :)
@@ -206,8 +258,10 @@ declare %private function max.plugin.ead_search:dateIntervalFilter($from as xs:s

    return
    for $m in $matches
        where $m//*:unitdate[1]
        let $unitDate := string((($m//*:unitdate)[1])/@normal)
        where $m/ancestor::*:c[1][@otherlevel='manuscrit']//*:unitdate[1]
        (: where $m//*:unitdate[1] :)
        (: let $unitDate := string((($m//*:unitdate)[1])/@normal) :)
        let $unitDate := string((($m/ancestor::*:c[1][@otherlevel='manuscrit']//*:unitdate)[1])/@normal)
        return if(contains($unitDate,'/'))
            then
            let $dates := tokenize($unitDate,'/')
+14 KiB
Loading image diff...
+10.1 KiB
Loading image diff...
Loading