We're using Search API with Solr and have setup the server, the index and a search page. Searching for complete words returns results but partial words returns no results. Is this expected behaviour? Solr itself clearly supports substring searching so does Search API not support this or are there some settings that we might be missing that would enable this to work?
Thanks in advance for any pointers.
| Comment | File | Size | Author |
|---|---|---|---|
| #19 | 1167494-19--search_api_solr-7.x-1.x--4.x--substring.patch | 658 bytes | grndlvl |
| #13 | search_api_solr-1167494-13.patch | 484 bytes | rooby |
| #9 | search_api_solr-1167494-9.patch | 3.73 KB | lliss |
Comments
Comment #1
drunken monkeyYes, this is expected behaviour, partial matching is currently not supported by the Search API. When using Solr, however, it should be rather simple to manually configure Solr for partial searches, or alter the queries sent accordingly. (Don't know how to do this with Solr off the top of my head, though.) Patches adding this as a server setting would also be welcome.
Comment #2
freshaspect commentedThanks DM - got this working by adjusting schema.xml. The key step appears to have been adding...
..to the set of filters on the index analyzer for Textfield fieldtypes. We're still prototyping so we'll see if this holds up in production dev before submitting a patch. Thanks for a great module - now going to give the Views integration a workout :)
Comment #3
jbguerraz commented"Patches adding this as a server setting would also be welcome"
Not better to add it at the filter level (for views integration) and at search page level ? this way we can use both methods, strict match or partial match regarding on our needs, no ?
Comment #4
drunken monkeyThis would be more complicated to add cleanly, that's why I proposed the easier variant.
But you are also free to submit a patch doing this optionally for each search. Should probably be an optional server feature and might then be added via the search query options.
Comment #5
drunken monkeyComment #6
damien tournoud commentedThis should actually be a filter. The standard way of doing this is by n-grams, and we have a Drupal core patch that we could steal from #103548: Partial Search in Drupal Core.
Comment #7
drunken monkeyYou are right, doing this as a processor (I guess that's what you mean by "filter?) would be an interesting idea. I would've thought more in terms of service class-specific options, but that wouldn't offer the same granularity. And I guess supporting this in a meaningful way in Solr (other than just changing the schema) wouldn't be possible either way.
Comment #8
Sebastian.Buesing commented@freshaspect:
Works like a charm. However searching for quotes doesn't work anymore once you add your line. Can you (or anybody else) confirm this? Here is the corresponding issue http://drupal.org/node/1290940
Comment #9
lliss commentedI don't really expect this to be added to the module and I don't really think it should be as it obviously causes trouble with the quoted string searches but I figured I'd add a patch just to make it easier for others to apply this fix later and so when I come looking for a the same solution later I'll save myself some time referencing the line numbers by hand. :)
Comment #10
user654 commented.
Comment #11
user654 commented.
Comment #12
lliss commentedWow, the patch in #9 is totally borked. The code from #2 is good though. Adjust that in the schema.xml file that is in your solr instance and it should work. You'll need to restart tomcat after doing this.
Comment #13
rooby commentedYep, there is a lot of unwanted stuff in there.
Here is the patch in #9 without the extra.
You apply it to the search_api_solr module (not really sure why it is in a search_api issue, just fixing the patch).
The patch amends the schema.xml file so after you patch you need to copy the schema.xml file to your solr install.
Comment #14
devyd commentedIs there any other requirement to the fields and/or processors?
I added the line according to #13 and http://www.druplitec.de/partial-substring-search-using-solr-server-and-s....
Also restarted the solr server and verified the live change in schema.xml at localhost:8983/solr/admin/file/?contentType=text/xml;charset=utf-8&file=schema.xml
Also re-indexed everything.
But unfortunately, solr still returns only full-word hits.
Comment #15
Anonymous (not verified) commentedSame as #14, only full word matches (on Solr 3.6), I'm guessing it's a Solr version-specific issue?
Comment #16
linus79 commented1) in /usr/local/share/apache-solr/example/solr/conf/schema.xml
substitute
with
2) restart solr
# cd /usr/local/share/apache-solr/example
# service solr restart
3) re-index Search API
Comment #17
texas-bronius commentedIs there a reason that one module (autocomplete) is able to support partial out of the box and another (live_results) is not? Please see add'l diagnosis at #1743244: How to do the fuzzy search for search_api_autocomplete?. I suspect one module specifies something that the other does not while firing off its query.
Comment #18
nebel54I had the same issues described in #14 and #15. Turned out that I had set the index-type of the field to String instead of Fulltext. After another solr-restart it did work.
Comment #19
grndlvl commentedAdding patch for module's solr-conf/4.x for builds.
I only added for 4.x since it's the one we're using.
Comment #20
carloshec commentedI would like to know if this is the same problem that i am having now. When i search for "Harry Potter and the Deathly Hallows: Part 1", or "Harry Potter and the Deathly Hallows: Part 2", the search ignore the number and return just "Harry Potter and the Deathly Hallows: Part". Does minGramSize="2" in schema.xml need to be change for minGramSize="2"?
Comment #21
drunken monkeySounds like it could be the issue, yes.
Why don't you just try it?