I am not seeing the natural sort option in the Views "Sort criteria".
I'm having the same issue as described in a previous ticket (see related issues). The response there was that the user was using an outdated version of the module and that the old implementation was different. I'm running the latest versions (Drupal 7).
The situation:
- modules are installed and enabled.
- the title field has been configured to enable natural sorting (in the content type's field management page)
- indexing all seems to running fine, both after saving the natural sort settings and when indexing using Search API
- the field has been set to String in the search index (to allow field to be used for sorting)
- modules are the latest versions
I can add the title as a Sort criteria (as usual), but no options are given for the natural sorting
ex.
Sort criteria:
Indexed Node: Title (asc)
Versions:
Drupal version : 7.43
Views Natural Sort Version : 7.x-2.6
Views Version : 7.x-3.18
Comments
Comment #2
mdeanComment #3
mdeanComment #4
mdeanComment #5
mdeanComment #6
generalredneck@mdean,
TLDR; exposing Views Natural Sort's transformation of the title to Search API as a indexable field would be a Feature Request.
First, #2540762: natural sort option not appearing under Views 3 was all about a misunderstanding where the reporter had tried to apply the instructions for Views Natural Sort 2.0 to the old 1.4 version.
I'm not 100% sure how you got to the screen below unless you created your own title field (or another module allows this) as by default you cannot access the field settings for a node title field as it's a drupal "property" as opposed to a "field". Note Node titles are handled using just the Views Natural Sort module. You must enable the Views Natural Sort Text Field module to work with other "fields" which looks like what you did.
I saw the "String" field type in one of your other screenshots and that got me really curious because there isn't a "String" field type.... we have "text" and "long text" which equate to "varchar" and "text" in database terms... and since you didn't provide me with any urls I had to dig to figure out where those screens came from.
Also the fact the field was called "title_field" instead of "title" or "field_title"... so here's the breakdown of where you are misunderstanding
The following is a screenshot from your search index

And the following view was made using Search API from the best I can tell from the screenshot.

A misconception you may have is around where your data is coming from and the technical limitations of what you are trying to do. The Title returned from your search index is not equivalent to the actual title field from the node. This is because search api could be returning from any number of backends that are not the Drupal database. In fact, it is very typical for a search page to only make supporting queries to the database to get node data (to like display the full node as a result). The main query is made to something like Solr.
I looked for a way to relate the node that is in the search api index with what is in the Drupal database, and currently that isn't possible. because then you would have to be able to link something like solr with a "join" to the drupal database. Given that, exposing Views Natural Sort's transformation of the title to Search API as a indexable field would be a Feature Request.
Another misconception you may also be having is between the terminology used in the Views Natural Sort modules about "reindexing". The Views Natural Sort module maintains it's own "index" of transformed strings so that when rows are sorted by this "index" MySQL and SqlLite will sort the data rows as if they were sorted by the "natural" rules we are suggesting (like removing A, The, and, or, the and sorting numbers in a natural way). Example:
The view for something close to the query above looks like this
Comment #7
nwom commentedRe-opening as a feature request (if that is ok). Thanks for the detailed information as to why Search API indexed views currently don't work with this module. Has anyone potentially found a workaround for this?
Comment #8
generalredneckFor what it's worth you may be able to do this with some solr configuration
http://www.andornot.com/blog/post/Make-numbers-behave-when-sorting-alpha...
Granted this wouldn't take all the permutations of number sorting into account like decimals and negatives... but may be what you are looking for.
Comment #9
elamanViews Natural Sort has index table, integrating which will be a pain. A different approach would be providing Search API processor, that uses Views Natural Sort text transforming methods.
Here is a patch, that does that.
Comment #10
generalredneckElaman
Think you forgot a file... the one housing the class.
includes/views_natural_sort_search_api_processor.inc
Also, excellent idea. Let's give it a try and see how it works. Would need to implement it for fields in the future.
Comment #11
elaman@generalredneck thank you, didn't notice that!
Comment #12
elamanComment #14
elamanChanged approach. Use Data alterations.
The reason is simple. This will allow having field indexed, then displayed as usual. Then it is possible to generate additional field specifically for sorting purposes.
Use:
Works with text fields only.
Should work with Elasticsearch Connector.
Comment #15
generalredneckSomething to consider. The current seperation of functionality are Text properties in Views Natural Sort and Text "Fields" in views Natural Sort Text Fields modules... mostly for performance sake currently. I would like to bring both functionalities back in... but we will have to see how this fits into the model.
Comment #16
nwom commented#14 worked great and applied cleanly. Thank you so much!
Comment #17
elaman@generalredneck
I would propose creating a separate module, Views Natural Sort Search API inside this module.
Comment #18
bohus ulrychHi all,
I have problems to get this patch to work with Related fields in Search API search.
I'm trying to list taxonomy terms, one field is entity reference to user. In my search I would like to sort by field "prijmeni" (means Surname).
But as you can see from the screenshot only "Sort by User" is available.
Any idea?
Thanks
Comment #19
drupal_lib commentedI was also able to apply the patch from #14 cleanly, however, after applying the patch when I go to my Search API index and select fields to sort on the "Fields" tab, I don't see an option on the "Filters" tab under "Data Alterations" for "Natural Sort." Am I missing a step? Thanks - any help is greatly appreciated!
Comment #20
maskedjellybeanI found that the patch did not apply successfully against version 7.x-2.6+5-dev of views_natural_sort.
Here's a new patch that should be able to be applied against it.
After applying and following the steps laid out in comment #14 by elaman, I have natural sort working as expected on Search API index view.
Thank elaman!
Comment #21
maskedjellybeanArgh, my last patch didn't work for me trying to reapply it to test again. Here's another attempt.
Comment #22
schnydszch commentedHi! I'm not seeing view sort natural in my Drupal 8 installation, I am assuming this isn't available yet in Drupal 8? The patch I am seeing are for Drupal 7 and I am afraid that if I open a new bug issue it will be a duplicate? I hope this feature for search api will be available too for Drupal 8.x. Thanks!
Comment #23
rgeerolfI can confirm that the natural sorting options are not available in D8+. Do we need to create a separate issue for this?
Comment #24
generalredneckYeah lets create another issue for D8 port.
Comment #25
jackg102 commentedThis was helpful seeing this issue and the discussion. I wonder if it would be helpful to place a note on the front of the module page (maybe somewhere under the 'Drupal 8' heading) that Search API integration is not currently supported for D8+, but is in its early stages of development. It might head off some potential heart ache. I was working on incorporating this on a project, trying to figure out the issue and then ran across these posts at the bottom of the thread.
Thank you so much!
Comment #26
generalredneckLets see if we can get this ported to a secondary module... Going to propose the same for the D8 version.
Comment #27
generalredneck