Currently I don't see range field with other fields at: /admin/config/search/search_api/index/ENTITY_TYPE/fields
It should be integrated with Search API, so could be searchable using search engines (e.g. apachesolr).

See:
http://drupalcode.org/project/search_api.git/blame/refs/heads/7.x-1.x:/R...
#1093332: Custom field type

Information for developers
--------------------------

| NOTE:
| For modules providing new entities: In order for your entities to become
| searchable with the Search API, your module will need to implement
| hook_entity_property_info() in addition to the normal hook_entity_info().
| hook_entity_property_info() is documented in the entity module.
| For making certain non-entities searchable, see "Item type" below.
| For custom field types to be available for indexing, provide a
| "property_type" key in hook_field_info(), and optionally a callback at the
| "property_callbacks" key.
| Both processes are explained in [1].
|
| [1] http://drupal.org/node/1021466

Comments

taran2l’s picture

Hi kenorb,

You cited information how to add support for properties of custom entities in order to be searchable via Search API, not fields.

I've checked Search API docs and didn't find what I need to add to the code.

Maybe you have another suggestions ?

Thanks!

ghindle’s picture

From the Search API Readme:

- Data type
  Hook: hook_search_api_data_type_info()

You can specify new data types for indexing fields. These new types can then be
selected on indexes' „Fields“ tabs. You just have to implement the hook,
returning some information on your data type, and specify in your module's
documentation the format of your data type and how it should be used.

For a custom data type to have an effect, in most cases the server's service
class has to support that data type. A service class can advertize its support
of a data type by declaring support for the "search_api_data_type_TYPE" feature
in its supportsFeature() method. If this support isn't declared, a fallback data
type is automatically used instead of the custom one.

