Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      Sunshine And March Vibes (2025 Wallpapers Edition)

      May 16, 2025

      The Case For Minimal WordPress Setups: A Contrarian View On Theme Frameworks

      May 16, 2025

      How To Fix Largest Contentful Paint Issues With Subpart Analysis

      May 16, 2025

      How To Prevent WordPress SQL Injection Attacks

      May 16, 2025

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025

      Minecraft licensing robbed us of this controversial NFL schedule release video

      May 16, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      The power of generators

      May 16, 2025
      Recent

      The power of generators

      May 16, 2025

      Simplify Factory Associations with Laravel’s UseFactory Attribute

      May 16, 2025

      This Week in Laravel: React Native, PhpStorm Junie, and more

      May 16, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025
      Recent

      Microsoft has closed its “Experience Center” store in Sydney, Australia — as it ramps up a continued digital growth campaign

      May 16, 2025

      Bing Search APIs to be “decommissioned completely” as Microsoft urges developers to use its Azure agentic AI alternative

      May 16, 2025

      Microsoft might kill the Surface Laptop Studio as production is quietly halted

      May 16, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»Development»Laravel Solr

    Laravel Solr

    November 5, 2024

    Laravel Solr

    If you have ever had a need to implement search into your application you’ve probably heard of Apache Solr. Solr is a fast, open source search platform built on the full-text, vector, and geospatial search capabilities of Apache Lucene.

    Developer Haider Jabbar Abdullah has built a package called Laravel-Solr to provide a seamless integration with Apache Solr. This will allow Laravel developers to efficiently utilize Solr’s powerful search capabilities right in their applications.

    Key Features

    • Easy installation and setup
    • Comprehensive methods for indexing and searching
    • Built-in support for common use cases
    • Well-documented and user-friendly

    To install this package, run:

    composer require haiderjabbar/laravelsolr
    

    Next, add the service provider to your config/app.php:

    'providers' => [
        // ...
        haiderjabbarlaravelsolrLaravelSolrServiceProvider::class,
    ];
    

    You should also publish the config/solr.php config file with:

    php artisan vendor:publish --provider="haiderjabbarlaravelsolrLaravelSolrServiceProvider"
    

    Once you have this setup, you will want to create a core (if one does not already exist). In Solr, the term core is used to refer to a single index and associated transaction log. You can have multiple cores if needed and in doing so it will allow you to index data with different structures in the same server. This can also give you more control over how your data is presented to different audiences.

    # Create a new Solr core and migration file
    php artisan solr:create-core coreName
    

    Now you can begin to add documents. Documents are Solr’s basic unit of information and it is just a set of data that describes something. So a document about a book could contain the title, author, year of publication, number of pages, and so on. When you add a document, Solr takes that information and adds it to an index. When you perform a query, Solr can quickly consult the index and return the matching documents.

    We will need to define the fields that our documents will have and to do so we can run:

    # Create new Solr fields with optional parent and fields
    php artisan solr:create-fields coreName
    

    This command will allow you to specify the name, type and whether or not the field is multi-valued, should be required or indexed.

    When you have defined your fields you can begin to add a documents and to do so you could write:

    use haiderjabbarlaravelsolrModelsSolrModel;
    
    $coreName = 'your_core_name';
    $data = [
        'id' => 'unique_id',
        'name' => 'document_name',
        // ... other fields
    ];
    
    $result = SolrModel::addDocument($coreName, $data);
    

    The Laravel-Solr package also comes with a QueryBuilder which allows you to have a familiar interface to search and return documents.

    use haiderjabbarlaravelsolrServicesSolrQueryBuilder;
    
    $builder = new SolrQueryBuilder($coreName);
    
    // Basic search
    $builder->search('field', '=', 'value', $boost);
    
    // Where clause
    $builder->where('field', '=', 'value', $priority);
    
    // Sort and Paginate
    $builder
        ->sort('field asc')    // Add sorting
        ->start(0)             // Starting offset (pagination)
        ->rows(10);            // Number of rows to return
    
    $results = $builder->get();
    

    Additional Commands

    # Update a Solr core with a new name
    php artisan solr:update-core
    
    # Delete a Solr core and its migration file
    php artisan solr:delete-core coreName
    
    # Update existing Solr core fields
    php artisan solr:update-fields
    
    # Delete fields from a Solr core
    php artisan solr:delete-fields
    

    You can learn more about this package and view the source code on Github.


    The post Laravel Solr appeared first on Laravel News.

    Join the Laravel Newsletter to get all the latest
    Laravel articles like this directly in your inbox.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleWhy Optimizing Your Lighthouse Score Is Not Enough For A Fast Website
    Next Article Perficient Joins Salesforce’s Agentforce Partner Network

    Related Posts

    Security

    Nmap 7.96 Launches with Lightning-Fast DNS and 612 Scripts

    May 17, 2025
    Common Vulnerabilities and Exposures (CVEs)

    CVE-2025-40906 – MongoDB BSON Serialization BSON::XS Multiple Vulnerabilities

    May 17, 2025
    Leave A Reply Cancel Reply

    Continue Reading

    IT Help Desk Support SLA

    News & Updates

    Trinity-2-Codestral-22B and Tess-3-Mistral-Large-2-123B Released: Pioneering Open Source Advances in Computational Power and AI Integration

    Development

    TileOS – Debian based Linux distribution using tiling window managers

    Linux

    This AI Paper from Microsoft and Tsinghua University Introduces Rho-1 Model to Boost Language Model Training Efficiency and Effectiveness

    Development

    Highlights

    Linux

    How to Disable (or Change) Login Sound in Ubuntu 24.10

    February 16, 2025

    When you log in to Ubuntu 24.10 an audio clip plays to greet you —…

    Critical Atlassian Flaw Exploited to Deploy Linux Variant of Cerber Ransomware

    April 17, 2024

    250W of power, six ports, AI, and a clock? This USB-C charger makes your current plug look like a potato.

    December 1, 2024

    Top 5 Tech Trends at CES 2025

    January 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.