Verse Search Logs - warwickfoster/qurantools GitHub Wiki

File: app/library/search_engine.php

Purpose

The provided code snippet is a PHP function named search_translations() that performs a search operation on a database of translations.

Functionality

The function takes a search text as input and returns a result set containing the matching translations. It performs the following steps:

  1. Parses the search text The function identifies the phrases and regular expressions to match in the translations.
  2. Searches the database It queries the database to retrieve translations that match the search criteria.
  3. Extracts highlighted words For each matching translation, the function extracts the words or phrases that match the regular expressions specified in the search text.
  4. Returns the result set The function returns a result set containing the matching translations and the highlighted words.

Key Features

  • Supports searching across multiple translator names, translation texts, and rendered versions.
  • Uses regular expressions to match search terms.
  • Highlights matching words in the results.
  • Tracks hit counts for highlighted words.

Usage

The search_translations() function can be used to implement a search functionality in a translation management system. The result set can be displayed to the user to show the matching translations and the highlighted words.

Example

$search_text = "Arabic text to search";
$search_result = search_translations($search_text);

// Display the results
foreach ($search_result as $row) {
    echo $row["TRANSLATION NAME"] . ": " . $row["RENDERED ARABIC"] . "<br>";
}

Output

Translation 1: Arabic text to search...
Translation 2: Another Arabic text...

Note

The code snippet includes a function called increment_hit_counts(), but its implementation is not included in the provided context.