If a field is indexed with a custom data type, its entry in the index's options
array will have the selected type in "real_type", while "type" contains the
fallback type (which is always one of the default data types, as returned by
search_api_default_field_types().
kenorb’s picture

Status: Active » Needs review
StatusFileSize
new1.21 KB

hook_entity_property_info_alter()

taran2l’s picture

Project: » Range
Version: » 7.x-1.0
taran2l’s picture

Status: Needs review » Fixed

Added support for the hook_entity_property_info().

Search API DB has an issue with dealing with multiple decimal fields. Here's an issue and patch: #1916474: Search DB incorrectly index multiple float/decimal fields

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

pol’s picture

I'm also looking for this feature. Any update ?

taran2l’s picture

This feature is already there. What are you looking for exactly ?

pol’s picture

Hey hi Roman,

What a quick reply, thanks !

I was looking for that yesterday and I ended up doing my own module in a sandbox, here: https://drupal.org/sandbox/pol/2128471

It's very simple and expose the "Range" fields to Search API.

Now the trick is this... let's take an example to explain what I would like to achieve:

Let's have a node with a range field, the first number is 100, the second one is 200.
If I do a search with the number 50, it should returns nothing.
If I do a search with any number in between 100 and 200, it should return something.
You see what I mean ?

I don't know yet how to do, but I will try to give it a couple of hours these days.

gilsbert’s picture

Hi Taran2L.
Hi Pol.

I need to use range fields in search_api too.

I could find my field in the option "Add related fields".
But after including the field the list is not updated with it and the field is not available for indexing.
In this moment I could find fields "from" and "to" in the option "Add related fields". After adding both fields they are not available for indexing as well.

I tested this using search_api 7.x-1.9 and last dev version.
In both the same result: I can't see the field/fields for indexing.

My database is a postgresql database.

What am I doing wrong?

Regards,
Gilsberty

P.S.: Pol, I need a facet doing filtering over a range field, much like your example. Is your sandbox working?

gilsbert’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work

A final note: I'm using search_api_db as the service for indexing.

gilsbert’s picture

Hi.

I read the file range.module and I couldn't find any trace of the patch at #3 (I could not find any function integrating range with search_api).

I applied the patch and tried to index my range field. No success (nothing changed).

No idea what else I might try.
I'm going to wait for help now.

Regards,
Gilsberty

pol’s picture

Hi there,

My sandbox does what I need for now, it's clear that adding a facet with a slider would be a huge plus but I don't have the time to work on this, I would help someone to do it for sure though.

gilsbert’s picture

Hi Pol.

I tried your sandbox without success. It appears that search_api is understanding much better the type "range" (the field is not listed in the option "Add related fields" and it is showed in the list available for indexing).

After marking my range field for indexing and renewing my index I get an ajax error in the indexing process.

I'm using the last dev version of search_api and search_api_db.
By the way, are you using search_api_db as your index server?

To be honest now I'm a litle lost.
Taran2L: should "range" module integrates naturally with search_api or should we use Pol's sandbox?

Regards,
Gilsberty

taran2l’s picture

Hi guys,

Seems like Search API changed property type int to integer after the original integration has been added.

Should work fine now.

Small explanation how to use: as this field has multiple values (FROM and TO) it should be added from the Additional fields selectbox. Basically, it works like Body field.

Please confirm that the issue is being solved.

P.S. Please create a separate issue for newly found bugs.

taran2l’s picture

Status: Needs work » Fixed
gilsbert’s picture

Hi Taran2L.

Thank you very much. The last git version has this issue fixed and the fields "from" and "to" can be indexed now.

Please clarify to me one thing: the fields "from" and "to" are added as independents fields. Do you think it is possible to add them as a true range/interval of values and make a search_api facet work like what Pol explained on his example?

Finally, do you think that this should be done in range module or in a new one?

Regards,
Gilsberty

taran2l’s picture

Search API on it's own does only simple equal queries. In this case you can search by FROM and TO value. In range/out of the range queries is not possible.

There an issue #1903342: Integration with Search API ranges. It could be it. I need to check this approach.

Meanwhile, you can achieve such functionality with Views. Look for Content: FIELD_NAME range filter.

gilsbert’s picture

Hi Taran2L.

Thank you for the information. Now I'm following the issue #1903342. :-)

The exposed filter "Content: FIELD_NAME range filter" is working perfectly in a view based on content data type (i.e.: nodes).

But I can't choose the filter in my view based on a search_api index! There are not "content" fields but only "indexed" fields avaliable on filter.
I tried to force a relationship with the node... no success.

I have this same limitation with https://drupal.org/project/views_between_dates_filter (it is a filter that works for date start/end range!).

Do you have an idea why I can't use the "range" filter on a view based in a search_api index?

Regards,
Gilsberty

kenorb’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

gilsbert’s picture

Hunnnnnn.... no answer to my question at #19.

tymn’s picture

We're also wanting to add an exposed range filter to a view based on Search API Indexed content.

Our use-case is for a holiday rentals site:

  • Property manager inputs sleeps range for a property using the range field e.g. 10 to 20
  • User can search by inputting a single sleeps value e.g. 15
  • The property should display in results if the inputted value (15) falls within the range (10 to 20)

Has anyone found a solution for this using Search API views?

taran2l’s picture

Hi @tymn,

Range module provides a views filter called @label range filter that should work for your use case. It allows for filtering a view by searching that something is within the range or outside it.

However, it's not possible to do it with search index views.

taran2l’s picture

Status: Closed (fixed) » Needs review
Issue tags: +Needs tests, +Needs backport to D8
StatusFileSize
new9.07 KB

Status: Needs review » Needs work

The last submitted patch, 25: range-add_add_support_for_search_api-1872194-25.patch, failed testing.

The last submitted patch, 25: range-add_add_support_for_search_api-1872194-25.patch, failed testing.

The last submitted patch, 25: range-add_add_support_for_search_api-1872194-25.patch, failed testing.

The last submitted patch, 25: range-add_add_support_for_search_api-1872194-25.patch, failed testing.

taran2l’s picture

Status: Needs work » Needs review

Updated tests, so they pass with Drupal core 7.50

taran2l’s picture

StatusFileSize
new9.52 KB

Make sure that we attach views handlers to fields that are being indexed.

taran2l’s picture

StatusFileSize
new9.27 KB

Ooops, missed dpm()

taran2l’s picture

StatusFileSize
new24.19 KB
new17.29 KB

New patch:

  • added tests
  • small bug fixes

Status: Needs review » Needs work

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

  • Taran2L committed bbafaf6 on 7.x-1.x
    Issue #1872194 by Taran2L, kenorb: Added test dependencies, so tests can...
taran2l’s picture

Status: Needs work » Needs review
Issue tags: -Needs tests

d.o doesn't not pick up new test dependecies until the patch is committed, let's do it again

Status: Needs review » Needs work

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

The last submitted patch, 33: range-add_add_support_for_search_api-1872194-33.patch, failed testing.

taran2l’s picture

Status: Needs work » Needs review
StatusFileSize
new23.86 KB

Ok, reroll

  • Taran2L committed fc4364f on 7.x-1.x
    feat(views): Add support for Search API (issue #1872194 by Taran2L,...
taran2l’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.