问题
I've seen some simple examples text searching STARTS WITH
name
such as:
- http://www.jexp.de/blog/html/full-text-and-spatial-search-in-neo4j-3.html
- https://blog.knoldus.com/2016/12/11/neo4j-with-scala-neo4j-vs-elasticsearch/
But I'm looking for something more along the lines of full-text search across multiple fields: title
, content
:
- https://www.digitalocean.com/community/tutorials/how-to-use-full-text-search-in-postgresql-on-ubuntu-16-04
Can I see an example of how this should be done with Neo4j?
回答1:
You can do this using the APOC Neo4j procedure library. Let's say you have node labels Book
and Author
and you want to make a full text query across :Book(title)
, :Book(content)
, and :Author(name)
and :Author(address)
. First, use apoc.index.addAllNodes
to create an index called bookIndex
and specify the labels and properties to include in the index:
CALL apoc.index.addAllNodes('bookIndex',{
Book: ["title","content"],
Author: ["name","address"]
})
Then, to search the index:
CALL apoc.index.search('bookIndex', 'River Runs Through It')
You can use this with more complex graph queries as well:
CALL apoc.index.search('bookIndex, 'River Runs Through It')
YIELD node AS book
MATCH (book)-[:IN_GENRE]->(g:Genre)
RETURN g
Lucene query syntax is used so you can do fuzzy search, required components of the string, etc: 'Norman Maclean~'
or 'Norman~ +Maclean'
See the APOC docs for more info.
来源:https://stackoverflow.com/questions/45867968/example-of-full-text-search-across-multiple-fields-in-neo4j