• Resolved tgaff2x

    (@tgaff2x)


    Using the standard search via wpsolr works fine.

    However, if I attempt to search within the title only with something like

    title:price

    I receive an error of “Solr HTTP error: OK (400) {“error”:{“metadata”:[“error-class”,”org.apache.solr.common.SolrException”,”root-error-class”,”org.apache.solr.parser.ParseException”],”msg”:”org.apache.solr.search.SyntaxError: Cannot parse ‘text:title:price’: Encountered \” \”:\” \”: \”\” at line 1, column 10.\nWas expecting one of:\n \n …\n …\n …\n \”+\” …\n \”-\” …\n …\n \”(\” …\n \”*\” …\n \”^\” …\n …\n …\n …\n …\n …\n …\n \”[\” …\n \”{\” …\n …\n \”filter(\” …\n …\n “,”code”:400}}”

    With a prior version of wpsolr, I thought this worked. If I go directly to solr admin (eliminating wpsolr), I am able to search for title:price and get the expected results.

    Am I incorrectly remembering how this used to work? Similarly, some of the other custom searches such as using the ~ to do a proximity search also don’t seem to work any more.

    I’m running wpsolr version 15.2 and cannot update at this time.

Viewing 8 replies - 1 through 8 (of 8 total)
  • Plugin Author WPSolr free

    (@wpsolr)

    Hi,

    However, if I attempt to search within the title only

    What do you do exactly ?

    Thread Starter tgaff2x

    (@tgaff2x)

    I go to the search page, type in “title:price” without the quotes, click the search button.

    Plugin Author WPSolr free

    (@wpsolr)

    It will not work.

    The field ‘text’ is used by default.

    You can modify your schema.xml to only copy the field ‘title’ in the field ‘text’. Your search will then be applied to ‘text’, which contains only titles.

    Replace:

        <copyField source="title" dest="text"/>
        <copyField source="tags" dest="text"/>
        <copyField source="categories" dest="text"/>
        <copyField source="content" dest="text"/>
        <copyField source="permalink" dest="text"/>
        <copyField source="comments" dest="text"/>

    with :
    <copyField source="title" dest="text"/>

    Do the same thing to other fields, like autocomplete, eventually.

    Then redindex everything.

    • This reply was modified 7 years, 10 months ago by WPSolr free.
    Thread Starter tgaff2x

    (@tgaff2x)

    Thanks for the replies.

    I could swear at one point, I could use many of the custom solr search approaches outlined here –
    https://www.solrtutorial.com/solr-query-syntax.html

    including the title: search, proximity search, etc.

    You are saying that the standard solr syntax isn’t just passed on to solr search in a way that is understood by solr?

    • This reply was modified 7 years, 10 months ago by tgaff2x.
    Plugin Author WPSolr free

    (@wpsolr)

    I understand now that you want to build complex Solr queries in the search bar.

    The only thing that prevents you to do that, is the query being prefixed with ‘text:’.

    But you can remove the prefix with our filters:
    https://www.wpsolr.com/guide/actions-and-filters/search-query-query/

    Here is a code tested in real conditions with the query: title:home

    <?php
    /**
     * Build complex Solr queries in the search bar
     */
    
    use wpsolr\core\classes\WpSolrFilters;
    
    add_action( 'init', function () {
    
    	if ( defined( 'WPSOLR_PLUGIN_SHORT_NAME' ) ) {
    		// WPSOLR is active
    
    		/**
    		 * @param array $parameters
    		 *
    		 */
    		function wpsolr_action_solarium_query( $parameters ) {
    
    			// Retrieve the Solarium query object from the parameters.
    			$solarium_query = $parameters[ WpSolrFilters::WPSOLR_ACTION_SOLARIUM_QUERY__PARAM_SOLARIUM_QUERY ];
    
    			$prefixed_query  = $solarium_query->getQuery(); // text:(title\:price)
    			$no_prefix_query = substr( $prefixed_query, 5 ); // (title\:price)
    			$unescaped_query = str_replace( '\\:', ':', $no_prefix_query ); // (title:price)
    			$solarium_query->setQuery( $unescaped_query );
    		}
    
    		if ( ! is_admin() ) {
    
    			// Catch Solarium query before calling Solr
    			add_action( WpSolrFilters::WPSOLR_ACTION_SOLARIUM_QUERY, 'wpsolr_action_solarium_query', 10, 1 );
    		}
    	}
    } );
    
    • This reply was modified 7 years, 10 months ago by WPSolr free.
    • This reply was modified 7 years, 10 months ago by WPSolr free.
    • This reply was modified 7 years, 10 months ago by WPSolr free.
    • This reply was modified 7 years, 10 months ago by WPSolr free.
    • This reply was modified 7 years, 10 months ago by WPSolr free.
    Thread Starter tgaff2x

    (@tgaff2x)

    OK great, that solved most of my use cases.

    However, with the proximity search such as “near me”~5 which should find any time those two words are within 5 it was still failing.

    It looks like this is due to the fact that the query is passed in as \”near me\”~5 with the quotes being escaped. I added in another str_replace to remove the back slashes and now it seems to work for me.

    Are you OK with this approach, or recommend anything else.

    Thanks again for your prompt responses.

    Plugin Author WPSolr free

    (@wpsolr)

    it’s fine.

    All Solr special characters have been escaped before you get this filter.
    You have to unescape them.

    Thread Starter tgaff2x

    (@tgaff2x)

    Thanks, looks good

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘custom search’ is closed to new replies.