Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6388391
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:16:22+00:00 2026-05-25T03:16:22+00:00

I’m trying to create a search engine for an inventory based site. The issue

  • 0

I’m trying to create a search engine for an inventory based site. The issue is that I have information inside bbtags (like in [b]test[/b] sentence, the test should be valued at 3, whereas sentence should be valued at 1).

Here is an example of an index:
My test sentence, my my (has a SKU of TST-DFS)
The Database:

|Product|  word  |relevancy|
|   1   |   my   |    3    |
|   1   |  test  |    1    |
|   1   |sentence|    1    |
|   1   | TST-DFS|    10   |

But how would I match TST-DFS if the user typed in TST DFS? I would like that SKU to have a relevancy of say 8, instead of the full 10..

I have heard that the FULL TEXT search feature in MySQL would help, but I can’t seem to find a good way to do it. I would like to avoid things like UNIONS, and to keep the query as optimized as possible.

Any help with coming up with a good system for this would be great.

Thanks,
Max

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:16:23+00:00Added an answer on May 25, 2026 at 3:16 am

    But how would I match TST-DFS if the user typed in TST DFS?
    I would like that SKU to have a relevancy of say 8, instead of the full 10..

    If I got the question right, the answer is actually easy.
    Well, if you forge your query a little before sending it to mysql.

    Ok, let’s say we have $query and it contains TST-DFS.

    Are we gonna focus on word spans?
    I suppose we should, as most search engines do, so:

    $ok=preg_match_all('#\w+#',$query,$m);
    

    Now if that pattern matched… $m[0] contains the list of words in $query.
    This can be fine-tuned to your SKU, but matching against full words in a AND fashion is pretty much what the user presumes is happening. (as it happens over google and yahoo)

    Then we need to cook a $expr expression that will be injected into our final query.

    if(!$ok) { // the search string is non-alphanumeric
      $expr="false";
    } else {   // the search contains words that are no in $m[0]
      $expr='';
      foreach($m[0] as $word) {
        if($expr)
          $expr.=" AND ";  // put an AND inbetween "LIKE" subexpressions
        $s_word=addslashes($word); // I put a s_ to remind me the variable
                                     // is safe to include in a SQL statement, that's me 
        $expr.="word LIKE '%$s_word%'"; 
      }
    }
    

    Now $expr should look like "words LIKE '%TST%' AND words LIKE '%DFS%'"

    With that value, we can build the final query:

    $s_expr="($expr)";
    $s_query=addslashes($query);
    
    $s_fullquery=
    "SELECT (Product,word,if((word LIKE '$s_query'),relevancy,relevancy-2) as relevancy) ".
    "FROM some_index ".
    "WHERE word LIKE '$s_query' OR $s_expr";
    

    Which shall read, for “TST-DFS”:

    SELECT (Product,word,if((word LIKE 'TST-DFS'),relevancy,relevancy-2) as relevancy)
    FROM some_index
    WHERE word LIKE 'TST-DFS' OR (word LIKE '%TST%' AND word LIKE '%DFS%')
    

    As you can see, in the first SELECT line, if the match is partial, mysql will return relevancy-2

    In the third one, the WHERE clause, if the full match fails, $s_expr, the partial match query we cooked in advance, is tried instead.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a French site that I want to parse, but am running into
I'm trying to create an if statement in PHP that prevents a single post
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Basically, what I'm trying to create is a page of div tags, each has
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I am trying to loop through a bunch of documents I have to put
I have some data like this: 1 2 3 4 5 9 2 6
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.