OpenBD / openbd-core

The original open source Java powered GPL CFML runtime engine
GNU General Public License v3.0
32 stars 14 forks source link

CFSearch can't order results?? #69

Open acg10 opened 6 years ago

acg10 commented 6 years ago

Hi everybody. I'm a project that use Razuna, an DAM platform what use OpenBD. My problem is that this App use Lucene like search-engine and i can't sort the results. I see so in Adobe ColdFusion 10 is possible order the results with a new param called "orderBy", but this not work in OpenBD. Is posible use the CFSearch class to sort my results??? Thanx everybody

mgrandb commented 6 years ago

I think you can use Querysort().

MFernstrom commented 6 years ago

@acg10, cfsearch returns a query object, so you can use querySort().

Example

<cfset collectionCreate( collection="mycollection", storebody=false )>
<cfset collectionIndexPath( collection="mycollection", key="/Library/Java/JavaVirtualMachines/jdk1.8.0_152.jdk/Contents", recurse=true )>
<cfsearch collection="mycollection" criteria="*" name="theSearch">
<cfdump var="#theSearch#">
<cfset querySort( theSearch, "size", "numeric" )> 
<cfdump var="#theSearch#">
acg10 commented 6 years ago

Thax for the replies. My problem is that im use pagination in the search (maxrows param), so my returned query object not contains all the data. Is possible say to Lucene that search in the index sorted?? Thax everybody

acg10 commented 6 years ago

com/bluedreagon/search/... QueryRun -> Modify searcher with Sort class of Lucene and ignore the scores results. DocumentWrap -> Add to document SortedDocVAluesField class. https://lucene.apache.org/core/5_5_1/core/index.html thank you can close issue.

MFernstrom commented 6 years ago

Can you show an example of how you did that? I'm curious :)

acg10 commented 6 years ago

Hi MFernstrom: In Queryrun.java, before that IndexSearch call search method, can pass a Sort class to say Lucene search in the documents sorted by an field. I'm the "filename" field so before write:

String field = "title"; SortField.Type type = SortField.Type.STRING; boolean descending = true; SortField sortField = new SortField(field, type, descending); Sort sorter = new Sort(sortField);

TopDocs localTopDocs = localIndexSearcher.search(this.queryAttributes.getQuery(), localCollection.getTotalDocs(), sorter);

And Lucene return the TopDocs sorted by this field "filename". A good idea is parametrizer this field in cfsearch function to can get the results sorted in Lucene.

Thx for everthing and sorry my bad english

MFernstrom commented 6 years ago

Nice @acg10 , thanks for sharing! And don't worry about your English, it's not my native language either, you're fine :)