3

Drupal 7 default Search module not returning partial results

I.E. I have a series of SKU #'s:

  • S0160-0003
  • S0160-0004
  • S0160-0005
  • S0160-0006

Searching for S0160 returns no results. I only get results when I search for the exact SKU number.

Any recommendations as to how to fix this?

3 Answers 3

3

Actually there's a quick way to set this up with the Search API and the Search API Database Search modules. No need for Solr.

  1. Enable both the modules and go to the Search API configuration page (admin/config/search/search_api)
  2. Add a server and give it a recognizable name (such as "MySQL"), make sure it's enabled
  3. Choose the following service class: Database service (normally the only option. If you don't see it, make sure that the "Search API Database Search" module is enabled).
  4. Selecting this service class will provide you the option Search on parts of a word (make sure you enable it). Now hit "Create server". Next, go back to the Search API configuration page, and add an index. Again give it a recognizable name, such as "Contentindex", and make sure it's enabled.
  5. Select the server you recently created (in this example "MySQL"). Datasource options: check the content types you want to index (the description of this field may be a bit confusing, but make no mistake: you should check the content types you want to index, not the ones you want to leave out).
  6. You could check "Index items immediately", but that depends on the size of your content. This option is alright for smaller websites. In the other case: let cron take care of it. Hit "Create index".
  7. Next, you want to enable the fields (in the fields tab) to that very index, e.g.: contant type, title, status and author - and hit "Save changes" (we'll take care of the related fields later).
  8. Then you want to configure the filters (in the filter tab). Here you can enable the bundle filter, if you want to finetune the content types once again (probably won't need to).
  9. Down below you'll find the highlight filter, to highlight the search word in the results.
  10. Now return to the fields tab and unfold the "Add related fields" tab. Add all the fields of which you want to get the content indexed, and hit Save Finally go to the "view" tab of the index, and index now all the items.

The last step is to create search results page and search block in Views, which only takes a few minutes.

  1. Make sure the submodule Search Views is enabled and create a view page which will show "Contentindex" (select the name you gave to your index configuration instead of "content" which is selected by default.
  2. Add all the fields (make sure your format is "fields") that every search result should consist of (title [link to content], body, …). You'll notice that these field look like this Indexed Node: Title
  3. Add an exposed filter: Search: Fulltext search; and select the following in its settings: Contains any of these words, and use as: Search keys.

You're done!

There's an excellent video tutorial on this partial search method without Solr, which also incorporates faceted search (which is not necessary for partial search, but in case you're interested…). If you're only looking for a partial search option, you can watch the video until 5:08 and after that skip to 6:45.

1
  • 1
    What about Drupal 8?
    – Barno
    Feb 4, 2016 at 20:26
3

Just add the following line to the type definition after the first occurrence of "solr.SnowballPorterFilterFactory" (inside of the <analyzer type="index"> element; not after the second occurrence):

<filter class="solr.EdgeNGramFilterFactory" minGramSize="2" maxGramSize="25" />
0
  1. I would recommend to use solr search with solr configurations as http://www.wunderkraut.com/blog/apache-solr-configuring-partial-word-search-functionality/2012-12-12

  2. In case you do want to have solr as search backend then you can use Search Api String Filter module with in turn will use search_api replacement of core search and search_api_db so to use drupal database for search index.

3
  • I was looking at Solr but it seem's was too hard to implement for just this simple thing
    – John
    Jul 7, 2015 at 18:46
  • you can go with 2 in that case, it uses core search tables.
    – arpitr
    Jul 7, 2015 at 18:48
  • Ok, I tried that but I guess I need to figure the correct way to implement. Thank you
    – John
    Jul 7, 2015 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.