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.

Comments

drunken monkey’s picture

Yes, 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.

freshaspect’s picture

Thanks DM - got this working by adjusting schema.xml. The key step appears to have been adding...

	    <filter class="solr.EdgeNGramFilterFactory"
	      minGramSize="3"
	      maxGramSize="30"/>

..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 :)

jbguerraz’s picture

"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 ?

drunken monkey’s picture

This 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.

drunken monkey’s picture

Version: 7.x-1.0-beta8 » 7.x-1.x-dev
Component: Database search » Framework
damien tournoud’s picture

Title: Substring searching unavailable? » Substring searching
Component: Framework » Plugins
Category: support » feature

This 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.

drunken monkey’s picture

You 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.

Sebastian.Buesing’s picture

@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

lliss’s picture

StatusFileSize
new3.73 KB

I 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. :)

user654’s picture

.

user654’s picture

.

lliss’s picture

Wow, 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.

rooby’s picture

StatusFileSize
new484 bytes

Yep, 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.

devyd’s picture

Is 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.

Anonymous’s picture

Same as #14, only full word matches (on Solr 3.6), I'm guessing it's a Solr version-specific issue?

linus79’s picture

1) in /usr/local/share/apache-solr/example/solr/conf/schema.xml

substitute

    <fieldType name="text" class="solr.TextField" indexed="true" stored="true" multiValued="true" positionIncrementGap="100">
      <analyzer type="index">
        <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>

with

    <fieldType name="text" class="solr.TextField" indexed="true" stored="true" multiValued="true" positionIncrementGap="100">
      <analyzer type="index">
        <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
        <tokenizer class="solr.WhitespaceTokenizerFactory"/>
		<filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="25" />

2) restart solr
# cd /usr/local/share/apache-solr/example
# service solr restart

3) re-index Search API

texas-bronius’s picture

Issue summary: View changes

Is 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.

nebel54’s picture

I 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.

grndlvl’s picture

Adding patch for module's solr-conf/4.x for builds.

I only added for 4.x since it's the one we're using.

carloshec’s picture

I 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"?

drunken monkey’s picture

I 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"?

Sounds like it could be the issue, yes.
Why don't you just try it?