【传智播客郑州】Hibernate Serach 5.9全文检索快速入门

Hibernate Search是基于Lucene的全文检索框架,可以很好的整合Hibernate,实现快速检索实体类。我们今天主要来介绍Hibernate Serach的基础入门。

开发环境准备——使用Maven搭建开发环境

DEMO使用Spring Data JPA(1.10) + Hibernate Search(5.9)来实现。

以下为本次开发的pom.xml文件

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.itheima</groupId>
    <artifactId>hibernatesearch-demo</artifactId>
    <version>0.0.1-SNAPSHOT</version>

    <properties>
        <hibernate-version>5.2.12.Final</hibernate-version>
        <hibernate-search-version>5.9.1.Final</hibernate-search-version>
        <spring-version>4.2.4.RELEASE</spring-version>
        <jdk-version>1.8</jdk-version>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <target>${jdk-version}</target>
                    <source>${jdk-version}</source>
                </configuration>
            </plugin>
        </plugins>
    </build>

    <dependencies>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-core</artifactId>
            <version>${hibernate-version}</version>
        </dependency>

        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-entitymanager</artifactId>
            <version>${hibernate-version}</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-search-orm</artifactId>
            <version>${hibernate-search-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context-support</artifactId>
            <version>${spring-version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-test</
在C++中,"search"通常指的是搜索或查找操作,这在许多场景下都非常常见,比如在数组、字符串、容器(如`std::vector`、`std::map`等)以及自定义数据结构中查找特定元素。以下是一些常见的搜索编程案例: 1. **数组搜索**: ```cpp int arr[] = {1, 2, 3, 4, 5}; int target = 3; bool found = false; for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i) { if (arr[i] == target) { found = true; break; } } if (found) { std::cout << "Element found at index: " << i << std::endl; } else { std::cout << "Element not found." << std::endl; } ``` 2. **动态数组(std::vector)搜索**: ```cpp std::vector<int> vec = {1, 2, 3, 4, 5}; auto it = std::find(vec.begin(), vec.end(), 3); if (it != vec.end()) { std::cout << "Element found at position: " << it - vec.begin() << std::endl; } else { std::cout << "Element not found in vector." << std::endl; } ``` 3. **线性搜索字符串(std::string)**: ```cpp std::string str = "Hello World"; size_t pos = str.find("World"); if (pos != std::string::npos) { std::cout << "Substring found starting from position: " << pos << std::endl; } else { std::cout << "Substring not found in the string." << std::endl; } ``` 4. **使用STL算法(如std::count_if)**: ```cpp std::vector<int> vec = {1, 1, 2, 2, 3, 3, 3}; int count = std::count(vec.begin(), vec.end(), 3); std::cout << "Count of element 3: " << count << std::endl; ``` 这些例子展示了如何在不同类型的容器中进行线性查找和使用内置函数进行复杂度更优的搜索。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值