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 4560490
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:56:14+00:00 2026-05-21T17:56:14+00:00

First of all: – I can’t use sphinx because i use share hosting –

  • 0

First of all:
– I can’t use sphinx because i use share hosting
– I don’t like google solutions ie. custom search have these stupid ad and site search isn’t free

I want to create search mechanizm on my own. I have pages table and i want to search pages content by keywords and on result page i want to show part of text which is matched with desired keywords (same like google does).

Thx in advanced

  • 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-21T17:56:15+00:00Added an answer on May 21, 2026 at 5:56 pm

    Then you have two ( and a half ) choices:

    • use MyISAM engine for the data you want to search
    • write your own indexing-thing
    • change hosting or change DBMS ( the 1/2 solution )

    Here is short version of how you can do the 2nd option:

    Lets say you want to search the content of your articles.
    Basically what you have to to is create an index of all the words you might want to search for.

    Code below taken from book SQL Antipatterns and modified only tiny bit.

    I will assume that you want to index articles:

    CREATE TABLE Articles(
       article_id INT AUTO_INCREMENT,
       title VARCHAR(120),
       content TEXT,
       PRIMARY KEY ( article_id )
    );
    

    You need a table for keywords ( each keyword can be in multiple articles ):

    CREATE TABLE Keywords(
       keyword_id INT AUTO_INCREMENT,
       keyword VARCHAR(40) UNIQUE NOT NULL,
       PRIMARY KEY ( keyword_id )
    );
    

    Now the table to implement many-to-many relationship:

    CREATE TABLE ArticlesKeywords(
       keyword_id INT,
       article_id INT,
       PRIMARY KEY ( keyword_id , article_id ),
       FOREIGN KEY ( keyword_id ) REFERENCES Keywords( keyword_id ),
       FOREIGN KEY ( article_id ) REFERENCES Articles( article_id )
    );
    

    And next you create a stored procedure, which populates your indexing mechanism:

    CREATE PROCEDURE ArticlesSearch(keyword VARCHAR(40))
    BEGIN
       SET @keyword = keyword;
       PREPARE s1 FROM 'SELECT MAX(keyword_id) INTO @k FROM Keywords
          WHERE keyword = ?';
       EXECUTE s1 USING @keyword;
       DEALLOCATE PREPARE s1;
       IF (@k IS NULL) THEN
    
          PREPARE s2 FROM 'INSERT INTO Keywords (keyword) VALUES (?)';
          EXECUTE s2 USING @keyword;
          DEALLOCATE PREPARE s2;
    
          SELECT LAST_INSERT_ID() INTO @k;
    
          PREPARE s3 FROM 'INSERT INTO ArticlesKeywords (article_id, keyword_id)
             SELECT article_id, ? FROM Articles
             WHERE title REGEXP CONCAT(''[[:<:]]'', ?, ''[[:>:]]'')
                OR content REGEXP CONCAT(''[[:<:]]'', ?, ''[[:>]]'')';
          EXECUTE s3 USING @k, @keyword, @keyword;
          DEALLOCATE PREPARE s3;
    
       END IF;
    
       PREPARE s4 FROM 'SELECT b.*FROM Articles b
          JOIN ArticlesKeywords k USING (article_id)
          WHERE k.keyword_id = ?';
       EXECUTE s4 USING @k;
       DEALLOCATE PREPARE s4;
    END
    

    Now you can use this procedure to search the index for keyword.

    CALL ArticlesSearch('OMG');

    The last part of solution is making sure that each new articles is automatically indexed:

    CREATE TRIGGER Articles_Insert AFTER INSERT ON Articles
    FOR EACH ROW
    BEGIN
       INSERT INTO ArticlesKeywords (article_id, keyword_id)
          SELECT NEW.article_id, k.keyword_id FROM Keywords k
          WHERE NEW.content REGEXP CONCAT('[[:<:]]', k.keyword, '[[:>:]]')
             OR NEW.title REGEXP CONCAT('[[:<:]]', k.keyword, '[[:>:]]');
    END
    

    .

    P.S. i have never needed to test this approach, that’s why i cannot guarantee that it will work.

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

Sidebar

Related Questions

First of all, I don't need a textual comparison so Beyond Compare doesn't do
First of all I know it's bad to use a task manager/killer in Android
First of all, I know how to build a Java application. But I have
First of all, I'm fairly sure snapping to grid is fairly easy, however I've
First of all: I am not an experienced ClearCase user, but I have lots
First of all (in case this is important) I'm using ActiveState's Perl (v5.8.7 built
First of all there is a partial question regarding this, but it is not
First of all, let's define a few tables: Users table will store information about
First of all, let me say I am very new to rails, have been
First of all, I'm not looking for miracle... I know how PHP works and

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.