cancel
Showing results for 
Search instead for 
Did you mean: 

Ordenación datos con lucene search

ruben_arjonilla
Champ in-the-making
Champ in-the-making
Buenas,
tengo un pequeño problema a la hora de ordenar una búsqueda echa con lucene en un webscript.

Estoy buscando usuarios ("cmSmiley Tongueerson"), y quiero ordenarlos por el nombre.

Este es el código javascript que uso para realizar la búsqueda:
var alfQuery = '+TYPE:"cm:person" ';
var sort =
{
   column: "@{http://www.alfresco.org/model/content/1.0}firstName",
   ascending: true
};
var nodes = search.luceneSearch(alfQuery, sort, true),
Esto me saca los resultados totalmente desordenados.

He revisado la Wiki de Alfresco, y he leído que tengo que indexar el campo para poder ordenar y en el contentModel.xml he echo la siguiente modificación, he añadido la parte de index en el campo firstName:

<property name="cm:firstName">
   <type>d:text</type>
   <mandatory>true</mandatory>
              
   <index enabled="true">
      <atomic>false</atomic>
      <stored>false</stored>
      <tokenised>both</tokenised>
   </index>
</property>
He probado varias combinaciones, tokenised en false y true, atomic en true y false, …
Pero siempre con el mismo resultado, y la misma ordenación, o sea, ninguna…

Estoy haciendo algo mal? o me estoy dejando algo?

Muchas gracias de antemano
2 REPLIES 2

yakon_8894
Champ in-the-making
Champ in-the-making
Hola rubén,

En el método que estás usando, el segundo parámetro sirve para indicar el metadato por el que quieres ordenar, pasando un string de su nombre. En tu caso sería algo como:

var nodes = search.luceneSearch(alfQuery, "@cm:firstName", true);

Para usar condiciones de ordenación más complejas, en la wiki hacen referencia al método query. Te dejo la información de la wiki por si te sirve de ayuda:

Array query(object search)
    Returns an array of ScriptNode objects representing the search results. The 'search' object defines the search to be executed as is constructed in this way:

search
{
   query: string,          mandatory, in appropriate format and encoded for the given language
   store: string,          optional, defaults to 'workspace://SpacesStore'
   language: string,       optional, one of: lucene, xpath, jcr-xpath, fts-alfresco, cmis-alfresco, cmis-strict - defaults to 'lucene'
   sort: [],               optional, Array of sort column options (see below)
   page: object            optional, paging information object (see below) - if supported by the language
}

sort
{
   column: string,         mandatory, sort column in appropriate format for the language
   ascending: boolean      optional, defaults to false
}

page
{
   maxItems: int,          optional, max number of items to return in result set
   skipCount: int          optional, number of items to skip over before returning results (NOT IMPLEMENTED YET)
}

The search definition object an be as simple to use as:

  var results = search.query({query: "TEXT:alfresco"});

Or as richly defined as:

  var sort1 =
  {
     column: "@{http://www.alfresco.org/model/content/1.0}modified",
     ascending: false
  };
  var sort2 =
  {
     column: "@{http://www.alfresco.org/model/content/1.0}created",
     ascending: false
  };
  var paging =
  {
     maxItems: 100,
     skipCount: 0
  };
  var def =
  {
     query: "cm:name:test*",
     store: "workspace://SpacesStore",
     language: "fts-alfresco",
     sort: [sort1, sort2],
     page: paging
  };
  var results = search.query(def);

Multi-column sorting and any of the Alfresco search languages are supported through this interface. The search definition objects may be extended with additional properties in future versions of the API but backward compatibility will be maintained.

Saludos

ruben_arjonilla
Champ in-the-making
Champ in-the-making
Muchisimas gracias.

Funciona perfectamente